Commits

Martin Gergov committed f85df3c

Init commit. Playing with base classes and added end-goal-test.

Comments (0)

Files changed (6)

+syntax: glob
+*~
+*kdev*
+*.pyc
+.rope*
+Summary
+=======
+
+Integration of udt as a transport protocol in twisted.
+
+
+Prerequisites
+=============
+
+#) PyUDT
+#) twisted

tests/__init__.py

Empty file added.

tests/test_top_api.py

+import socket as s
+from twisted.trial import unittest
+from twisted.internet.protocol import DatagramProtocol
+from twisted.internet import reactor
+import udt4twisted
+
+class Echo(DatagramProtocol):
+
+    def datagramReceived(self, data, (host, port)):
+        print "received %r from %s:%d" % (data, host, port)
+        self.transport.write(data, (host, port))
+
+class TestTopLevelAPI(unittest.TestCase):
+    
+    def setUp(self):
+        pass
+    
+    def test_listening(self):
+        reactor.listenUDT(9999, Echo())
+
+    test_listening.todo = "Make this work!"
+
+    
+        
+    

udt4twisted/__init__.py

Empty file added.

udt4twisted/udt.py

+import sys 
+
+import time 
+import struct
+import socket
+from zope.interface import implementer
+from twisted.internet import base, defer, address, udp
+from twisted.python import log, failure
+from twisted.internet import abstract, error, interfaces
+import udt4 as udt
+from   udt4 import pyudt
+
+@implementer(
+    interfaces.IListeningPort, interfaces.IUDPTransport,
+    interfaces.ISystemHandle)
+class Port(udp.Port):
+    """
+    UDT port, listening for packets.
+    This is inherited from udp port implementation.
+    """
+
+    def getHandle(self):
+        """
+        Return a socket object.
+        """
+        return pyudt.UdtSocket
+
+    def _bindSocket(self):
+        """
+        TODO
+        """
+        try:
+            skt = self.createInternetSocket()
+            skt.bind((self.interface, self.port))
+        except socket.error as le:
+            raise error.CannotListenError(self.interface, self.port, le)
+
+        # Make sure that if we listened on port 0, we update that to
+        # reflect what the OS actually assigned us.
+        self._realPortNumber = skt.getsockname()[1]
+
+        log.msg("%s starting on %s" % (
+                self._getLogPrefix(self.protocol), self._realPortNumber))
+
+        self.connected = 1
+        self.socket = skt
+        self.fileno = self.socket.fileno
+
+    def _connectToProtocol(self):
+        """
+        TODO
+        """
+        self.protocol.makeConnection(self)
+        self.startReading()
+