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, #uuid

Instance Method Summary collapse

Methods inherited from Selectable

#close_scheduled?, #get_peername, #heartbeat, #set_inactivity_timeout

Constructor Details

#initialize(io) ⇒ DatagramObject

Returns a new instance of DatagramObject.



907
908
909
910
# File 'lib/em/pure_ruby.rb', line 907

def initialize io
  super io
  @outbound_q = []
end

Instance Method Details

#get_outbound_data_sizeObject

#get_outbound_data_size



938
939
940
# File 'lib/em/pure_ruby.rb', line 938

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

#select_for_reading?Boolean

#select_for_reading?

Returns:

  • (Boolean)


933
934
935
# File 'lib/em/pure_ruby.rb', line 933

def select_for_reading?
  true
end

#select_for_writing?Boolean

#select_for_writing?

Returns:

  • (Boolean)


921
922
923
924
925
926
927
928
929
930
# File 'lib/em/pure_ruby.rb', line 921

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



913
914
915
916
917
918
# File 'lib/em/pure_ruby.rb', line 913

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