Module: cogen.core.sockets
Socket-only coroutine operations and
Socket
wrapper.Classes
Accept
Returns a (conn, addr) tuple when the operation completes.
Connect
Connect to the given
addr
using sock
.Read
len
is max read size, BUT, if if there are buffers from ReadLine
return them first.
Example usage:yield sockets.Read(socket_object, buffer_length)
ReadAll
Run this operator till we've read
len
bytes.ReadLine
Run this operator till we read a newline (\n) or we have a overflow.
len
is the max size for a lineSendFile
Uses underling OS sendfile call or a regular memory copy operation if
there is no sendfile.
You can use this as a WriteAll if you specify the length.
Usage:
yield sockets.SendFile(<file handle>, <sock>, 0) # will send till send operations return 0 yield sockets.SendFile(<file handle>, <sock>, 0, blocksize=0) # there will be only one send operation (if successfull) # that meas the whole file will be read in memory if there is #no sendfile yield sockets.SendFile(<file handle>, <sock>, 0, <file size>) # this will hang if we can't read <file size> bytes #from the file
Socket
A wrapper for socket objects, sets nonblocking mode and
add some attributes we need:
- rl_pending - for unchecked for linebreaks buffer
- rl_list - for checked for linebreaks buffers
- rl_list_sz - a cached size of the summed sizes of rl_list buffers
Write
Write the buffer to the socket and return the number of bytes written.
WriteAll
Run this operation till all the bytes have been written.