[Twisted-Python] fdport

Moshe Zadka moshez at twistedmatrix.com
Tue Aug 20 02:23:55 EDT 2002

import socket
from twisted.internet import tcp, abstract
from twisted.python import log

class FDPort(tcp.Port):

    port = "dummy"

    def __init__(self, fd, factory, backlog=None, reactor=None):
        """Initialize with a numeric port to listen on.
        abstract.FileDescriptor.__init__(self, reactor=reactor)
        self.fd = fd
        self.factory = factory
        if backlog:
	    self.backlog = backlog

    def __getstate__(self):
        """(internal) get my state for persistence
        dct = copy.copy(self.__dict__)
        try: del dct['socket']
        except: pass
        return dct

    def startListening(self):
        """Create and bind my socket, and begin listening on it.

        This is called on unserialization, and must be called after creating a
        server to begin listening on the specified port.
        log.msg("%s startings"% self.factory.__class__)
        skt = socket.fromfd(self.fd, socket.AF_INET,socket.SOCK_STREAM)
        self.connected = 1
        self.socket = skt
        self.numberAccepts = 100
        self.fileno = skt.fileno

More information about the Twisted-Python mailing list