diff options
author | Jean Boussier <[email protected]> | 2022-09-20 16:10:56 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2023-08-30 10:07:18 +0200 |
commit | bcc905100f1079e191632cfd02319c10af82dac0 (patch) | |
tree | e8dbe37eb4de741c51210f65ffaa0336ce579c8a /spec/ruby/library/socket/basicsocket/recv_spec.rb | |
parent | acedbcb1b4eb6b362f11e783bff53c237d05afc6 (diff) |
BasicSocket#recv* return `nil` rather than an empty packet
[Bug #19012]
man recvmsg(2) states:
> Return Value
> These calls return the number of bytes received, or -1 if an error occurred.
> The return value will be 0 when the peer has performed an orderly shutdown.
Not too sure how one is supposed to make the difference between a packet of
size 0 and a closed connection.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6407
Diffstat (limited to 'spec/ruby/library/socket/basicsocket/recv_spec.rb')
-rw-r--r-- | spec/ruby/library/socket/basicsocket/recv_spec.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/ruby/library/socket/basicsocket/recv_spec.rb b/spec/ruby/library/socket/basicsocket/recv_spec.rb index b6ccda5d00..a56114f4ab 100644 --- a/spec/ruby/library/socket/basicsocket/recv_spec.rb +++ b/spec/ruby/library/socket/basicsocket/recv_spec.rb @@ -32,6 +32,25 @@ describe "BasicSocket#recv" do ScratchPad.recorded.should == 'hello' end + ruby_version_is "3.3" do + it "returns nil on a closed stream socket" do + t = Thread.new do + client = @server.accept + packet = client.recv(10) + client.close + packet + end + + Thread.pass while t.status and t.status != "sleep" + t.status.should_not be_nil + + socket = TCPSocket.new('127.0.0.1', @port) + socket.close + + t.value.should be_nil + end + end + platform_is_not :solaris do it "accepts flags to specify unusual receiving behaviour" do t = Thread.new do |