vendor/bundle/ruby/1.8/gems/daemon_controller-1.0.0/lib/daemon_controller.rb
def connect
		connection = nil
		@lock_file.shared_lock do
			begin
				connection = yield
			rescue *ALLOWED_CONNECT_EXCEPTIONS
				connection = nil
			end
		end
		if connection.nil?
			@lock_file.exclusive_lock do
				if !daemon_is_running?
					start_without_locking
				end
				connect_exception = nil
				begin
					connection = yield
				rescue *ALLOWED_CONNECT_EXCEPTIONS => e
					connection = nil
					connect_exception = e
				end
				if connection.nil?
					# Daemon is running but we couldn't connect to it. Possible
					# reasons:
					# - The daemon froze.
					# - Bizarre security restrictions.
					# - There's a bug in the yielded code.
					if connect_exception
						raise ConnectError, "Cannot connect to the daemon: #{connect_exception} (#{connect_exception.class})"
					else
						raise ConnectError, "Cannot connect to the daemon"
					end
				else
					return connection
				end
			end
		else
			return connection
		end
	end
# Connect to the daemon by running the given block, which contains the
# connection logic. If the daemon isn't already running, then it will be
# started.
#
# The block must return nil or raise Errno::ECONNREFUSED, Errno::ENETUNREACH,
# Errno::ETIMEDOUT, Errno::ECONNRESET, Errno::EINVAL and Errno::EADDRNOTAVAIL
# to indicate that the daemon cannot be
# connected to. It must return non-nil if the daemon can be connected to.
# Upon successful connection, the return value of the block will
# be returned by #connect.
#
# Note that the block may be called multiple times.
#
# Raises:
# - StartError - an attempt to start the daemon was made, but the start
#   command failed with an error.
# - StartTimeout - an attempt to start the daemon was made, but the daemon
#   did not start in time, or it failed after it has gone into the background.
# - ConnectError - the daemon wasn't already running, but we couldn't connect
#   to the daemon even after starting it.
Connect to the daemon by running the given block, which contains the
connection logic. If the daemon isn't already running, then it will be
started.



Note that the block may be called multiple times.

an attempt to start the daemon was made, but the start
command failed with an error.
StartTimeout - an attempt to start the daemon was made, but the daemon
did not start in time, or it failed after it has gone into the background.
ConnectError - the daemon wasn't already running, but we couldn't connect
to the daemon even after starting it.
Connect to the daemon by running the given block which contains the connection logic . If the daemon isn ' t already running then it will be started . Note that the block may be called multiple times . an attempt to start the daemon was made but the start command failed with an error . StartTimeout - an attempt to start the daemon was made but the daemon did not start in time or it failed after it has gone into the background . ConnectError - the daemon wasn ' t already running but we couldn ' t connect to the daemon even after starting it .
def connect
		connection = nil
		@lock_file.shared_lock do
			begin
				connection = yield
			rescue *ALLOWED_CONNECT_EXCEPTIONS
				connection = nil
			end
		end
		if connection.nil?
			@lock_file.exclusive_lock do
				if !daemon_is_running?
					start_without_locking
				end
				connect_exception = nil
				begin
					connection = yield
				rescue *ALLOWED_CONNECT_EXCEPTIONS => e
					connection = nil
					connect_exception = e
				end
				if connection.nil?
					if connect_exception
						raise ConnectError, "Cannot connect to the daemon: #{connect_exception} (#{connect_exception.class})"
					else
						raise ConnectError, "Cannot connect to the daemon"
					end
				else
					return connection
				end
			end
		else
			return connection
		end
	end
def connect connection = nil @lock_file . shared_lock do begin connection = yield rescue * ALLOWED_CONNECT_EXCEPTIONS connection = nil end end if connection . nil? @lock_file . exclusive_lock do if ! daemon_is_running? start_without_locking end connect_exception = nil begin connection = yield rescue * ALLOWED_CONNECT_EXCEPTIONS => e connection = nil connect_exception = e end if connection . nil? if connect_exception raise ConnectError , "Cannot connect to the daemon: #{connect_exception} (#{connect_exception.class})" else raise ConnectError , "Cannot connect to the daemon" end else return connection end end else return connection end end
Connect to the daemon by running the given block, which contains the
connection logic.
Connect to the daemon by running the given block which contains the connection logic .
# Daemon is running but we couldn't connect to it. Possible # reasons: # - The daemon froze. # - Bizarre security restrictions. # - There's a bug in the yielded code.