Implement active sockets like Erlang's gen_tcp and gen_udp
Created a new module -- pyact.actnet that has 3 functions
socket() : equivalent to socket.socket()
connect() : equivalent to eventlet.connect()
listen() : equivalent to eventlet.listen()
These take all the original arguments plus an optional 'active'
argument (see below for details) and return an active socket
object. The active socket object is similar to eventlet's
green socket object but has these additional methods:
.getactor() -> actor.Address
.getactive() -> True|False|actnet.ONCE
.getrecvmax() -> int
An active socket is created by an actor. It is then associated with that
actor. If the socket is set to active mode (True or actnet.ONCE)
it will listen for data from the socket, receive the data and send it
to the controlling process as a set of actor message.
Messages would look like this:
This allows the creating actor to have a single message receive
loop where it waits for actor message and network data, instead
of having to continuously poll both.
When active is False, socket object will act as regular eventlet
green sockets objects -- on receive they will block the green
thread that is listening for data.
When active is True, data will be continously read off the socket
and sent to the controlling actor as messages specified in the
format above. This however would be a problem when receiving a
fast stream of TCP data, as it will break flow control, to alievate
that problem, can set socket active to actnet.ONCE value. This will
make the socket active but only for the reception of one single
packet, after that the socket becomes inactive again and the
user will have to manually switch it back to active mode.