Class: Coolio::Socket

Inherits:
IO
  • Object
show all
Defined in:
lib/cool.io/socket.rb

Direct Known Subclasses

TCPSocket, UNIXSocket

Defined Under Namespace

Classes: Connector

Constant Summary

Constants inherited from IO

IO::INPUT_SIZE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from IO

#attached?, #close, #closed?, #detach, #disable, #enable, #enabled?, #evloop, #on_close, #on_read, #on_write_complete, #write

Methods included from Meta

#event_callback, #watcher_delegate

Constructor Details

#initialize(*args) ⇒ Socket

Just initializes some instance variables to avoid warnings and calls super().



22
23
24
25
26
# File 'lib/cool.io/socket.rb', line 22

def initialize *args
  @_failed = nil
  @_connector = nil
  super
end

Class Method Details

.connect(socket, *args) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/cool.io/socket.rb', line 12

def self.connect(socket, *args)

  new(socket, *args).instance_eval do
    @_connector = Connector.new(self, socket)
    self
  end
end

Instance Method Details

#attach(evloop) ⇒ Object

Raises:

  • (RuntimeError)


31
32
33
34
35
36
37
38
39
40
# File 'lib/cool.io/socket.rb', line 31

def attach(evloop)
  raise RuntimeError, "connection failed" if @_failed

  if @_connector
    @_connector.attach(evloop)
    return self
  end

  super
end

#on_connectObject

Called upon completion of a socket connection



43
# File 'lib/cool.io/socket.rb', line 43

def on_connect; end

#on_connect_failedObject Also known as: on_resolve_failed

Called if a socket connection failed to complete



47
# File 'lib/cool.io/socket.rb', line 47

def on_connect_failed; end