2018-08-03 12:19:40 -04:00
|
|
|
require_relative '../spec_helper'
|
2018-03-04 10:09:32 -05:00
|
|
|
require_relative '../fixtures/classes'
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
describe "TCPServer#sysaccept" do
|
|
|
|
before :each do
|
2017-06-15 08:48:52 -04:00
|
|
|
@server = TCPServer.new(SocketSpecs.hostname, 0)
|
|
|
|
@port = @server.addr[1]
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
after :each do
|
|
|
|
@server.close unless @server.closed?
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'blocks if no connections' do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { @server.sysaccept }.should block_caller
|
2017-05-07 08:04:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns file descriptor of an accepted connection' do
|
|
|
|
begin
|
2017-06-15 08:48:52 -04:00
|
|
|
sock = TCPSocket.new(SocketSpecs.hostname, @port)
|
2017-05-07 08:04:49 -04:00
|
|
|
|
|
|
|
fd = @server.sysaccept
|
|
|
|
|
2018-09-25 06:41:16 -04:00
|
|
|
fd.should be_kind_of(Integer)
|
2017-05-07 08:04:49 -04:00
|
|
|
ensure
|
|
|
|
sock.close if sock && !sock.closed?
|
|
|
|
IO.for_fd(fd).close if fd
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-08-03 12:19:40 -04:00
|
|
|
|
|
|
|
describe 'TCPServer#sysaccept' do
|
|
|
|
SocketSpecs.each_ip_protocol do |family, ip_address|
|
|
|
|
before do
|
|
|
|
@server = TCPServer.new(ip_address, 0)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
@server.close
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'without a connected client' do
|
|
|
|
it 'blocks the caller' do
|
2019-07-27 06:40:09 -04:00
|
|
|
-> { @server.sysaccept }.should block_caller
|
2018-08-03 12:19:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with a connected client' do
|
|
|
|
before do
|
|
|
|
@client = TCPSocket.new(ip_address, @server.connect_address.ip_port)
|
|
|
|
end
|
|
|
|
|
|
|
|
after do
|
|
|
|
Socket.for_fd(@fd).close if @fd
|
|
|
|
@client.close
|
|
|
|
end
|
|
|
|
|
2018-09-25 06:41:16 -04:00
|
|
|
it 'returns a new file descriptor as an Integer' do
|
2018-08-03 12:19:40 -04:00
|
|
|
@fd = @server.sysaccept
|
|
|
|
|
2018-09-25 06:41:16 -04:00
|
|
|
@fd.should be_kind_of(Integer)
|
2018-08-03 12:19:40 -04:00
|
|
|
@fd.should_not == @client.fileno
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|