Skip to content
Browse files

SO_SNDTIMO and SO_RCVTIMEO must be set before connect

  • Loading branch information...
1 parent 668521e commit 2abfea76e965380e20fff915b816e402c6a9f507 @rtomayko rtomayko committed Feb 4, 2010
Showing with 3 additions and 1 deletion.
  1. +3 −1 lib/bertrpc/action.rb
View
4 lib/bertrpc/action.rb
@@ -57,7 +57,8 @@ def transaction(bert_request)
# +port+ Integer port of the target TCP server
# +timeout+ Optional Integer (in seconds) of the read timeout
def connect_to(host, port, timeout = nil)
- sock = TCPSocket.new(host, port)
+ addr = Socket.getaddrinfo(host, nil)
+ sock = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)
sock.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1
if timeout
@@ -68,6 +69,7 @@ def connect_to(host, port, timeout = nil)
sock.setsockopt Socket::SOL_SOCKET, Socket::SO_SNDTIMEO, optval
end
+ sock.connect(Socket.pack_sockaddr_in(port, addr[0][3]))
sock
end
end

0 comments on commit 2abfea7

Please sign in to comment.
Something went wrong with that request. Please try again.