Skip to content

Commit

Permalink
Spec the new output buffer argument for recv/recv_nonblock
Browse files Browse the repository at this point in the history
* See #175.
  • Loading branch information
eregon committed Nov 27, 2016
1 parent 600d305 commit e000de6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
14 changes: 14 additions & 0 deletions library/socket/basicsocket/recv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,18 @@
ScratchPad.recorded.should == "firstline\377"
end

ruby_version_is "2.3" do
it "allows an output buffer as third argument" do
socket = TCPSocket.new('127.0.0.1', SocketSpecs.port)
socket.write("data")

client = @server.accept
buf = "foo"
client.recv(4, 0, buf)
client.close
buf.should == "data"

socket.close
end
end
end
12 changes: 12 additions & 0 deletions library/socket/shared/recv_nonblock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@
@s1.recv_nonblock(5).should == "aaa"
end

ruby_version_is "2.3" do
it "allows an output buffer as third argument" do
@s1.bind(Socket.pack_sockaddr_in(SocketSpecs.port, "127.0.0.1"))
@s2.send("data", 0, @s1.getsockname)
IO.select([@s1], nil, nil, 2)

buf = "foo"
@s1.recv_nonblock(5, 0, buf)
buf.should == "data"
end
end

it "does not block if there's no data available" do
@s1.bind(Socket.pack_sockaddr_in(SocketSpecs.port, "127.0.0.1"))
@s2.send("a", 0, @s1.getsockname)
Expand Down

0 comments on commit e000de6

Please sign in to comment.