Commits

Martin Gergov committed 027f539

Working with twisted 13.0.0

Comments (0)

Files changed (5)

 import gc
 import random
 from time import sleep
-
-ok = False
-startup()
-poller = UDTepoll()
-s = UdtSocket(AF_INET, SOCK_DGRAM, AI_PASSIVE)
-s.setblocking(False)
-s.bind(("127.0.0.1", 5001))
-s.listen(20)
-print s.UDTSOCKET
-counter = 0
-poller.add_usock(s.UDTSOCKET, UDT_EPOLL_IN)
+#from meliae import scanner
 
 # try:
 #     while 1:
 # except KeyboardInterrupt:
 #     exit("Bye!")
 
-try:
-    while True:
-        print "---------------------------------------------"
-        sets = [[], []]
-        try:
-            sets = poller.wait(True, True, 1000, False, False)
-        except UDTException as ue:
-            if ue[0] == 6003:
-                pass
-        print sets
+def main():
+    #hp = hpy()
+    ok = False
+    startup()
+    poller = UDTepoll()
+    s = UdtSocket(AF_INET, SOCK_DGRAM, AI_PASSIVE)
+    s.setblocking(False)
+    s.bind(("127.0.0.1", 5000))
+    s.listen(20)
+    print s.UDTSOCKET
+    counter = 0
+    poller.add_usock(s.UDTSOCKET, UDT_EPOLL_IN)
 
-        for socket in sets[0]:
-            if (socket.UDTSOCKET == s.UDTSOCKET.UDTSOCKET):
-                sock, host = accept(socket)
-                print sock, host
-                sock = UdtSocket(_sock=sock)
-                sock.setblocking(False)
-                poller.add_usock(sock.UDTSOCKET, UDT_EPOLL_IN)
-            else:
-                try:
-                    mess = recvmsg(socket, 100)
-                    print "READ:", socket,";", "RECV:", mess
-                    if counter < 100:
-                        poller.add_usock(socket , UDT_EPOLL_OUT)
-                    #sendmsg(socket.UDTSOCKET, mess, len(mess))
-                except udt4.UDTException as ue:
-                    print "ERR:",ue
-                    if ue[0] == 6002:
-                        poller.remove_usock(socket)
-                        poller.add_usock(socket, UDT_EPOLL_IN)
-                        pass
-            gc.collect()
+    try:
+        while True:
+            #print "---------------------------------------------"
+            sets = [[], []]
+            try:
+                sets = poller.wait(True, True, 1000, False, False)
+            except UDTException as ue:
+                if ue[0] == 6003:
+                    pass
+            #print sets
 
-        for socket in sets[1]:
-            if sock.UDTSOCKET.UDTSOCKET == socket.UDTSOCKET:
-                mess = "HELLO!"
-                mess = sendmsg(socket, mess, len(mess))
-                poller.remove_usock(socket)
-                poller.add_usock(socket, UDT_EPOLL_IN)
+            for socket in sets[0]:
+                if (socket.UDTSOCKET == s.UDTSOCKET.UDTSOCKET):
+                    sock, host = accept(socket)
+                    print sock, host
+                    sock = UdtSocket(_sock=sock)
+                    sock.setblocking(False)
+                    poller.add_usock(sock.UDTSOCKET, UDT_EPOLL_IN)
+                else:
+                    try:
+                        mess = recvmsg(socket, 100)
+                        print "READ:", socket,";", "RECV:", mess, counter
+                        if counter < 1500:
+                            poller.add_usock(socket , UDT_EPOLL_OUT)
+                        else:
+                            gc.collect()
+                            print "G unit"
 
-                counter += 1
+                        #sendmsg(socket.UDTSOCKET, mess, len(mess))
+                    except udt4.UDTException as ue:
+                        #print "ERR:",ue, counter
+                        if ue[0] == 6002:
+                            poller.remove_usock(socket)
+                            poller.add_usock(socket, UDT_EPOLL_IN)
+                            pass
+                gc.collect()
 
-            gc.collect()
-except KeyboardInterrupt:
-    poller.remove_usock(s.UDTSOCKET)
-    sock.close()
-    s.close()
-    cleanup()
-    exit("Bye!")
+            for socket in sets[1]:
+                if sock.UDTSOCKET.UDTSOCKET == socket.UDTSOCKET:
+                    mess = "HELLO!"
+                    mess = sendmsg(socket, mess, len(mess))
+                    poller.remove_usock(socket)
+                    poller.add_usock(socket, UDT_EPOLL_IN)
 
+                    counter += 1
+
+                gc.collect()
+    except KeyboardInterrupt:
+        poller.remove_usock(s.UDTSOCKET)
+        sock.close()
+        s.close()
+        cleanup()
+        exit("Bye!")
+
+main()

examples/client.py

                 try:
                     mess = recvmsg(socket, 100)
                     print "READ:", socket,";", "RECV:", mess
-                    if counter < 100:
+                    if counter < 2600:
                         poller.add_usock(socket , UDT_EPOLL_OUT)
                     #sendmsg(socket.UDTSOCKET, mess, len(mess))
                 except udt4.UDTException as ue:

examples/newserver.py

 from twisted.internet.protocol import DatagramProtocol, Protocol, Factory
 from twisted.python import log
 from udt4twisted import udt
+from time import sleep
+import gc
 log.startLogging(sys.stdout)
 
+
 class Echo(Protocol):
+    def __init__(self):
+        self.hp = hpy()
+
     counter=0
     def connectionMade(self):
         pass
         #self.transport.write("An apple a day keeps the doctor away\r\n")
 
+
     def dataReceived(self, data):
         #print self.counter
-        log.msg("{2}:received {0}:{1}".format(self.counter, data, len(data)))
-        if self.counter == 10:
+        #log.msg("{2}:received {0}:{1}".format(self.counter, data, len(data)))
+        if self.counter == 50000:
             self.transport.loseConnection()
+            gc.collect()
+            print self.hp.heap()[0]
             return
         self.transport.write(data)
         self.counter += 1
     port = None
     def listen_to_udt_port(self, res):
         self.echo = EchoFactory()
-        self.port = reactor.listenUDT(5000, self.echo)
+        self.port = reactor.listenUDT(5000, self.echo, interface="127.0.0.1")
         print self.port
 
     def print_hello(self, res):
 d.addCallback(test.listen_to_udt_port)
 
 reactor.callLater(0.3, d.callback, 1)
-reactor.callLater(100, test.bye)
+#reactor.callLater(10, test.bye)
 reactor.run()

udt4twisted/udt.py

 from twisted.internet import base, defer, address, udp, tcp
 from twisted.internet.task import deferLater
 from twisted.python import log, failure, _reflectpy3 as reflect
-from twisted.python._utilpy3 import unsignedID
 from twisted.python.runtime import platformType
 from twisted.internet import abstract, error, interfaces, main
 import udt4 as udt
-from   udt4 import pyudt
+from udt4 import pyudt
 from udt4 import EASYNCRCV, ECONNLOST
 from socket import AI_PASSIVE
 from errno import EWOULDBLOCK, EINTR, EMSGSIZE, ECONNREFUSED, EAGAIN
 
         return None
         
-
     def doWrite(self):
         """
         Called when data can be written. It will send all messages recorded

udt4twisted/udtepollreactor.py

         except UDTException as ue:
             if ue[0] == 6003:
                 return
+
         #handle system sockets
         sread, swrite = l[2:]
         #print sread, swrite
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.