# ``twisted`.`internet`.`abstract`.`FileDescriptor``

class documentation

`class FileDescriptor(_ConsumerMixin, _LogOwner): (source)`

Known subclasses: `twisted.internet.base.BasePort`, `twisted.internet.inotify.INotify`, `twisted.internet.process.ProcessReader`, `twisted.internet.process.ProcessWriter`, `twisted.internet.process.PTYProcess`, `twisted.internet.serialport.SerialPort`, `twisted.internet.serialport.SerialPort`, `twisted.internet.tcp.Connection`, `twisted.pair.tuntap.TuntapPort`

Implements interfaces: `twisted.internet.interfaces.IConsumer`, `twisted.internet.interfaces.IHalfCloseableDescriptor`, `twisted.internet.interfaces.IPushProducer`, `twisted.internet.interfaces.IReadWriteDescriptor`, `twisted.internet.interfaces.ITransport`

View In Hierarchy

An object which can be operated on by select().

This is an abstract superclass of all objects which may be notified when they are readable or writable; e.g. they have a file-descriptor that is valid to be passed to select(2).

Method | `__init__` |
Method | `connectionLost` | The connection was lost.
Method | `doRead` | Called when data is available for reading.
Method | `doWrite` | Called when data can be written.
Method | `fileno` | File Descriptor number for select().
Method | `getHost` | Similar to getPeer, but returns an address describing this side of the connection.
Method | `getPeer` | Get the remote address of this connection.
Method | `loseConnection` | Close the connection at the next available opportunity.
Method | `loseWriteConnection` | Undocumented
Method | `pauseProducing` | Pause producing data.
Method | `readConnectionLost` | Indicates read connection was lost.
Method | `resumeProducing` | Resume producing data.
Method | `startReading` | Start waiting for read availability.
Method | `startWriting` | Start waiting for write availability.
Method | `stopConsuming` | Stop consuming data.
Method | `stopProducing` | Stop producing data.
Method | `stopReading` | Stop waiting for read availability.
Method | `stopWriting` | Stop waiting for write availability.
Method | `write` | Reliably write some data.
Method | `writeConnectionLost` | Indicates write connection was lost.
Method | `writeSequence` | Reliably write a sequence of data.
Method | `writeSomeData` | Write as much as possible of the given data, immediately.
Constant | `SEND_LIMIT` | Undocumented
Class Variable | `bufferSize` | Undocumented
Instance Variable | `connected` | Undocumented
Instance Variable | `dataBuffer` | Undocumented
Instance Variable | `disconnected` | Undocumented
Instance Variable | `disconnecting` | Undocumented
Instance Variable | `offset` | Undocumented
Instance Variable | `producer` | Undocumented
Instance Variable | `producerPaused` | Undocumented
Instance Variable | `reactor` | Undocumented
Method | `_closeWriteConnection` | Undocumented
Method | `_isSendBufferFull` | Determine whether the user-space send buffer for this transport is full or not.
Method | `_maybePauseProducer` | Possibly pause a producer, if there is one and the send buffer is full.
Method | `_postLoseConnection` | Called after a loseConnection(), when all data has been written.
Instance Variable | `_tempDataBuffer` | Undocumented
Instance Variable | `_tempDataLen` | Undocumented
Instance Variable | `_writeDisconnected` | Undocumented
Instance Variable | `_writeDisconnecting` | Undocumented

Inherited from `_ConsumerMixin`:

Method | `registerProducer` | Register to receive data from a producer.
Method | `unregisterProducer` | Stop consuming data from a producer, without disconnecting.
Instance Variable | `streamingProducer` | `bool` or `int`

Inherited from `_LogOwner`:

Method | `logPrefix` | Override this method to insert custom logging behavior. Its return value will be inserted in front of every line. It may be called more times than the number of output lines.
Method | `_getLogPrefix` | Determine the log prefix to use for messages related to `applicationObject`, which may or may not be an `interfaces.ILoggingContext` provider.

def __init__(self, reactor=None): (source)
overridden in `twisted.internet.inotify.INotify`, `twisted.internet.process.ProcessReader`, `twisted.internet.process.ProcessWriter`, `twisted.internet.process.PTYProcess`, `twisted.internet.serialport.SerialPort`, `twisted.internet.serialport.SerialPort`, `twisted.internet.tcp.Connection`, `twisted.internet.tcp.Port`, `twisted.internet.udp.Port`, `twisted.pair.tuntap.TuntapPort`

Parameters
reactor:`Optional[interfaces.IReactorFDSet]` | An `IReactorFDSet` provider which this descriptor will use to get readable and writeable event notifications. If no value is given, the global reactor will be used.

