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

Type FileDescriptor

Ephemeral --+
            |
   Logger --+
            |
   object --+
            |
           FileDescriptor

Known Subclasses:
Connection, BasePort

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)
  connectionLost(self, reason)
The connection was lost.
  doRead(self)
Called when data is avaliable for reading.
  doWrite(self)
Called when data can be written.
  fileno(self)
File Descriptor number for select().
  loseConnection(self, _connDone)
Close the connection at the next available opportunity.
  loseWriteConnection(self)
  pauseProducing(self)
  readConnectionLost(self, reason)
  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.
  writeConnectionLost(self, reason)
  writeSequence(self, iovec)
Reliably write a sequence of data.
  writeSomeData(self, data)
Write as much as possible of the given data, immediately.
  _closeWriteConnection(self)
  _postLoseConnection(self)
Called after a loseConnection(), when all data has been written.
    Inherited from Logger
  logPrefix(self)
Override this method to insert custom logging behavior.
    Inherited from Ephemeral
  __getstate__(self)
  __setstate__(self, state)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Class Variable Summary
Implements __implemented__ = <implementedBy twisted.internet.abstra...
ClassProvides __provides__ = <zope.interface.declarations.ClassProvide...
int bufferSize = 65536                                                                 
int connected = 0                                                                     
str dataBuffer = ''
int disconnected = 0                                                                     
int disconnecting = 0                                                                     
int offset = 0                                                                     
NoneType producer = None                                                                  
int producerPaused = 0                                                                     
int SEND_LIMIT = 131072                                                                
int streamingProducer = 0                                                                     
bool _writeDisconnected = False
bool _writeDisconnecting = False
    Inherited from Logger
ClassProvides __providedBy__ = <zope.interface.declarations.ClassProvi...

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.

doRead(self)

Called when data is avaliable for reading.

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

doWrite(self)

Called when data can be written.

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, _connDone=<twisted.python.failure.Failure <class 'twisted.internet....)

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.

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(). When the FileDescriptor's internal data buffer is filled, it will ask the producer to pauseProducing(). If the connection is lost, FileDescriptor calls producer's stopProducing() method.

If streaming is true, the producer should provide the IPushProducer interface. Otherwise, it is assumed that producer provides the IPullProducer interface. In this case, the producer won't be asked to pauseProducing(), but it has to be careful to write() data only when its resumeProducing() method is called.

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.

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.

writeSequence(self, iovec)

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.

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

__implemented__

Type:
Implements
Value:
<implementedBy twisted.internet.abstract.FileDescriptor>               

__provides__

Type:
ClassProvides
Value:
<zope.interface.declarations.ClassProvides object at 0x30261c50>       

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                                                                     

SEND_LIMIT

Type:
int
Value:
131072                                                                

streamingProducer

Type:
int
Value:
0                                                                     

_writeDisconnected

Type:
bool
Value:
False                                                                  

_writeDisconnecting

Type:
bool
Value:
False                                                                  

Generated by Epydoc 2.1 on Fri May 18 09:35:48 2007 http://epydoc.sf.net