Class: Coolio::Socket::Connector

Inherits:
IOWatcher show all
Defined in:
lib/cool.io/socket.rb

Instance Method Summary collapse

Methods inherited from IOWatcher

#attach, #detach, #disable, #enable, #on_readable

Methods included from Meta

#event_callback, #watcher_delegate

Methods inherited from Watcher

#attach, #attached?, #detach, #disable, #enable, #enabled?, #evloop

Constructor Details

#initialize(coolio_socket, ruby_socket) ⇒ Connector

Returns a new instance of Connector.


59
60
61
62
# File 'lib/cool.io/socket.rb', line 59

def initialize(coolio_socket, ruby_socket)
  @coolio_socket, @ruby_socket = coolio_socket, ruby_socket
  super(ruby_socket, :w)
end

Instance Method Details

#on_writableObject


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/cool.io/socket.rb', line 64

def on_writable
  evl = evloop
  detach

  if connect_successful?
    @coolio_socket.instance_eval { @_connector = nil }
    @coolio_socket.attach(evl)
    @ruby_socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, [1].pack("l"))
    @ruby_socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_KEEPALIVE, true)

    @coolio_socket.__send__(:on_connect)
  else
    @coolio_socket.instance_eval { @_failed = true }
    @coolio_socket.__send__(:on_connect_failed)
  end
end