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



1176
1177
1178
1179
# File 'lib/em/pure_ruby.rb', line 1176

def initialize io
  super io
  @outbound_q = []
end

Instance Method Details

#get_outbound_data_sizeObject

#get_outbound_data_size



1207
1208
1209
# File 'lib/em/pure_ruby.rb', line 1207

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

#select_for_reading?Boolean

#select_for_reading?

Returns:

  • (Boolean)


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

def select_for_reading?
  true
end

#select_for_writing?Boolean

#select_for_writing?

Returns:

  • (Boolean)


1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
# File 'lib/em/pure_ruby.rb', line 1190

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



1182
1183
1184
1185
1186
1187
# File 'lib/em/pure_ruby.rb', line 1182

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