concurrence.io – The concurrence io module

Platforms: Unix

class concurrence.io.Buffer

Creates a Buffer object. The buffer class forms the basis for IO in the Concurrence Framework. The buffer class represents a mutable array of bytes of that can be read from and written to using the read_XXX and write_XXX methods. Operations on the buffer are performed relative to the current position attribute of the buffer. A buffer also has a current limit property above which no data may be read or written. If an operation tries to read beyond the current limit a BufferUnderflowError is raised. If an operation tries to write beyond the current limit a BufferOverflowError is raised. The general idea of the Buffer was shamelessly copied from java NIO.

copy(src, src_start, dst_start, length)
Copies length bytes from buffer src, starting at position src_start, to this buffer at position dst_start.
clear()
Prepares the buffer for relative read operations. The buffers limit will set to the buffers capacity and its position will be set to 0.
compact()
Prepares the buffer again for relative reading, but any left over data still present in the buffer (the bytes between the current position and current limit) will be copied to the start of the buffer. The position of the buffer will be right after the copied data.
copy()
Copies length bytes from buffer src, starting at position src_start, to this buffer at position dst_start.
duplicate()
Return a shallow copy of the Buffer, e.g. the copied buffer references the same bytes as the original buffer, but has its own independend position and limit.
flip()
Prepares the buffer for relative write operations. The buffers limit will set to the buffers position and its position will be set to 0.
read_byte()
Reads and returns a single byte from the buffer and updates the position by 1.
read_bytes()
Reads n bytes from buffer, updates position, and returns bytes as a python string, if there are no n bytes available, a BufferUnderflowError is raised.
read_bytes_until()
Reads bytes until character b is found, or end of buffer is reached in which case it will raise a BufferUnderflowError.
read_line()
Reads a single line of bytes from the buffer where the end of the line is indicated by either ‘LF’ or ‘CRLF’. The line will be returned as a string not including the line-separator. Optionally include_separator can be specified to make the method to also return the line-separator.
read_short()
Read a 2 byte little endian integer from buffer and updates position.
recv()
Reads as many bytes as will fit up till the limit of the buffer from the filedescriptor fd. Returns a tuple (bytes_read, bytes_remaining). If bytes_read is negative, a IO Error was encountered. The position of the buffer will be updated according to the number of bytes read.
rewind()
Sets the buffers position back to 0.
send()
Sends as many bytes as possible up till the limit of the buffer to the filedescriptor fd. Returns a tuple (bytes_written, bytes_remaining). If bytes_written is negative, an IO Error was encountered.
skip()
Updates the buffers position by skipping n bytes. It is not allowed to skip passed the current limit. In that case a BufferUnderflowError will be raised and the position will remain the same
write_buffer()
writes available bytes from other buffer to this buffer
write_byte()
writes a single byte to the buffer and updates position
write_bytes()
Writes a number of bytes given by the python string s to the buffer and updates position. Raises BufferOverflowError if you try to write beyond the current limit.
write_int()
writes a 32 bit integer to the buffer and updates position (little-endian)
write_short()
writes a 16 bit integer to the buffer and updates position (little-endian)
class concurrence.io.Socket(socket, state=0)

don’t call directly pls use one of the provided classmethod to create a socket

accept()
waits on a listening socket, returns a new socket_class instance for the incoming connection
classmethod connect(addr, timeout=-1)
creates a new socket and connects it to the given address. returns the connected sockets
classmethod from_address(addr)
Creates a new socket from the given address. If the addr is a tuple (host, port) a normal tcp socket is assumed. if addr is a string, a UNIX Domain socket is assumed
read(buffer, timeout=-1.0)
Blocks till socket becomes readable and then reads as many bytes as possible the socket into the given buffer. The buffer position is updated according to the number of bytes read from the socket. This method could possible read 0 bytes. The method returns the total number of bytes read
read_socket(socket_class=None, socket_family=2, socket_type=1, socket_state=0, timeout=-1)
reads a socket from this socket
write(buffer, timeout=-1.0)
Blocks till socket becomes writable and then writes as many bytes as possible from given buffer to the socket. The buffer position is updated according to the number of bytes read from it. This method could possible write 0 bytes. The method returns the total number of bytes written
write_socket(socket, timeout=-1)
writes a socket trough this socket
class concurrence.io.SocketServer(endpoint, handler=None)
bind()
creates socket if needed, and binds it
listen(backlog=255)
creates socket if needed, and listens it
serve()
listens and starts a new tasks accepting incoming connections on the configured address
class concurrence.io.BufferedStream(stream, buffer_size=8192, read_buffer_size=0, write_buffer_size=0)

Previous topic

concurrence.core – The concurrence core module

Next topic

concurrence.timer – A timer module

This Page