class EventMachine::EvmaUDPSocket
@private
def create host, port
def create host, port sd = Socket.new( Socket::AF_INET, Socket::SOCK_DGRAM, 0 ) sd.bind Socket::pack_sockaddr_in( port, host ) EvmaUDPSocket.new sd end
def eventable_read
If we have it, then we can read multiple times safely to improve
Proper nonblocking I/O was added to Ruby 1.8.4 in May 2006.
def eventable_read begin if io.respond_to?(:recvfrom_nonblock) 40.times { data,@return_address = io.recvfrom_nonblock(16384) EventMachine::event_callback uuid, ConnectionData, data @return_address = nil } else raise "unimplemented datagram-read operation on this Ruby" end rescue Errno::EAGAIN # no-op rescue Errno::ECONNRESET, EOFError @close_scheduled = true EventMachine::event_callback uuid, ConnectionUnbound, nil end end
def eventable_write
#eventable_write
def eventable_write 40.times { break if @outbound_q.empty? begin data,target = @outbound_q.first # This damn better be nonblocking. io.send data.to_s, 0, target @outbound_q.shift rescue Errno::EAGAIN # It's not been observed in testing that we ever get here. # True to the definition, packets will be accepted and quietly dropped # if the system is under pressure. break rescue EOFError, Errno::ECONNRESET @close_scheduled = true @outbound_q.clear end } end
def send_data data
def send_data data send_datagram data, @return_address end