Class: Async
- Inherits:
-
Object
- Object
- Async
- Defined in:
- lib/bellite.rb
Overview
Simple implementation of Python Asyncore
Constant Summary collapse
- @@map =
!attribute @@map List of objects, implements asyncore methods
[]
Class Method Summary collapse
-
.check(timeout = false, map = false) ⇒ Object
Checks sockets from map objects using IO.select.
-
.loop(timeout, map = false) ⇒ Object
Running check while at least one socket in objects map is connected.
Class Method Details
.check(timeout = false, map = false) ⇒ Object
Checks sockets from map objects using IO.select
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bellite.rb', line 17 def Async.check(timeout=false, map=false) if not map map = @@map end readable = [] writable = [] excepted = [] changedCount = 0 map.each do |obj| if obj.writable? if obj.fileno writable << obj.fileno end end if obj.readable? if obj.fileno readable << obj.fileno end end if obj.exceptable? if obj.fileno excepted << obj.fileno end end end if readable.size == 0 and writable.size == 0 and excepted.size == 0 return false end if (timeout) r,w,e = IO.select(readable, writable, excepted,timeout) else r,w,e = IO.select(readable, writable, excepted) end map.each do |obj| if obj.writable? and w.include? obj.fileno obj.handle_write_event end if obj.readable? and r.include? obj.fileno obj.handle_read_event end if obj.exceptable? and e.include? obj.fileno obj.handle_expt_event end end return r.size + w.size + e.size end |