Skip to content

Commit

Permalink
connect to socket in nonblock mode, bump 1.1.7
Browse files Browse the repository at this point in the history
  • Loading branch information
senid231 committed Feb 4, 2020
1 parent 744799c commit 9e1daac
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
17 changes: 13 additions & 4 deletions lib/jrpc/transport/socket_tcp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,25 @@ def set_timeout_to(socket, type, value)
def build_socket
host = @server.split(':').first
addr = Socket.getaddrinfo(host, nil)
sock = Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)
set_timeout_to(sock, Socket::SO_RCVTIMEO, @connect_timeout) if @connect_timeout
sock
Socket.new(Socket.const_get(addr[0][0]), Socket::SOCK_STREAM, 0)
end

def connect_socket
host, port = @server.split(':')
addr = Socket.getaddrinfo(host, nil)
full_addr = Socket.pack_sockaddr_in(port, addr[0][3])
socket.connect(full_addr)

begin
socket.connect_nonblock(full_addr)
rescue IO::WaitWritable => _
if IO.select(nil, [socket], nil, @connect_timeout)
socket.connect_nonblock(full_addr)
else
clear_socket!
raise ConnectionFailedError, "Can't connect during #{@connect_timeout}"
end
end

rescue Errno::EISCONN => _
# already connected
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH, Errno::ETIMEDOUT, Errno::EPIPE => e
Expand Down
2 changes: 1 addition & 1 deletion lib/jrpc/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module JRPC
VERSION = '1.1.6'
VERSION = '1.1.7'
end

0 comments on commit 9e1daac

Please sign in to comment.