vendor/bundle/ruby/2.7.0/gems/dnsruby-1.61.5/lib/dnsruby/packet_sender.rb
#  This method returns the current tcp socket for pipelining
#  If this is the first time the method is called then the socket is bound to
#  @src_address:@src_port and connected to the remote dns server @server:@port.
#  If the connection has been closed because of an EOF on recv_nonblock (closed by server)
#  the function will recreate of the socket (since @pipeline_socket.connect will result in a IOError
#  exception)
#  In general, every subsequent call the function will either return the current tcp
#  pipeline socket or a new connected socket if the current one was closed by the server
This method returns the current tcp socket for pipelining
If this is the first time the method is called then the socket is bound to
This method returns the current tcp socket for pipelining If this is the first time the method is called then the socket is bound to
def tcp_pipeline_socket(src_port)
      Dnsruby.log.debug("Using tcp_pipeline_socket")
      sockaddr = Socket.sockaddr_in(@port, @server)
      reuse_pipeline_socket = -> do
        begin
          max = @tcp_pipelining_max_queries
          use_count = @use_counts[@pipeline_socket]
          if use_count && max != :infinite && use_count >= max
            @use_counts.delete(@pipeline_socket)
            @pipeline_socket = nil
            Dnsruby.log.debug("Max queries per connection attained - creating new socket")
          else
            @pipeline_socket.connect(sockaddr)
          end
        rescue Errno::EISCONN
        rescue IOError, Errno::ECONNRESET 
          @pipeline_socket = nil
          Dnsruby.log.debug("Connection closed - recreating socket")
        end
      end
      create_pipeline_socket = -> do
        @tcp_pipeline_local_port = src_port
        src_address = @ipv6 ? @src_address6 : @src_address
        begin
          @pipeline_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)
          @pipeline_socket.bind(Addrinfo.tcp(src_address, src_port))
          @pipeline_socket.connect(sockaddr)
          Dnsruby.log.debug("Creating socket #{src_address}:#{src_port}")
          @use_counts[@pipeline_socket] = 0
        rescue Exception => e
          @pipeline_socket = nil
          raise e
        end
      end
      reuse_pipeline_socket.() if @pipeline_socket
      new_socket = @pipeline_socket.nil?
      create_pipeline_socket.() unless @pipeline_socket
      @use_counts[@pipeline_socket] += 1
      [@pipeline_socket, new_socket]
    end
def tcp_pipeline_socket ( src_port ) Dnsruby . log . debug ( "Using tcp_pipeline_socket" ) sockaddr = Socket . sockaddr_in ( @port , @server ) reuse_pipeline_socket = -> do begin max = @tcp_pipelining_max_queries use_count = @use_counts [ @pipeline_socket ] if use_count && max != :infinite && use_count >= max @use_counts . delete ( @pipeline_socket ) @pipeline_socket = nil Dnsruby . log . debug ( "Max queries per connection attained - creating new socket" ) else @pipeline_socket . connect ( sockaddr ) end rescue Errno :: EISCONN rescue IOError , Errno :: ECONNRESET @pipeline_socket = nil Dnsruby . log . debug ( "Connection closed - recreating socket" ) end end create_pipeline_socket = -> do @tcp_pipeline_local_port = src_port src_address = @ipv6 ? @src_address6 : @src_address begin @pipeline_socket = Socket . new ( Socket :: AF_INET , Socket :: SOCK_STREAM , 0 ) @pipeline_socket . bind ( Addrinfo . tcp ( src_address , src_port ) ) @pipeline_socket . connect ( sockaddr ) Dnsruby . log . debug ( "Creating socket #{src_address}:#{src_port}" ) @use_counts [ @pipeline_socket ] = 0 rescue Exception => e @pipeline_socket = nil raise e end end reuse_pipeline_socket . ( ) if @pipeline_socket new_socket = @pipeline_socket . nil? create_pipeline_socket . ( ) unless @pipeline_socket @use_counts [ @pipeline_socket ] += 1 [ @pipeline_socket , new_socket ] end
This method returns the current tcp socket for pipelining
If this is the first time the method is called then the socket is bound to
This method returns the current tcp socket for pipelining If this is the first time the method is called then the socket is bound to
#we can't reuse the socket since max is reached #already connected, do nothing and reuse! #close by remote host, reconnect # Don't combine the following 2 statements; the reuse lambda can set the # socket to nil and if so we'd want to call the create lambda to recreate it.
src_port
<not_specific>
src_address:@src_port
and connected to the remote dns server @server:@port. If the connection has been closed because of an EOF on recv_nonblock (closed by server) the function will recreate of the socket (since @pipeline_socket.connect will result in a IOError exception) In general, every subsequent call the function will either return the current tcp pipeline socket or a new connected socket if the current one was closed by the server
and connected to the remote dns server @server : @port . If the connection has been closed because of an EOF on recv_nonblock ( closed by server ) the function will recreate of the socket ( since @pipeline_socket . connect will result in a IOError exception ) In general every subsequent call the function will either return the current tcp pipeline socket or a new connected socket if the current one was closed by the server