[Twisted-Python] best way to turn on SO_KEEPALIVE option on all sockets

Alec Matusis matusis at matusis.com
Thu Feb 10 21:22:56 EST 2005


I was wondering what is the best way to turn on KEEPALIVE option on all
sockets opened by my twisted server.

I have inserted s.setsockopt(socket.SOL_SOCKET,socket.SO_KEEPALIVE,1) line
into twisted/internet/base.py

class BasePort(abstract.FileDescriptor):
    """Basic implementation of a ListeningPort."""

    addressFamily = None
    socketType = None

    def createInternetSocket(self):
        s = socket.socket(self.addressFamily, self.socketType)
   ++ s.setsockopt(socket.SOL_SOCKET,socket.SO_KEEPALIVE,1)

but I am wondering if there is a better way of doing this, without actually
modyfying twsited code...


Alec Matusis.

More information about the Twisted-Python mailing list