def connectionLost(self, reason): (source)
from `twisted.internet.interfaces.IFileDescriptor`
overridden in `twisted.internet.inotify.INotify`, `twisted.internet.process.ProcessReader`, `twisted.internet.process.ProcessWriter`, `twisted.internet.process.PTYProcess`, `twisted.internet.serialport.SerialPort`, `twisted.internet.serialport.SerialPort`, `twisted.internet.tcp.Connection`, `twisted.internet.tcp.Port`, `twisted.internet.udp.Port`, `twisted.pair.tuntap.TuntapPort`

The connection was lost.

This is called when the connection on a selectable object has been lost. It will be called whether the connection was closed explicitly, an exception occurred in an event handler, or the other end of the connection closed it first.

Clean up state here, but make sure to call back up to FileDescriptor.

def doRead(self): (source)
from `twisted.internet.interfaces.IReadDescriptor`
overridden in `twisted.internet.inotify.INotify`, `twisted.internet.process.ProcessReader`, `twisted.internet.process.ProcessWriter`, `twisted.internet.process.PTYProcess`, `twisted.internet.serialport.SerialPort`, `twisted.internet.tcp.Connection`, `twisted.internet.tcp.Port`, `twisted.internet.udp.Port`, `twisted.pair.tuntap.TuntapPort`

Called when data is available for reading.

Subclasses must override this method. The result will be interpreted in the same way as a result of doWrite().

def doWrite(self): (source)
from `twisted.internet.interfaces.IWriteDescriptor`
overridden in `twisted.internet.base.BasePort`
Called when data can be written.

Returns
`None` on success, an exception or a negative integer on failure.
See Also
`twisted.internet.interfaces.IWriteDescriptor.doWrite`.

def fileno(self): (source)
from `twisted.internet.interfaces.IFileDescriptor`
overridden in `twisted.internet.inotify.INotify`, `twisted.internet.process.ProcessReader`, `twisted.internet.process.ProcessWriter`, `twisted.internet.process.PTYProcess`, `twisted.internet.serialport.SerialPort`, `twisted.pair.tuntap.TuntapPort`

File Descriptor number for select().

This method must be overridden or assigned in subclasses to indicate a valid file descriptor for the operating system.

def getHost(self): (source)
from `twisted.internet.interfaces.ITransport`
overridden in `twisted.internet.tcp.Port`, `twisted.internet.tcp.Server`, `twisted.internet.udp.Port`, `twisted.internet.unix.Client`, `twisted.pair.tuntap.TuntapPort`
Similar to getPeer, but returns an address describing this side of the connection.

Returns
An `IAddress` provider.

def getPeer(self): (source)
from `twisted.internet.interfaces.ITransport`
overridden in `twisted.internet.tcp.Server`, `twisted.internet.unix.Client`, `twisted.internet.unix.ConnectedDatagramPort`

Get the remote address of this connection.

Treat this method with caution. It is the unfortunate result of the CGI and Jabber standards, but should not be considered reliable for the usual host of reasons; port forwarding, proxying, firewalls, IP masquerading, etc.

Returns
An `IAddress` provider.

def loseConnection(self): (source)
from `twisted.internet.interfaces.ITransport`
overridden in `twisted.internet.process.ProcessReader`, `twisted.internet.tcp.Port`, `twisted.internet.udp.Port`, `twisted.pair.tuntap.TuntapPort`

Close the connection at the next available opportunity.

Call this to cause this FileDescriptor to lose its connection. It will first write any data that it has buffered.

If there is data buffered yet to be written, this method will cause the transport to lose its connection as soon as it's done flushing its write buffer. If you have a producer registered, the connection won't be closed until the producer is finished. Therefore, make sure you unregister your producer when it's finished, or the connection will never close.

def loseWriteConnection(self): (source)

Undocumented

def pauseProducing(self): (source)
from `twisted.internet.interfaces.IPushProducer`

Pause producing data.

Tells a producer that it has produced too much data to process for the time being, and to stop until `resumeProducing()` is called.

def readConnectionLost(self, reason): (source)
from `twisted.internet.interfaces.IHalfCloseableDescriptor`
overridden in `twisted.internet.tcp.Connection`
Indicates read connection was lost.

Parameters
reason:`failure.Failure` | Undocumented

def resumeProducing(self): (source)
from `twisted.internet.interfaces.IPushProducer`

Resume producing data.

This tells a producer to re-add itself to the main loop and produce more data for its consumer.

def startReading(self): (source)
Start waiting for read availability.
def startWriting(self): (source)
overrides `twisted.internet.abstract._ConsumerMixin.startWriting`

Start waiting for write availability.

Call this to have this FileDescriptor be notified whenever it is ready for writing.

def stopConsuming(self): (source)

Stop consuming data.

