Class: Moped::Connection::TCPSocket Private
- Defined in:
- lib/moped/connection.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
This is a wrapper around a tcp socket.
Instance Attribute Summary collapse
- #host ⇒ Object readonly private
- #port ⇒ Object readonly private
Class Method Summary collapse
-
.connect(host, port, timeout) ⇒ TCPSocket
private
Connect to the tcp server.
Instance Method Summary collapse
-
#alive? ⇒ true, false
private
Is the socket connection alive?.
-
#initialize(host, port, *args) ⇒ TCPSocket
constructor
private
Initialize the new TCPSocket.
-
#read(length) ⇒ Object
private
Read from the TCP socket.
-
#write(*args) ⇒ Integer
private
Write to the socket.
Constructor Details
#initialize(host, port, *args) ⇒ TCPSocket
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the new TCPSocket.
205 206 207 208 |
# File 'lib/moped/connection.rb', line 205 def initialize(host, port, *args) @host, @port = host, port handle_socket_errors { super } end |
Instance Attribute Details
#host ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
178 179 180 |
# File 'lib/moped/connection.rb', line 178 def host @host end |
#port ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
178 179 180 |
# File 'lib/moped/connection.rb', line 178 def port @port end |
Class Method Details
.connect(host, port, timeout) ⇒ TCPSocket
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Connect to the tcp server.
262 263 264 265 266 267 268 269 |
# File 'lib/moped/connection.rb', line 262 def connect(host, port, timeout) Timeout::timeout(timeout) do sock = new(host, port) sock.set_encoding('binary') sock.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) sock end end |
Instance Method Details
#alive? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Is the socket connection alive?
188 189 190 191 192 193 194 |
# File 'lib/moped/connection.rb', line 188 def alive? if Kernel::select([ self ], nil, nil, 0) !eof? rescue false else true end end |
#read(length) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Read from the TCP socket.
217 218 219 |
# File 'lib/moped/connection.rb', line 217 def read(length) handle_socket_errors { super } end |
#write(*args) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Write to the socket.
231 232 233 234 |
# File 'lib/moped/connection.rb', line 231 def write(*args) raise Errors::ConnectionFailure, "Socket connection was closed by remote host" unless alive? handle_socket_errors { super } end |