Module: Moped::Connection::Socket::Connectable

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

Overview

Since:

  • 2.0.0

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#hostObject (readonly)

Since:

  • 2.0.0



6
7
8
# File 'lib/moped/connection/socket/connectable.rb', line 6

def host
  @host
end

#portObject (readonly)

Since:

  • 2.0.0



6
7
8
# File 'lib/moped/connection/socket/connectable.rb', line 6

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



34
35
36
# File 'lib/moped/connection/socket/connectable.rb', line 34

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



16
17
18
19
20
21
22
23
24
# File 'lib/moped/connection/socket/connectable.rb', line 16

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:

  • (Object)

    The data.

Since:

  • 1.2.0



45
46
47
48
# File 'lib/moped/connection/socket/connectable.rb', line 45

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



60
61
62
63
# File 'lib/moped/connection/socket/connectable.rb', line 60

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