lib/mongrel2/control.rb in mongrel2-0.30.1 vs lib/mongrel2/control.rb in mongrel2-0.31.0

- old
+ new

@@ -1,9 +1,10 @@ #!/usr/bin/ruby require 'zmq' require 'yajl' +require 'pathname' require 'tnetstring' require 'loggability' require 'mongrel2' unless defined?( Mongrel2 ) @@ -23,10 +24,11 @@ DEFAULT_PORT = 'ipc://run/control' ### Create a new control port object using the current configuration. def initialize( port=DEFAULT_PORT ) + check_port( port ) @ctx = Mongrel2.zmq_context @socket = @ctx.socket( ZMQ::REQ ) @socket.setsockopt( ZMQ::LINGER, 0 ) @socket.connect( port.to_s ) end @@ -203,9 +205,21 @@ raise Mongrel2::ControlError.new( table['code'], table['error'] ) else raise ScriptError, "Don't know how to handle response: %p" % [ table ] end + end + + + ### Check the path of the specified port if it's an 'ipc' URL, ensuring that a pipe exists + ### there, and raising an exception if none does. + def check_port( port ) + scheme, path = port.split( '://' ) + return unless scheme == 'ipc' + + raise "%s: not a socket" % [ path ] unless FileTest.socket?( path ) + + return true end end # class Mongrel2::Control # vim: set nosta noet ts=4 sw=4: