git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@668997
13f79535-47bb-0310-9956-
ffa450edef68
deprecate_class! :TSocket => Socket
class ServerSocket < ServerTransport
- def initialize(port)
- @port = port
+ # call-seq: initialize(host = nil, port)
+ def initialize(host_or_port, port = nil)
+ if port
+ @host = host_or_port
+ @port = port
+ else
+ @host = nil
+ @port = host_or_port
+ end
@handle = nil
end
attr_reader :handle
def listen
- @handle = TCPServer.new(nil, @port)
+ @handle = TCPServer.new(@host, @port)
end
def accept
@socket.handle.should be_an_instance_of(TCPServer)
end
+ it "should accept an optional host argument" do
+ @socket = ServerSocket.new('localhost', 1234)
+ TCPServer.should_receive(:new).with('localhost', 1234)
+ @socket.listen
+ end
+
it "should create a Thrift::Socket to wrap accepted sockets" do
handle = mock("TCPServer")
TCPServer.should_receive(:new).with(nil, 1234).and_return(handle)