Sha256: fa7a4a7cc6a8a0bfbeac26b64e3adeedd3d42547db438c017e501acb19d1329e

Contents?: true

Size: 735 Bytes

Versions: 4

Compression:

Stored size: 735 Bytes

Contents

require File.expand_path('../../fixtures/classes', __FILE__)
require 'socket'

describe "Socket.for_fd" do
  before :each do
    @server = TCPServer.new("127.0.0.1", SocketSpecs.port)
    @client = TCPSocket.open("127.0.0.1", SocketSpecs.port)
  end

  after :each do
    @socket.shutdown Socket::SHUT_RD if @socket
    @client.shutdown Socket::SHUT_WR

    @host.close if @host
    @server.close
  end

  it "creates a new Socket that aliases the existing Socket's file descriptor" do
    @socket = Socket.for_fd(@client.fileno)
    @socket.fileno.should == @client.fileno

    @socket.send("foo", 0)
    @client.send("bar", 0)

    @host = @server.accept
    @host.read(3).should == "foo"
    @host.read(3).should == "bar"
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rubysl-socket-1.0.1 spec/socket/for_fd_spec.rb
rubysl-socket-2.0.1 spec/socket/for_fd_spec.rb
rubysl-socket-1.0.0 spec/socket/for_fd_spec.rb
rubysl-socket-2.0.0 spec/socket/for_fd_spec.rb