Skip to content

Commit 80aeefb

Browse files
aardvark179eregon
authored andcommitted
Add specs that sockets are nonblocking by default.
1 parent 4cd14c4 commit 80aeefb

File tree

5 files changed

+54
-0
lines changed

5 files changed

+54
-0
lines changed

spec/ruby/library/socket/tcpserver/accept_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,17 @@
114114
@socket = @server.accept
115115
@socket.should be_an_instance_of(TCPSocket)
116116
end
117+
118+
it "returns a TCPSocket which is set to nonblocking" do
119+
require 'io/nonblock'
120+
@socket = @server.accept
121+
@socket.should.nonblock?
122+
end
123+
124+
it "returns a TCPSocket which is set to close on exec" do
125+
@socket = @server.accept
126+
@socket.should.close_on_exec?
127+
end
117128
end
118129
end
119130
end

spec/ruby/library/socket/tcpsocket/initialize_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@
7272
@client.remote_address.ip_port.should == @server.local_address.ip_port
7373
end
7474

75+
it "creates a socket which is set to nonblocking" do
76+
require 'io/nonblock'
77+
@client = TCPSocket.new(ip_address, @port)
78+
@client.should.nonblock?
79+
end
80+
81+
it "creates a socket which is set to close on exec" do
82+
@client = TCPSocket.new(ip_address, @port)
83+
@client.should.close_on_exec?
84+
end
85+
7586
describe 'using a local address and service' do
7687
it 'binds the client socket to the local address and service' do
7788
@client = TCPSocket.new(ip_address, @port, ip_address, 0)

spec/ruby/library/socket/udpsocket/initialize_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@
3030
@socket.binmode?.should be_true
3131
end
3232

33+
it 'sets the socket to nonblock' do
34+
require 'io/nonblock'
35+
@socket = UDPSocket.new(:INET)
36+
@socket.should.nonblock?
37+
end
38+
39+
it 'sets the socket to close on exec' do
40+
@socket = UDPSocket.new(:INET)
41+
@socket.should.close_on_exec?
42+
end
43+
3344
it 'raises Errno::EAFNOSUPPORT or Errno::EPROTONOSUPPORT when given an invalid address family' do
3445
-> {
3546
UDPSocket.new(666)

spec/ruby/library/socket/unixserver/accept_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@
110110
@socket = @server.accept
111111
@socket.recv(5).should == 'hello'
112112
end
113+
114+
it "is set to nonblocking" do
115+
require 'io/nonblock'
116+
@socket = @server.accept
117+
@socket.should.nonblock?
118+
end
119+
120+
it "is set to close on exec" do
121+
@socket = @server.accept
122+
@socket.should.close_on_exec?
123+
end
113124
end
114125
end
115126
end

spec/ruby/library/socket/unixsocket/initialize_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@
3333
it 'sets the socket to binmode' do
3434
@socket.binmode?.should be_true
3535
end
36+
37+
it 'sets the socket to nonblock' do
38+
require 'io/nonblock'
39+
@socket.should.nonblock?
40+
end
41+
42+
it 'sets the socket to close on exec' do
43+
@socket.should.close_on_exec?
44+
end
45+
3646
end
3747
end
3848
end

0 commit comments

Comments
 (0)