1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64180 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
eregon 2018-08-03 16:19:40 +00:00
parent aeeaadaad0
commit b53cf149ad
246 changed files with 9108 additions and 548 deletions

View file

@ -1,5 +1,5 @@
# -*- encoding: binary -*-
require_relative '../../../spec_helper'
require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "BasicSocket#recv" do
@ -92,3 +92,68 @@ describe "BasicSocket#recv" do
socket.close
end
end
describe 'BasicSocket#recv' do
SocketSpecs.each_ip_protocol do |family, ip_address|
before do
@server = Socket.new(family, :DGRAM)
@client = Socket.new(family, :DGRAM)
end
after do
@client.close
@server.close
end
describe 'using an unbound socket' do
it 'blocks the caller' do
lambda { @server.recv(4) }.should block_caller
end
end
describe 'using a bound socket' do
before do
@server.bind(Socket.sockaddr_in(0, ip_address))
end
describe 'without any data available' do
it 'blocks the caller' do
lambda { @server.recv(4) }.should block_caller
end
end
describe 'with data available' do
before do
@client.connect(@server.getsockname)
end
it 'reads the given amount of bytes' do
@client.write('hello')
@server.recv(2).should == 'he'
end
it 'reads the given amount of bytes when it exceeds the data size' do
@client.write('he')
@server.recv(6).should == 'he'
end
it 'blocks the caller when called twice without new data being available' do
@client.write('hello')
@server.recv(2).should == 'he'
lambda { @server.recv(4) }.should block_caller
end
it 'takes a peek at the data when using the MSG_PEEK flag' do
@client.write('hello')
@server.recv(2, Socket::MSG_PEEK).should == 'he'
@server.recv(2).should == 'he'
end
end
end
end
end