Module: Moped::Sockets::Connectable

Included in:
SSL, TCP
Defined in:
lib/moped/sockets/connectable.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



5
6
7
# File 'lib/moped/sockets/connectable.rb', line 5

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



5
6
7
# File 'lib/moped/sockets/connectable.rb', line 5

def port
  @port
end

Class Method Details

.included(klass) ⇒ Object

Bring in the class methods when included.

Examples:

Extend the class methods.

Connectable.included(class)

Parameters:

  • klass (Class)

    The class including the module.

Since:

  • 1.3.0



33
34
35
# File 'lib/moped/sockets/connectable.rb', line 33

def self.included(klass)
  klass.send(:extend, ClassMethods)
end

Instance Method Details

#alive?true, false

Is the socket connection alive?

Examples:

Is the socket alive?

socket.alive?

Returns:

  • (true, false)

    If the socket is alive.

Since:

  • 1.0.0



15
16
17
18
19
20
21
22
23
# File 'lib/moped/sockets/connectable.rb', line 15

def alive?
  if Kernel::select([ self ], nil, [ self ], 0)
    !eof? rescue false
  else
    true
  end
rescue IOError
  false
end

#read(length) ⇒ Object

Read from the TCP socket.

Parameters:

  • length (Integer)

    The length to read.

Returns:

Since:

  • 1.2.0



44
45
46
47
# File 'lib/moped/sockets/connectable.rb', line 44

def read(length)
  check_if_alive!
  handle_socket_errors { super }
end

#write(*args) ⇒ Integer

Write to the socket.

Examples:

Write to the socket.

socket.write(data)

Parameters:

  • args (Object)

    The data to write.

Returns:

  • (Integer)

    The number of bytes written.

Since:

  • 1.0.0



59
60
61
62
# File 'lib/moped/sockets/connectable.rb', line 59

def write(*args)
  check_if_alive!
  handle_socket_errors { super }
end