def createTransport(self, socket, peer, data, protocol): """ Create a TCP transport from a socket object passed by the parent. """ from twisted.internet import reactor factory = self.wrappedProtocolFactory factory.inheritedPort.reportStatus("+") self.log.info("{factory.inheritedPort.statusQueue}", factory=factory) socketFD = socket.fileno() transport = reactor.adoptStreamConnection( socketFD, getsockfam(socketFD), factory ) transport.startReading() return transport
def test_unix(self): """ When passed the file descriptor of a socket created with the C{AF_UNIX} address family, L{getsockfam} returns C{AF_UNIX}. """ self.assertEqual(AF_UNIX, getsockfam(self._socket(AF_UNIX)))
def test_inet6(self): """ When passed the file descriptor of a socket created with the C{AF_INET6} address family, L{getsockfam} returns C{AF_INET6}. """ self.assertEqual(AF_INET6, getsockfam(self._socket(AF_INET6)))
""" return self.fd def doRead(self): """ A message is ready to read. Receive a file descriptor from our parent process. """ try: fd, description = recvfd(self.fd) except SocketError, se: if se.errno != EAGAIN: raise else: try: skt = fromfd(fd, getsockfam(fd), SOCK_STREAM) close(fd) # fromfd() calls dup() try: peeraddr = skt.getpeername() except SocketError: peeraddr = ('0.0.0.0', 0) # FIXME: when using UNIX Domain sockets, peeraddr = "" if not peeraddr: peeraddr = ('0.0.0.0', 0) protocol = self.protocolFactory.buildProtocol(peeraddr) transport = self.transportFactory(skt, peeraddr, description, protocol) protocol.makeConnection(transport) except: log.failure("doRead()")