-
Notifications
You must be signed in to change notification settings - Fork 0
data structures
Implementation of datastructures supporting lock-free and wait-free constructs. The implementations are helpful for an application which deals with shared data across threads.
#include <ev_queue.h>
Exposes the Type definitions
typedef struct ev_queue_s *ev_queue_type;
typedef void (*print_qnode_func_type)(void*);
Creates a new ev_queue and initializes it
Parameters:
none
Return:
queue: ev_queue_type
Empties the queue and frees up the memory.
Parameters:
queue: ev_queue_type
Return:
none
Enqueues data at the tail of the datastructure
Parameters:
queue: ev_queue_type
data: void*
Return:
none
Dequeues one element from the head of the datastructure
Parameters:
queue: ev_queue_type
Return:
data: void \*, NULL if empty
C++ Class that implements the chunked memory stream
chunked_memory_stream is a datastructure suitable for transmission of large streams of data like, video/audio buffer etc... It provides a mechanism by which the sending side can push parts of memory stream as chunks and the receiving side can dequeue the chunks and push the data over a socket.
The sending and the receiving threads can operate concurrently on the data structure without the need to synchronize their operations.
Transfers 'bytes' number of bytes to the chunked_memory_stream.
From the memory buffer.
The caller is expected to manage the memory for buffer.
Returns the number of bytes transferred.
Parameters:
buffer: void*
bytes: size_t
Return:
bytes_transferred: size_t
Copies 'bytes' number of bytes from the chunked_memory_stream,
the data is copied starting at offset '0 + start_pos'.
If there is less data, as many bytes as there are are copied
to the location pointed by buffer.
The caller is expected to allocate memory to the buffer.
Differences between this and pull_out are,
This method only copies the data and leaves the source unaltered
This method has the ability to copy from any offset location.
Returns the number of bytes copied, or 0 if no data is available
or -1 if there is any error.
Parameters:
start_pos: size_t
buffer: void*
bytes: size_t
Return:
bytes: ssize_t
Copies 'bytes' number of bytes from the chunked_memory_stream,
from the start position 0.
If there is less data, as many bytes as there are are copied
to the location pointed by buffer.
The caller is expected to allocate memory to the buffer.
Unlike the other version of read, this copies the data to the buffer
and erases from the source.
The index start_pos is C style, i.e. first character is at 0th
position.
Differences between this and pull_out are,
This method only copies the data and leaves the source unaltered
This method has the ability to copy from any offset location.
Returns the number of bytes copied, or 0 if no data is available
or -1 if there is any error.
Parameters:
buffer: void*
bytes: size_t
Return:
bytes: size_t
Moves the head of the data stream to the offset 0 + bytes
Memory holding the data is freed.
Returns the number of bytes erased.
Parameters:
bytes: size_t
Return:
bytes: size_t
Gets the available allocated, buffer at the head.
This way of accessing data will help to avoid
a memcpy
Parameters:
none
Return:
buffer: void*
Gets length of the available allocated buffer at the head.
This way of accessing data will help to avoid
Parameters:
none
Return:
none
Gets the length of the buffer of the given node.
Parameters:
node: void*
Return:
bytes: size_t
Gets the data buffer in the given node
Parameters:
node: void*
Return:
buffer: void*
Gets the next node in the list of nodes, given the current node
Parameters:
node: void*
Return:
nex_node: void*
C++ Class that implements the chunked memory stream
Exposes chunked_memory_stream as a a std::basic_streambuf The user has to implement a concrete class inheriting ev_buffered_stream. Further they have to expose the stream by classes inheriting std::ios, std::istream and std::ostream for management of the buffer, as input stream and as output stream respectively.
The construction of std::ios , std::istream and std::ostream implementations should inialize the base class ev_buffered_stream with chunked_memory_stream *cms
Ensures that the whole input buffer (of max_len) is consumed before the buffer is destroyed.
Parameters:
none
Return:
none
The inheriting class can override the implementation to get an actual prefix in a chunk of multiple chunks of the stream.
Used in chuncked stream encoding of HTTP Request and HTTP response
Parameters:
buffer: char*
prefix: char*
ptr_bytes: size_t
Return:
none
The inheriting class can override the implementation to get an actual suffix in a chunk of multiple chunks of the stream.
Used in chuncked stream encoding of HTTP Request and HTTP response
Parameters:
buffer: char*
prefix: char*
ptr_bytes: size_t
Return:
none
Reads memory from source, can be overriden by the inheriting class to manage the reading process.
Used in chuncked stream encoding of HTTP Request and HTTP response
Parameters:
buffer: char*
prefix: char*
ptr_bytes: size_t
Return:
none
Used to set prefix and siffix lengths
Used in chuncked stream encoding of HTTP Request and HTTP response
Parameters:
length: size_t
Return:
none
Writes data to output buffer (sync). Can be overriden in the inherited class
Used in chuncked stream encoding of HTTP Request and HTTP response
Parameters:
buffer: char*
size: std::streamsize
Return:
size: size_t
Reads one character from source and moves the pointer by one char
Parameters:
none
Return:
ch: int