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,4 +1,4 @@
require_relative '../../../spec_helper'
require_relative '../spec_helper'
require_relative '../fixtures/classes'
describe "BasicSocket#send" do
@ -83,3 +83,132 @@ describe "BasicSocket#send" do
data.should == 'hello'
end
end
describe 'BasicSocket#send' do
SocketSpecs.each_ip_protocol do |family, ip_address|
describe 'using a disconnected socket' do
before do
@client = Socket.new(family, :DGRAM)
@server = Socket.new(family, :DGRAM)
@server.bind(Socket.sockaddr_in(0, ip_address))
end
after do
@client.close
@server.close
end
describe 'without a destination address' do
it "raises #{SocketSpecs.dest_addr_req_error}" do
lambda { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error)
end
end
describe 'with a destination address as a String' do
it 'returns the amount of sent bytes' do
@client.send('hello', 0, @server.getsockname).should == 5
end
it 'does not persist the connection after writing to the socket' do
@client.send('hello', 0, @server.getsockname)
lambda { @client.send('hello', 0) }.should raise_error(SocketSpecs.dest_addr_req_error)
end
end
describe 'with a destination address as an Addrinfo' do
it 'returns the amount of sent bytes' do
@client.send('hello', 0, @server.connect_address).should == 5
end
end
end
describe 'using a connected UDP socket' do
before do
@client = Socket.new(family, :DGRAM)
@server = Socket.new(family, :DGRAM)
@server.bind(Socket.sockaddr_in(0, ip_address))
end
after do
@client.close
@server.close
end
describe 'without a destination address argument' do
before do
@client.connect(@server.getsockname)
end
it 'returns the amount of bytes written' do
@client.send('hello', 0).should == 5
end
end
describe 'with a destination address argument' do
before do
@alt_server = Socket.new(family, :DGRAM)
@alt_server.bind(Socket.sockaddr_in(0, ip_address))
end
after do
@alt_server.close
end
it 'sends the message to the given address instead' do
@client.send('hello', 0, @alt_server.getsockname).should == 5
lambda { @server.recv(5) }.should block_caller
@alt_server.recv(5).should == 'hello'
end
it 'does not persist the alternative connection after writing to the socket' do
@client.send('hello', 0, @alt_server.getsockname)
@client.connect(@server.getsockname)
@client.send('world', 0)
@server.recv(5).should == 'world'
end
end
end
platform_is_not :windows do
describe 'using a connected TCP socket' do
before do
@client = Socket.new(family, :STREAM)
@server = Socket.new(family, :STREAM)
@server.bind(Socket.sockaddr_in(0, ip_address))
@server.listen(1)
@client.connect(@server.getsockname)
end
after do
@client.close
@server.close
end
describe 'using the MSG_OOB flag' do
it 'sends an out-of-band message' do
@server.setsockopt(:SOCKET, :OOBINLINE, true)
@client.send('a', Socket::MSG_OOB).should == 1
socket, _ = @server.accept
begin
socket.recv(1, Socket::MSG_OOB).should == 'a'
ensure
socket.close
end
end
end
end
end
end
end