Class: OMQ::Transport::TCP::Dialer

Inherits:
Object
  • Object
show all
Defined in:
lib/omq/transport/tcp.rb

Overview

A TCP dialer — stateful factory for outgoing connections.

Created once per Engine#connect, stored in @dialers. Reconnect calls #connect directly — no transport lookup or opts replay needed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, engine) ⇒ Dialer

Returns a new instance of Dialer.

Parameters:

  • endpoint (String)

    e.g. “tcp://127.0.0.1:5555”

  • engine (Engine)


159
160
161
162
# File 'lib/omq/transport/tcp.rb', line 159

def initialize(endpoint, engine)
  @endpoint = endpoint
  @engine   = engine
end

Instance Attribute Details

#endpointString (readonly)

Returns the endpoint this dialer connects to.

Returns:

  • (String)

    the endpoint this dialer connects to



153
154
155
# File 'lib/omq/transport/tcp.rb', line 153

def endpoint
  @endpoint
end

Instance Method Details

#connectvoid

This method returns an undefined value.

Establishes a TCP connection to the endpoint.



169
170
171
172
173
174
175
# File 'lib/omq/transport/tcp.rb', line 169

def connect
  host, port = TCP.parse_endpoint(@endpoint)
  host       = TCP.normalize_connect_host(host)
  sock       = ::Socket.tcp(host, port, connect_timeout: TCP.connect_timeout(@engine.options))
  TCP.apply_buffer_sizes(sock, @engine.options)
  @engine.handle_connected(IO::Stream::Buffered.wrap(sock), endpoint: @endpoint)
end