This is called when a producer has lost its connection, to tell the consumer to go lose its connection (and break potential circular references).

def stopProducing(self): (source)
from `twisted.internet.interfaces.IProducer`

Stop producing data.

This tells a producer that its consumer has died, so it must stop producing data for good.

def stopReading(self): (source)

Stop waiting for read availability.

Call this to remove this selectable from being notified when it is ready for reading.

def stopWriting(self): (source)

Stop waiting for write availability.

Call this to remove this selectable from being notified when it is ready for writing.

def write(self, data): (source)
from `twisted.internet.interfaces.IConsumer`
overridden in `twisted.internet.process.ProcessWriter`, `twisted.internet.serialport.SerialPort`, `twisted.internet.udp.Port`, `twisted.pair.tuntap.TuntapPort`

Reliably write some data.

The data is buffered until the underlying file descriptor is ready for writing. If there is more than `self.bufferSize` data in the buffer and this descriptor has a registered streaming producer, its `pauseProducing()` method will be called.

Parameters
data:`bytes` | Undocumented

def writeConnectionLost(self, reason): (source)
from `twisted.internet.interfaces.IHalfCloseableDescriptor`
Indicates write connection was lost.
def writeSequence(self, iovec): (source)
from `twisted.internet.interfaces.ITransport`
overridden in `twisted.internet.udp.Port`, `twisted.pair.tuntap.TuntapPort`

Reliably write a sequence of data.

Currently, this is a convenience method roughly equivalent to:

        for chunk in iovec:
            fd.write(chunk)

It may have a more efficient implementation at a later time or in a different reactor.

As with the `write()` method, if a buffer size limit is reached and a streaming producer is registered, it will be paused until the buffered data is written to the underlying file descriptor.

Parameters
iovec:`Iterable[bytes]` | Undocumented

def writeSomeData(self, data): (source)
overridden in `twisted.internet.process.ProcessReader`, `twisted.internet.process.ProcessWriter`, `twisted.internet.process.PTYProcess`, `twisted.internet.serialport.SerialPort`, `twisted.internet.tcp.Connection`

Write as much as possible of the given data, immediately.

This is called to invoke the lower-level writing functionality, such as a socket's send() method, or a file's write(); this method returns an integer or an exception. If an integer, it is the number of bytes written (possibly zero); if an exception, it indicates the connection was lost.

Parameters
data:`bytes` | Undocumented

SEND_LIMIT = (source)

Undocumented

Value

    128*1024

bufferSize = (source)

Undocumented

connected: `int` = (source)
overridden in `twisted.internet.inotify.INotify`, `twisted.internet.process.ProcessReader`, `twisted.internet.process.ProcessWriter`, `twisted.internet.process.PTYProcess`, `twisted.internet.serialport.SerialPort`, `twisted.internet.serialport.SerialPort`, `twisted.internet.tcp.BaseClient`, `twisted.internet.tcp.Port`, `twisted.internet.tcp.Server`, `twisted.internet.udp.Port`, `twisted.pair.tuntap.TuntapPort`

Undocumented

dataBuffer: `bytes` = (source)

Undocumented

disconnected: `int` = (source)

Undocumented

disconnecting: `int` = (source)
overridden in `twisted.internet.process.ProcessReader`, `twisted.internet.tcp.Port`, `twisted.pair.tuntap.TuntapPort`

Undocumented

offset: `int` = (source)

Undocumented

producer = (source)
overrides `twisted.internet.abstract._ConsumerMixin.producer`

Undocumented

producerPaused: `bool` = (source)
overrides `twisted.internet.abstract._ConsumerMixin.producerPaused`

Undocumented

reactor = (source)
overridden in `twisted.internet.serialport.SerialPort`, `twisted.internet.serialport.SerialPort`

Undocumented

def _closeWriteConnection(self): (source)
overridden in `twisted.internet.tcp.Connection`

Undocumented

def _isSendBufferFull(self): (source)

Determine whether the user-space send buffer for this transport is full or not.

When the buffer contains more than `self.bufferSize` bytes, it is considered full. This might be improved by considering the size of the kernel send buffer and how much of it is free.

Returns
`True` if it is full, `False` otherwise.

def _maybePauseProducer(self): (source)
Possibly pause a producer, if there is one and the send buffer is full.
def _postLoseConnection(self): (source)

Called after a loseConnection(), when all data has been written.

Whatever this returns is then returned by doWrite.

_tempDataBuffer: `list` = (source)

Undocumented

_tempDataLen: `int` = (source)

Undocumented

_writeDisconnected: `bool` = (source)
overridden in `twisted.internet.inotify.INotify`

Undocumented

_writeDisconnecting: `bool` = (source)

Undocumented