Package twisted :: Package internet :: Module abstract :: Class FileDescriptor

[show private | hide private]
[frames | no frames]

## Class FileDescriptor

       Logger --+
                |
    Ephemeral --+
                |
               FileDescriptor

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

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)`
| `__getstate__(self)` (inherited from `Ephemeral`)
| `__setstate__(self, state)` (inherited from `Ephemeral`)
| ``connectionLost`(self, reason)` The connection was lost.
| ``doWrite`(self)` Called when data is available for writing.
| ``fileno`(self)` File Descriptor number for select().
| `log(self, bytes)` (inherited from `Logger`)
| ``logPrefix`(self)` Override this method to insert custom logging behavior. (inherited from `Logger`)
| ``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.
| `_Logger__prefix(self)` (inherited from `Logger`)
| ``_postLoseConnection`(self)` Called after a loseConnection(), when all data has been written.

Class Variable Summary
`tuple` | `__implements__`
`int` | `bufferSize`
`int` | `connected`
`int` | `disconnected`
`int` | `disconnecting`
`None` | `producer`
`int` | `producerPaused`
`int` | `streamingProducer`
`string` | `unsent`

Method Details

### 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.

Call this to remove this selectable notified whenever it is ready for reading.

### 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.

### _postLoseConnection(self)

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

Whatever this returns is then returned by doWrite.

Class Variable Details

### __implements__

  Type:
    `tuple`
  Value:

        (<class twisted.internet.interfaces.IProducer at 0x81d489c>,
         <class twisted.internet.interfaces.IReadWriteDescriptor at 0x81d45dc>\
        ,
         <class twisted.internet.interfaces.IConsumer at 0x81d4704>,
         <class twisted.internet.interfaces.ITransport at 0x81d4bcc>)

### bufferSize

  Type:
    `int`
  Value:

        65536

### connected

  Type:
    `int`
  Value:

        0

### disconnected

  Type:
    `int`
  Value:

        0

### disconnecting

  Type:
    `int`
  Value:

        0

### producer

  Type:
    `None`
  Value:

        None

### producerPaused

  Type:
    `int`
  Value:

        0

### streamingProducer

  Type:
    `int`
  Value:

        0

### unsent

  Type:
    `string`
  Value:

        ''

Generated by Epydoc 1.1 on Sat Feb 15 21:19:03 2003 | http://epydoc.sf.net