def test_epoll_remove_bad_usock(self): epoll = udt.epoll() s = self.create_socket() fileno = s.fileno() s.close() self.assertRaises(RuntimeError, epoll.remove_usock, fileno, udt.UDT_EPOLL_IN)
def test_epoll_remove_ssock(self): epoll = udt.epoll() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1', 22)) self.assertEquals( epoll.add_ssock(s.fileno(), udt.UDT_EPOLL_IN), 0 ) epoll.remove_ssock(s.fileno())
def test_epoll_add_ssock(self): epoll = udt.epoll() s1, s2 = socket.socketpair() epoll.add_ssock(s1.fileno(), udt.UDT_EPOLL_IN)
def test_epoll_add_usock(self): epoll = udt.epoll() s = self.create_socket() self.assertEquals(0, epoll.add_usock(s.fileno(), udt.UDT_EPOLL_IN))
def test_epoll_double_release(self): epoll = udt.epoll() epoll.release() self.assertRaises(RuntimeError, epoll.release)
def test_epoll_release(self): epoll = udt.epoll() epoll.release()
def test_create_epoll(self): epoll = udt.epoll() self.assert_(epoll.eid)
max_bandwidth = 1024 * 512 * 10 def test(client, text): data = "a" * int(text) sent = 0 len_data = len(data) while sent != len_data: sent += client.send(data[sent:], 0) s = udt.socket(socket.AF_INET, socket.SOCK_STREAM, 0) s.bind(("127.0.0.1", 5555)) s.listen(10) i = 0 clients = {} epoll = udt.epoll() for x in xrange(0, threads): child, host = s.accept() child.setsockopt(0, udt.UDT_MAXBW, max_bandwidth) clients[child.fileno()] = child epoll.add_usock(child.fileno(), udt.UDT_EPOLL_IN) while True: print 'wait..' sets = epoll.epoll_wait(-1) print sets poll = [] for i in sets[0]: text = clients[i].recv(1024, 0)
def test_epoll_remove_ssock(self): epoll = udt.epoll() s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(('127.0.0.1', 22)) self.assertEquals(epoll.add_ssock(s.fileno(), udt.UDT_EPOLL_IN), 0) epoll.remove_ssock(s.fileno())
def test_epoll_remove_usock(self): epoll = udt.epoll() s = self.create_socket() epoll.add_usock(s.fileno(), udt.UDT_EPOLL_IN) epoll.remove_usock(s.fileno())
def test_epoll_remove_bad_usock(self): epoll = udt.epoll() s = self.create_socket() fileno = s.fileno() s.close() self.assertRaises(RuntimeError, epoll.remove_usock, fileno)
def test_epoll_wait(self): s = self.create_socket() epoll = udt.epoll() epoll.add_usock(s.fileno(), udt.UDT_EPOLL_IN) print epoll.epoll_wait(0) print epoll.epoll_wait(1)
import udt import socket import time import threading class Pinger(threading.Thread): def run(self): for i in range(300): print "ping ...", i time.sleep(1) p = Pinger() p.start() s = udt.socket(socket.AF_INET, socket.SOCK_STREAM, 0) epoll = udt.epoll() s.bind(("127.0.0.1", 5555)) s.listen(10) while 1: client, addr = s.accept() print "accept", client, addr epoll.add_usock(client.fileno(), udt.UDT_EPOLL_IN) print 'wait..' print epoll.epoll_wait(-1) print 'got data..' client.send("Hello World" * 10, -1) client.close()