Commits

Martin Gergov committed a352965

Tests run. Preparing for merge.

Comments (0)

Files changed (4)

examples/newserver.py

         if self.counter == 100:
             return
         log.msg("received {0} from {1}".format(data, self.transport.getPeer()))
-        self.transport.write(data, 0, False)
+        self.transport.write(data, 10, False)
         self.counter += 1
 
     def connectionLost(self, reason):

tests/test_top_api.py

 import socket as s
 from twisted.trial import unittest
-from twisted.internet.protocol import DatagramProtocol
+from twisted.internet.protocol import DatagramProtocol, Protocol, Factory
+from twisted.internet.protocol import ClientFactory
 from twisted.internet import reactor
 from twisted.internet import udp
 import udt4twisted
 
+class TEcho(Protocol):
+
+    def dataReceived(self, data):
+        self.transport.write(data)
+
+class EchoFactory(Factory):
+
+    def buildProtocol(self, addr):
+        return TEcho()
+
+class CEchoFactory(ClientFactory):
+
+    pr = []
+    def buildProtocol(self, addr):
+        p = TEcho()
+        self.pr.append(p)
+        return p
+
+
 class Echo(DatagramProtocol):
 
     def datagramReceived(self, data, (host, port)):
     def setUp(self):
         pass
     def test_listening(self):
-        udtServer = reactor.listenUDT(9999, Echo())
+        udtServer = reactor.listenUDT(9999, EchoFactory())
         udtServer.stopListening()
 
     def test_udp_handling(self):
 
     def test_udt_conversation(self):
         #FIXME learn how to test transport protocols
-        srv = reactor.listenUDT(6000, Echo())
-        echo = Echo()
+        srv = reactor.listenUDT(6000, EchoFactory())
+        echo = CEchoFactory()
         client = reactor.connectUDT("127.0.0.1", 6000, echo)
-        echo.transport.write("hello")
         srv.stopListening()
-        client.stopListening()
+        client.disconnect()

tests/test_udt_reactor.py

 
 
     def test_reactor_add_udt_socket(self):
-        srv = reactor.listenUDT(0, Echo())
+        srv = reactor.listenUDT(0, EchoFactory())
         self.assertIn(srv.socket.UDTSOCKET.UDTSOCKET, reactor._selectables)
         srv.stopListening()

udt4twisted/udt.py

 from twisted.internet import fdesc
 from twisted.python.compat import _PY3
 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
     addressFamily = socket.AF_INET
     socketType = socket.SOCK_DGRAM
 
+    def _stopReadingAndWriting(self):
+        """
+        Implement the POSIX-ish (i.e.
+        L{twisted.internet.interfaces.IReactorFDSet}) method of detaching this
+        socket from the reactor for L{_BaseBaseClient}.
+        """
+        if hasattr(self, "reactor"):
+            # this doesn't happen if we failed in __init__
+            self.stopReading()
+            self.stopWriting()
+
+    def _collectSocketDetails(self):
+        """
+        Clean up references to the socket and its file descriptor.
+
+        @see: L{_BaseBaseClient}
+        """
+        del self.socket, self.fileno
+
+
+
     def _finishInit(self, whenDone, skt, error, reactor):
         """
         Called by subclasses to continue to the stage of initialization where
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.