Class/Module Index [+]

Quicksearch

Moped::Sockets::Connectable

Attributes

host[R]
port[R]

Public Class Methods

included(klass) click to toggle source

Bring in the class methods when included.

@example Extend the class methods.

Connectable.included(class)

@param [ Class ] klass The class including the module.

@since 1.3.0

# File lib/moped/sockets/connectable.rb, line 33
def self.included(klass)
  klass.send(:extend, ClassMethods)
end

Public Instance Methods

alive?() click to toggle source

Is the socket connection alive?

@example Is the socket alive?

socket.alive?

@return [ true, false ] If the socket is alive.

@since 1.0.0

# File lib/moped/sockets/connectable.rb, line 15
def alive?
  if Kernel::select([ self ], nil, nil, 0)
    !eof? rescue false
  else
    true
  end
rescue IOError
  false
end
read(length) click to toggle source

Read from the TCP socket.

@param [ Integer ] length The length to read.

@return [ Object ] The data.

@since 1.2.0

# File lib/moped/sockets/connectable.rb, line 44
def read(length)
  handle_socket_errors { super }
end
write(*args) click to toggle source

Write to the socket.

@example Write to the socket.

socket.write(data)

@param [ Object ] args The data to write.

@return [ Integer ] The number of bytes written.

@since 1.0.0

# File lib/moped/sockets/connectable.rb, line 58
def write(*args)
  raise Errors::ConnectionFailure, "Socket connection was closed by remote host" unless alive?
  handle_socket_errors { super }
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.