lib/nonnative/socket_pair.rb in nonnative-1.25.0 vs lib/nonnative/socket_pair.rb in nonnative-1.26.0
- old
+ new
@@ -1,11 +1,12 @@
# frozen_string_literal: true
module Nonnative
class SocketPair
- def initialize(proxy)
+ def initialize(proxy, logger)
@proxy = proxy
+ @logger = logger
end
def connect(local_socket)
remote_socket = create_remote_socket
@@ -13,17 +14,19 @@
ready = select([local_socket, remote_socket], nil, nil)
break if pipe(ready, local_socket, remote_socket)
break if pipe(ready, remote_socket, local_socket)
end
+ rescue StandardError => e
+ logger.error e
ensure
local_socket.close
remote_socket&.close
end
protected
- attr_reader :proxy
+ attr_reader :proxy, :logger
def create_remote_socket
::TCPSocket.new('0.0.0.0', proxy.port)
end