twisted.internet.abstract.FileDescriptor

Package twisted :: Package internet :: Module abstract :: Class FileDescriptor |
[frames | no frames]

## Class FileDescriptor

    Ephemeral --+
                |
       Logger --+
                |
               FileDescriptor

Known Subclasses:
  `BasePort`, `Connection`, `Process`, `ProcessReader`, `ProcessWriter`, `PTYProcess`, `SerialPort`, `SerialPort`, `StandardIO`, `StandardIOWriter`

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 Summary
| `__init__(self, reactor)`
| ``_postLoseConnection`(self)` Called after a loseConnection(), when all data has been written.
| ``connectionLost`(self, reason)` The connection was lost.
| ``doWrite`(self)` Called when data is available for writing.
| ``fileno`(self)` File Descriptor number for select().
| ``loseConnection`(self)` Close the connection at the next available opportunity.
| `pauseProducing(self)`
| ``registerProducer`(self, producer, streaming)` Register to receive data from a producer.
| `resumeProducing(self)`
| ``startReading`(self)` Start waiting for read availability.
| ``startWriting`(self)` Start waiting for write availability.
| ``stopConsuming`(self)` Stop consuming data.
| `stopProducing(self)`
| ``stopReading`(self)` Stop waiting for read availability.
| ``stopWriting`(self)` Stop waiting for write availability.
| ``unregisterProducer`(self)` Stop consuming data from a producer, without disconnecting.
| ``write`(self, data)` Reliably write some data.
| `writeSequence(self, iovec)`
| ``writeSomeData`(self, data)` Write as much as possible of the given data, immediately.
Inherited from Logger
| ``logPrefix`(self)` Override this method to insert custom logging behavior.
Inherited from Ephemeral
| ``__getstate__`(self)`
| ``__setstate__`(self, state)`

Class Variable Summary
`tuple` | `__implements__` = `(<class twisted.internet.interfaces.IPr...`
`int` | `bufferSize` = 65536
`int` | `connected` = 0
`str` | `dataBuffer` = `''`
`int` | `disconnected` = 0
`int` | `disconnecting` = 0
`int` | `offset` = 0
`NoneType` | `producer` = None
`int` | `producerPaused` = 0
`int` | `streamingProducer` = 0

Method Details

### _postLoseConnection(self) Called after a loseConnection(), when all data has been written. Whatever this returns is then returned by doWrite.

### connectionLost(self, reason) 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.

### doWrite(self) Called when data is available for writing. A result that is true (which will be a negative number) implies the connection was lost. A false result implies the connection is still there; a result of 0 implies no write was done, and a result of None indicates that a write was done.

### fileno(self) File Descriptor number for select(). This method must be overridden or assigned in subclasses to indicate a valid file descriptor for the operating system.

### loseConnection(self) Close the connection at the next available opportunity. Call this to cause this FileDescriptor to lose its connection; if this is in the main loop, it will lose its connection as soon as it's done flushing its write buffer; otherwise, it will wake up the main thread and lose the connection immediately. 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.

### registerProducer(self, producer, streaming) Register to receive data from a producer. This sets this selectable to be a consumer for a producer. When this selectable runs out of data on a write() call, it will ask the producer to resumeProducing(). A producer should implement the IProducer interface. FileDescriptor provides some infrastructure for producer methods.

### startReading(self) Start waiting for read availability.

### startWriting(self) Start waiting for write availability. Call this to have this FileDescriptor be notified whenever it is ready for writing.

### stopConsuming(self) 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).

### stopReading(self) Stop waiting for read availability. Call this to remove this selectable from being notified when it is ready for reading.

### stopWriting(self) Stop waiting for write availability. Call this to remove this selectable from being notified when it is ready for writing.

### unregisterProducer(self) Stop consuming data from a producer, without disconnecting.

### write(self, data) Reliably write some data. If there is no buffered data this tries to write this data immediately, otherwise this adds data to be written the next time this file descriptor is ready for writing.

### writeSomeData(self, data) 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. If positive, it is the number of bytes written; if negative, it indicates the connection was lost.

Class Variable Details

    ### __implements__ Type: `tuple` Value:
        (<class twisted.internet.interfaces.IProducer at 0x827b064>,
         <class twisted.internet.interfaces.IReadWriteDescriptor at 0x827d20c>\
        ,
         <class twisted.internet.interfaces.IConsumer at 0x824feb4>,
         <class twisted.internet.interfaces.ITransport at 0x8254024>)

    ### bufferSize Type: `int` Value:
        65536

    ### connected Type: `int` Value:
        0

    ### dataBuffer Type: `str` Value:
        ''

    ### disconnected Type: `int` Value:
        0

    ### disconnecting Type: `int` Value:
        0

    ### offset Type: `int` Value:
        0

    ### producer Type: `NoneType` Value:
        None

    ### producerPaused Type: `int` Value:
        0

    ### streamingProducer Type: `int` Value:
        0

Generated by Epydoc 2.0 on Sat May 15 20:08:36 2004 | http://epydoc.sf.net