Corey Jewett
2007-Aug-06 00:02 UTC
[Mongrel] [Patch] HttpServer.port reports the bound port
This is for when you pass mongrel 0 for the port and the OS assigns an open one. Corey --- mongrel-1.0.1/lib/mongrel.rb 2007-08-05 15:29:59.000000000 -0700 +++ mongrel-1.0.1/lib/mongrel.rb.zero_port_fix 2007-08-05 15:29:23.000000000 -0700 @@ -560,7 +560,7 @@ @socket = TCPServer.new(host, port) @classifier = URIClassifier.new @host = host - @port = port + @port = @socket.addr[1] @workers = ThreadGroup.new @timeout = timeout @num_processors = num_processors
Zed A. Shaw
2007-Aug-06 05:32 UTC
[Mongrel] [Patch] HttpServer.port reports the bound port
On Sun, 5 Aug 2007 17:02:12 -0700 Corey Jewett <ml at syntheticplayground.com> wrote:> This is for when you pass mongrel 0 for the port and the OS assigns > an open one. > > CoreyDoes that work on Windows? :-) (Gets them every time.) -- Zed A. Shaw - Hate: http://savingtheinternetwithhate.com/ - Good: http://www.zedshaw.com/ - Evil: http://yearofevil.com/
Corey Jewett
2007-Aug-06 07:08 UTC
[Mongrel] [Patch] HttpServer.port reports the bound port
On Aug 5, 2007, at 10:32 PM, Zed A. Shaw wrote:> On Sun, 5 Aug 2007 17:02:12 -0700 > Corey Jewett <ml at syntheticplayground.com> wrote: > >> This is for when you pass mongrel 0 for the port and the OS assigns >> an open one. >> >> Corey > > Does that work on Windows? :-) (Gets them every time.)What''sat? Does anything good work there? I just figured that if it''s good enough for Webrick, it''s certainly good enough for mongrel. ;) Corey
Steven Lumos
2007-Aug-06 21:42 UTC
[Mongrel] [Patch] HttpServer.port reports the bound port
"Zed A. Shaw" <zedshaw at zedshaw.com> writes:> On Sun, 5 Aug 2007 17:02:12 -0700 > Corey Jewett <ml at syntheticplayground.com> wrote: > >> This is for when you pass mongrel 0 for the port and the OS assigns >> an open one. >> >> Corey > > Does that work on Windows? :-) (Gets them every time.)Well, they just ripped off Berkeley sockets, right? This is v1.8.2 of the one-click installer. I''ll bother to update it if anyone thinks it matters. irb(main):001:0> require ''socket'' => true irb(main):002:0> s = TCPServer.new(0) => #<TCPServer:0x2dc4930> irb(main):003:0> s.addr => ["AF_INET", 1110, "0.0.0.0", "0.0.0.0"] irb(main):004:0> Steve
Luis Lavena
2007-Aug-06 21:54 UTC
[Mongrel] [Patch] HttpServer.port reports the bound port
On 8/6/07, Steven Lumos <steven at lumos.us> wrote:> "Zed A. Shaw" <zedshaw at zedshaw.com> writes: > > > On Sun, 5 Aug 2007 17:02:12 -0700 > > Corey Jewett <ml at syntheticplayground.com> wrote: > > > >> This is for when you pass mongrel 0 for the port and the OS assigns > >> an open one. > >> > >> Corey > > > > Does that work on Windows? :-) (Gets them every time.) > > Well, they just ripped off Berkeley sockets, right? >yes and no, sockets are a bit tricky on windows, but in this case, isolation of Ruby VM play on our side.> This is v1.8.2 of the one-click installer. I''ll bother to update it > if anyone thinks it matters. > > irb(main):001:0> require ''socket'' > => true > irb(main):002:0> s = TCPServer.new(0) > => #<TCPServer:0x2dc4930> > irb(main):003:0> s.addr > => ["AF_INET", 1110, "0.0.0.0", "0.0.0.0"] > irb(main):004:0> >Confirmed, 1.8.5 behaves the same way like 1.8.2, since addr is the Array with [Protocol, Port, ServerIP, ClientIP]. Anyway, what is the purpose of a random HTTPServer port? If you try to open a mongrel server in an already taken port, a error must be shown, instead of a false positive. -- Luis Lavena Multimedia systems - Leaders are made, they are not born. They are made by hard effort, which is the price which all of us must pay to achieve any goal that is worthwhile. Vince Lombardi