From 7bb1c28f811d89feb2538f36afae64312db12640 Mon Sep 17 00:00:00 2001 From: Mark Eschbach Date: Tue, 2 Feb 2016 12:49:49 -0800 Subject: [PATCH] Use the correct port when 0 is passed --- lib/thin/backends/tcp_server.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/thin/backends/tcp_server.rb b/lib/thin/backends/tcp_server.rb index 0f2b38ee..5a70dfcc 100644 --- a/lib/thin/backends/tcp_server.rb +++ b/lib/thin/backends/tcp_server.rb @@ -4,26 +4,31 @@ module Backends class TcpServer < Base # Address and port on which the server is listening for connections. attr_accessor :host, :port - + def initialize(host, port) @host = host @port = port super() end - + # Connect the server def connect @signature = EventMachine.start_server(@host, @port, Connection, &method(:initialize_connection)) + binary_name = EventMachine.get_sockname( @signature ) + port_name = Socket.unpack_sockaddr_in( binary_name ) + @port = port_name[0] + @host = port_name[1] + @signature end - + # Stops the server def disconnect EventMachine.stop_server(@signature) end - + def to_s "#{@host}:#{@port}" end end end -end \ No newline at end of file +end