Class: EventMachine::DatagramObject

Inherits:
Selectable show all
Defined in:
lib/em/pure_ruby.rb

Direct Known Subclasses

EvmaUDPSocket

Instance Attribute Summary

Attributes inherited from Selectable

#io, #is_server, #uuid

Instance Method Summary collapse

Methods inherited from Selectable

#close_scheduled?, #get_peername, #get_sockname, #heartbeat, #schedule_close, #set_inactivity_timeout

Constructor Details

#initialize(io) ⇒ DatagramObject



1171
1172
1173
1174
# File 'lib/em/pure_ruby.rb', line 1171

def initialize io
  super io
  @outbound_q = []
end

Instance Method Details

#get_outbound_data_sizeObject

#get_outbound_data_size



1202
1203
1204
# File 'lib/em/pure_ruby.rb', line 1202

def get_outbound_data_size
  @outbound_q.inject(0) {|memo,obj| memo += (obj || "").length}
end

#select_for_reading?Boolean

#select_for_reading?



1197
1198
1199
# File 'lib/em/pure_ruby.rb', line 1197

def select_for_reading?
  true
end

#select_for_writing?Boolean

#select_for_writing?



1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
# File 'lib/em/pure_ruby.rb', line 1185

def select_for_writing?
  unless @close_scheduled
    if @outbound_q.empty?
      @close_scheduled = true if @close_requested
      false
    else
      true
    end
  end
end

#send_datagram(data, target) ⇒ Object

#send_datagram



1177
1178
1179
1180
1181
1182
# File 'lib/em/pure_ruby.rb', line 1177

def send_datagram data, target
  # TODO, coalesce here perhaps by being smarter about appending to @outbound_q.last?
  unless @close_scheduled or @close_requested
    @outbound_q << [data.to_s, target]
  end
end