Module: Bones::RPC::Connection::Socket::Connectable::ClassMethods
- Defined in:
- lib/bones/rpc/connection/socket/connectable.rb
Overview
Instance Method Summary collapse
-
#connect(host, port, timeout) ⇒ TCPSocket
Connect to the tcp server.
Instance Method Details
#connect(host, port, timeout) ⇒ TCPSocket
Connect to the tcp server.
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/bones/rpc/connection/socket/connectable.rb', line 176 def connect(host, port, timeout) begin Timeout::timeout(timeout) do sock = new(host, port) sock.set_encoding('binary') timeout_val = [ timeout, 0 ].pack("l_2") sock.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_RCVTIMEO, timeout_val) sock.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_SNDTIMEO, timeout_val) sock end rescue Timeout::Error raise Errors::ConnectionFailure, "Timed out connection to Bones RPC on #{host}:#{port}" end end |