Class: EventMachine::EvmaUDPSocket
- Inherits:
-
DatagramObject
- Object
- Selectable
- DatagramObject
- EventMachine::EvmaUDPSocket
- Defined in:
- lib/em/pure_ruby.rb
Instance Attribute Summary
Attributes inherited from Selectable
Class Method Summary collapse
Instance Method Summary collapse
-
#eventable_read ⇒ Object
Proper nonblocking I/O was added to Ruby 1.8.4 in May 2006.
-
#eventable_write ⇒ Object
#eventable_write This really belongs in DatagramObject, but there is some UDP-specific stuff.
- #send_data(data) ⇒ Object
Methods inherited from DatagramObject
#get_outbound_data_size, #initialize, #select_for_reading?, #select_for_writing?, #send_datagram
Methods inherited from Selectable
#close_scheduled?, #get_peername, #get_sockname, #heartbeat, #initialize, #schedule_close, #select_for_reading?, #select_for_writing?, #set_inactivity_timeout
Constructor Details
This class inherits a constructor from EventMachine::DatagramObject
Class Method Details
.create(host, port) ⇒ Object
1238 1239 1240 1241 1242 |
# File 'lib/em/pure_ruby.rb', line 1238 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 |
Instance Method Details
#eventable_read ⇒ Object
Proper nonblocking I/O was added to Ruby 1.8.4 in May 2006. If we have it, then we can read multiple times safely to improve performance.
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 |
# File 'lib/em/pure_ruby.rb', line 1272 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 |
#eventable_write ⇒ Object
#eventable_write This really belongs in DatagramObject, but there is some UDP-specific stuff.
1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 |
# File 'lib/em/pure_ruby.rb', line 1247 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 |
#send_data(data) ⇒ Object
1291 1292 1293 |
# File 'lib/em/pure_ruby.rb', line 1291 def send_data data send_datagram data, @return_address end |