Module: Moped::Sockets::Connectable
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Class Method Summary collapse
-
.included(klass) ⇒ Object
Bring in the class methods when included.
Instance Method Summary collapse
-
#alive? ⇒ true, false
Is the socket connection alive?.
-
#read(length) ⇒ Object
Read from the TCP socket.
-
#write(*args) ⇒ Integer
Write to the socket.
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
5 6 7 |
# File 'lib/moped/sockets/connectable.rb', line 5 def host @host end |
#port ⇒ Object (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.
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?
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.
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.
59 60 61 62 |
# File 'lib/moped/sockets/connectable.rb', line 59 def write(*args) check_if_alive! handle_socket_errors { super } end |