Class: EventMachine::CallsBackToEM

Inherits:
Rev::TCPSocket show all
Defined in:
lib/revem.rb

Defined Under Namespace

Classes: ConnectTimer

Constant Summary

Constants inherited from Rev::IO

Rev::IO::INPUT_SIZE

Instance Attribute Summary

Attributes inherited from Rev::TCPSocket

#address_family, #remote_addr, #remote_host, #remote_port

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Rev::TCPSocket

#initialize, #peeraddr, precreate

Methods inherited from Rev::Socket

#attach

Methods inherited from Rev::IO

#attach, #attached?, #close, #closed?, #detach, #disable, #enable, #enabled?, #evloop, #initialize, #output_buffer_size, #write

Methods included from Rev::Meta

#event_callback, #watcher_delegate

Constructor Details

This class inherits a constructor from Rev::TCPSocket

Class Method Details

.connect(*args) ⇒ Object



156
157
158
159
160
161
162
163
# File 'lib/revem.rb', line 156

def self.connect *args
  a = super *args
  # the connect timer currently kills TCPServer classes.  I'm not sure why.
  #@connection_timer = ConnectTimer.new(14) # needs to be at least higher than 12 :)
  #@connection_timer.parent = a
  #@connection_timer.attach(Rev::Loop.default)
  a
end

Instance Method Details

#call_back_to_this(parent) ⇒ Object



113
114
115
116
# File 'lib/revem.rb', line 113

def call_back_to_this parent
  @call_back_to_this = parent
  parent.post_init
end

#connection_has_timed_outObject



123
124
125
126
127
# File 'lib/revem.rb', line 123

def connection_has_timed_out
  return if closed?
  close unless closed? # wonder if this works when you're within a half-connected phase.  I think it does.  What about TCP state?
  @call_back_to_this.unbind
end

#failObject



151
152
153
154
# File 'lib/revem.rb', line 151

def fail
  #@connection_timer.detch if @connection_timer
  @call_back_to_this.unbind
end

#on_closeObject



135
136
137
# File 'lib/revem.rb', line 135

def on_close
  @call_back_to_this.unbind # about the same ltodo check if they ARE the same here
end

#on_connectObject



118
119
120
121
# File 'lib/revem.rb', line 118

def on_connect
  # @connection_timer.detach if @connection_timer # won't need that anymore :) -- with server connecteds we don't have it, anyway
  @call_back_to_this.connection_completed if @call_back_to_this # TODO should server accepted's call this? They don't currently [and can't, since on_connect gets called basically in the initializer--needs some code love for that to happen :)
end

#on_connect_failedObject



143
144
145
# File 'lib/revem.rb', line 143

def on_connect_failed
  fail
end

#on_read(data) ⇒ Object



147
148
149
# File 'lib/revem.rb', line 147

def on_read(data)
  @call_back_to_this.receive_data data
end

#on_resolve_failedObject



139
140
141
# File 'lib/revem.rb', line 139

def on_resolve_failed
  fail
end

#on_write_completeObject



129
# File 'lib/revem.rb', line 129

def on_write_complete; close if @should_close_after_writing; end

#should_close_after_writingObject



131
132
133
# File 'lib/revem.rb', line 131

def should_close_after_writing
  @should_close_after_writing = true;
end