Package pike :: Module transport :: Class Transport
[hide private]
[frames] | no frames]

Class Transport

source code

object --+
         |
        Transport
Known Subclasses:

Transport is responsible for managing the underlying socket, registering for socket events, dispatching read, write, and errors to higher layers. It is analogous to asyncore.dispatcher and is a drop in replacement for most purposes.

If the alternate_poller is specified on instantiation, then the connection will register for events on that poller as opposed to the global poller.

Instance Methods [hide private]
 
__init__(self, alternate_poller=None)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
close(self)
close the underlying socket connection and unregister this Transport from the underlying poller
source code
 
connect(self, address)
begin establishing a connection to the (host, port) address tuple.
source code
 
create_socket(self, family, type)
Creates the underlying non-blocking socket and associates it with this Transport's underlying poller
source code
 
handle_close(self)
callback fired when the socket is closed
source code
 
handle_connect(self)
callback fired when connection is established
source code
 
handle_connect_event(self)
called internally when the socket becomes connected
source code
 
handle_error(self)
callback fired if a non-recoverable exception is raised
source code
 
handle_read(self)
callback fired when the socket has data available
source code
 
handle_write(self)
callback fired when the socket is available for writing
source code
 
recv(self, bufsize)
recv bufsize bytes over the connection.
source code
 
send(self, data)
send data bytes over the connection.
source code
 
set_socket(self, sock)
mirror the given Socket sock's file descriptor on the Transport and register this Transport with the underlying poller
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, alternate_poller=None)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

connect(self, address)

source code 

begin establishing a connection to the (host, port) address tuple.

must call create_socket first. if the underlying socket is non-blocking then this command may return before the connection is established.

higher level code should wait for the handle_connect event to signal that the endpoint is successfully connected

handle_write(self)

source code 

callback fired when the socket is available for writing

note: unlike asyncore, write notifications are not provided by default. this is a performance optimization because the socket is usually available for writing, and the application usually knows when it wants to write. There is no point in filling the event queues with write ready messages that will be ignored if the client has no data to send.

Instead, applications are expected to implement handle_write, but to call it directly when data is to be sent. IF the socket would block, EALREADY will be handled by the Transport. The Transport requests a single write notification from the pollwer; when received, handle_write will be called once signalling that the socket may now be ready to retry

If the application would prefer to be notified when the socket is ready to write, transport.poller.defer_write(transport) may be called to schedule a single handle_write callback.

recv(self, bufsize)

source code 

recv bufsize bytes over the connection. if the socket would block, then return an empty buffer. When the socket is available for reading handle_read will be called.

returns a string representing the bytes received

send(self, data)

source code 

send data bytes over the connection. if the socket would block, schedule this Transport to be notified when the socket is available for writing. handle_write will be called in this case.

returns the number of bytes sent or zero if the write would block