Go to the latest version of this document.
search in docstrings

Search bar offers the following options:

- Term presence. The below example searches for documents that must contain “foo”, might contain “bar” and must not contain “baz”: `+foo bar -baz`
- Wildcards. The below example searches for documents with words beginning with “foo”: `foo*`
- Search in specific fields. The following search matches all objects in "twisted.mail" that matches “search”: `+qname:twisted.mail.* +search`

  Possible fields: 'name', 'qname' (fully qualified name), 'docstring', and 'kind'. Last two fields are only applicable if "search in docstrings" is enabled.

- Fuzzy matches. The following search matches all documents that have a word within 1 edit distance of “foo”: `foo~1`

Results provided by Lunr.js

# ``twisted`.`internet`.`interfaces`.`IReactorSocket``

interface documentation

`class IReactorSocket(Interface): (source)`

Known implementations: `twisted.internet.posixbase.PosixReactorBase`, `twisted.internet.testing.MemoryReactor`, `twisted.internet.testing.RaisingMemoryReactor`

View In Hierarchy

Methods which allow a reactor to use externally created sockets.

For example, to use `adoptStreamPort` to implement behavior equivalent to that of `IReactorTCP.listenTCP`, you might write code like this:

        from socket import SOMAXCONN, AF_INET, SOCK_STREAM, socket
        portSocket = socket(AF_INET, SOCK_STREAM)
        # Set FD_CLOEXEC on port, left as an exercise.  Then make it into a
        # non-blocking listening port:
        portSocket.setblocking(False)
        portSocket.bind(('192.168.1.2', 12345))
        portSocket.listen(SOMAXCONN)

        # Now have the reactor use it as a TCP port
        port = reactor.adoptStreamPort(
            portSocket.fileno(), AF_INET, YourFactory())

        # portSocket itself is no longer necessary, and needs to be cleaned
        # up by us.
        portSocket.close()

        # Whenever the server is no longer needed, stop it as usual.
        stoppedDeferred = port.stopListening()

Another potential use is to inherit a listening descriptor from a parent process (for example, systemd or launchd), or to receive one over a UNIX domain socket.

Some plans for extending this interface exist. See:

- http://twistedmatrix.com/trac/ticket/6594: AF_UNIX SOCK_DGRAM ports

Method | `adoptDatagramPort` | Add an existing listening SOCK_DGRAM socket to the reactor to monitor for read and write readiness.
Method | `adoptStreamConnection` | Add an existing connected SOCK_STREAM socket to the reactor to monitor for data.
Method | `adoptStreamPort` | Add an existing listening SOCK_STREAM socket to the reactor to monitor for new connections to accept and handle.

def adoptDatagramPort(fileDescriptor, addressFamily, protocol, maxPacketSize): (source)

Add an existing listening SOCK_DGRAM socket to the reactor to monitor for read and write readiness.

Parameters
fileDescriptor:`int` | A file descriptor associated with a socket which is already bound to an address and marked as listening. The socket must be set non-blocking. Any additional flags (for example, close-on-exec) must also be set by application code. Application code is responsible for closing the file descriptor, which may be done as soon as `adoptDatagramPort` returns.
addressFamily:`AddressFamily` | The address family or domain of the socket. For example, `socket.AF_INET6`.
protocol:`DatagramProtocol` | A `DatagramProtocol` instance to connect to a UDP transport.
maxPacketSize:`int` | The maximum packet size to accept.
Returns
`IListeningPort` | An object providing `IListeningPort`.
Raises
`UnsupportedAddressFamily` | If the given address family is not supported by this reactor, or not supported with the given socket type.
`UnsupportedSocketType` | If the given socket type is not supported by this reactor, or not supported with the given socket type.

def adoptStreamConnection(fileDescriptor, addressFamily, factory): (source)

Add an existing connected SOCK_STREAM socket to the reactor to monitor for data.

Note that the given factory won't have its `startFactory` and `stopFactory` methods called, as there is no sensible time to call them in this situation.

Parameters
fileDescriptor:`int` | A file descriptor associated with a socket which is already connected. The socket must be set non-blocking. Any additional flags (for example, close-on-exec) must also be set by application code. Application code is responsible for closing the file descriptor, which may be done as soon as `adoptStreamConnection` returns.
addressFamily:`AddressFamily` | The address family (or domain) of the socket. For example, `socket.AF_INET6`.
factory:`ServerFactory` | A `ServerFactory` instance to use to create a new protocol to handle the connection via this socket.
Raises
`UnsupportedAddressFamily` | If the given address family is not supported by this reactor, or not supported with the given socket type.
`UnsupportedSocketType` | If the given socket type is not supported by this reactor, or not supported with the given socket type.

def adoptStreamPort(fileDescriptor, addressFamily, factory): (source)

Add an existing listening SOCK_STREAM socket to the reactor to monitor for new connections to accept and handle.

Parameters
fileDescriptor:`int` | A file descriptor associated with a socket which is already bound to an address and marked as listening. The socket must be set non-blocking. Any additional flags (for example, close-on-exec) must also be set by application code. Application code is responsible for closing the file descriptor, which may be done as soon as `adoptStreamPort` returns.
addressFamily:`AddressFamily` | The address family (or domain) of the socket. For example, `socket.AF_INET6`.
factory:`ServerFactory` | A `ServerFactory` instance to use to create new protocols to handle connections accepted via this socket.
Returns
`IListeningPort` | An object providing `IListeningPort`.
Raises
`twisted.internet.error.UnsupportedAddressFamily` | If the given address family is not supported by this reactor, or not supported with the given socket type.
`twisted.internet.error.UnsupportedSocketType` | If the given socket type is not supported by this reactor, or not supported with the given socket type.