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

Returns a new instance of DatagramObject.



1194
1195
1196
1197
# File 'lib/em/pure_ruby.rb', line 1194

def initialize io
  super io
  @outbound_q = []
end

Instance Method Details

#get_outbound_data_sizeObject

#get_outbound_data_size



1225
1226
1227
# File 'lib/em/pure_ruby.rb', line 1225

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

#select_for_reading?Boolean

#select_for_reading?

Returns:

  • (Boolean)


1220
1221
1222
# File 'lib/em/pure_ruby.rb', line 1220

def select_for_reading?
  true
end

#select_for_writing?Boolean

#select_for_writing?

Returns:

  • (Boolean)


1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
# File 'lib/em/pure_ruby.rb', line 1208

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



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

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