-
Notifications
You must be signed in to change notification settings - Fork 9
/
udt.py
51 lines (42 loc) · 1.3 KB
/
udt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
# use socket library for portability
import socket as socketlib
from _udt import *
import _udt
class socket(_udt.socket):
def connect(self, addr):
conn_addr = self._get_addr(addr)
return _udt.socket.connect(self, conn_addr)
def bind(self, addr):
bind_addr = self._get_addr(addr)
return _udt.socket.bind(self, bind_addr)
def _get_addr(self, addr):
host, port = addr
family, socktype, proto, name, addr = socketlib.getaddrinfo(
host,
port,
self.family,
0,
0,
0
)[0]
return addr
class epoll(_udt.epoll):
def __init__(self):
_udt.epoll.__init__(self)
self._released = False
def release(self):
if not self._released:
_udt.epoll.release(self)
def add_usock(self, s, events):
# according to the docs, adding flags is not supported
rv = _udt.epoll.add_usock(self, s, events)
return rv
def add_ssock(self, s, events):
rv = _udt.epoll.add_ssock(self, s, events)
return rv
def remove_usock(self, s, events):
rv = _udt.epoll.remove_usock(self, s, events)
return rv
def remove_ssock(self, s, events):
rv = _udt.epoll.remove_ssock(self, s, events)
return rv