]>
git.ipfire.org Git - people/shoehn/ipfire.org.git/blob - www/pages/torrent/client/selectpoll.py
1 # Written by Bram Cohen
2 # see LICENSE.txt for license information
4 from select
import select
, error
6 from types
import IntType
7 from bisect
import bisect
18 def register(self
, f
, t
):
19 if type(f
) != IntType
:
30 def unregister(self
, f
):
31 if type(f
) != IntType
:
36 def poll(self
, timeout
= None):
37 if self
.rlist
or self
.wlist
:
39 r
, w
, e
= select(self
.rlist
, self
.wlist
, [], timeout
)
47 result
.append((s
, POLLIN
))
49 result
.append((s
, POLLOUT
))
52 def remove(list, item
):
53 i
= bisect(list, item
)
54 if i
> 0 and list[i
-1] == item
:
57 def insert(list, item
):
58 i
= bisect(list, item
)
59 if i
== 0 or list[i
-1] != item
:
106 assert x
== [2, 3, 4]