This module provides optional support for data compression and decompression according to RFC 8054. More...
Macros | |
#define | MAIN_ERR_PREFIX "COMPR: " |
Message prefix for COMPRESSION module. | |
#define | CMPR_DEBUG 0 |
Print debug messages to stdout if nonzero. | |
#define | CMPR_BUFSIZE (size_t) 32768 |
Size of internal data buffers. More... | |
#define | CMPR_ZLIB_WINDOW_BITS -15 |
Window size for DEFLATE algorithm. More... | |
#define | CMPR_ZLIB_MEM_LEVEL 9 |
Memory usage for DEFLATE algorithm. More... | |
Functions | |
posix_ssize_t | cmpr_send (void *stream, const void *buf, size_t len) |
Send data. More... | |
int | cmpr_flush (void *stream) |
Flush TX direction. More... | |
int | cmpr_terminate (void *stream) |
Flush TX direction and terminate data stream. More... | |
posix_ssize_t | cmpr_recv (void *stream, void *buf, size_t len, int peek) |
Receive data. More... | |
struct cmpr_stream * | cmpr_stream_constructor (unsigned int alg, int sd, ssize_t(*tx_send)(int, const void *, size_t, int), ssize_t(*rx_recv)(int, void *, size_t, int)) |
Compressed data stream object constructor. More... | |
void | cmpr_stream_destructor (void *stream) |
Destroy compressed data stream object allocated by compression module. More... | |
int | cmpr_init (void) |
Initialize compression module. | |
void | cmpr_exit (void) |
Shutdown compress module. | |
Flush options for TX direction of compressed data streams | |
#define | CMPR_FLUSH_NO 0 |
#define | CMPR_FLUSH_YES 1 |
#define | CMPR_FLUSH_END 2 |
Compression algorithms | |
#define | CMPR_ALG_DEFLATE 0x0001U |
DEFLATE according to RFC 1951. | |
This module provides optional support for data compression and decompression according to RFC 8054.
Currently the following algorithms are supported:
#define CMPR_BUFSIZE (size_t) 32768 |
Size of internal data buffers.
uInt
must be capable of holding this value. Definition at line 94 of file compression.c.
#define CMPR_ZLIB_MEM_LEVEL 9 |
Memory usage for DEFLATE algorithm.
Speed vs. memory usage tradeoff for zlib (integer value from 1 to 9)
1: Minimum memory usage for minimum speed
9: Maximum memory usage for maximum speed
Definition at line 124 of file compression.c.
#define CMPR_ZLIB_WINDOW_BITS -15 |
Window size for DEFLATE algorithm.
Compression ratio vs. memory usage tradeoff (integer value from -8 to -15). Negative base two logarithm of the window size (size of the history buffer) for zlib. The negative sign selects raw data without container.
-8: Worst compression and minimum memory usage (256 Byte)
-15: Best compression and maximum memory usage (32 KiByte)
Definition at line 114 of file compression.c.
int cmpr_flush | ( | void * | stream | ) |
Flush TX direction.
[in] | stream | Pointer to stream object pointer |
Definition at line 384 of file compression.c.
References MAIN_ERR_PREFIX.
posix_ssize_t cmpr_recv | ( | void * | stream, |
void * | buf, | ||
size_t | len, | ||
int | peek | ||
) |
Receive data.
[in] | stream | Pointer to stream object pointer |
[out] | buf | Pointer to data buffer |
[in] | len | Number of octets to receive |
[in] | peek | Data should stay available for reading if nonzero |
Definition at line 443 of file compression.c.
References CMPR_ALG_DEFLATE, CMPR_BUFSIZE, MAIN_ERR_PREFIX, and PRINT_ERROR.
posix_ssize_t cmpr_send | ( | void * | stream, |
const void * | buf, | ||
size_t | len | ||
) |
Send data.
[in] | stream | Pointer to stream object pointer |
[in] | buf | Pointer to data buffer |
[in] | len | Number of octets to send |
Definition at line 362 of file compression.c.
References MAIN_ERR_PREFIX.
struct cmpr_stream* cmpr_stream_constructor | ( | unsigned int | alg, |
int | sd, | ||
ssize_t(*)(int, const void *, size_t, int) | tx_send, | ||
ssize_t(*)(int, void *, size_t, int) | rx_recv | ||
) |
Compressed data stream object constructor.
[in] | alg | Compression algorithm (use CMPR_ALG_xxx constants) |
[in] | sd | Socket descriptor or stream handle of undelaying protocol |
[in] | tx_send | Send function to underlaying protocol |
[in] | rx_recv | Receive function for underlaying protocol |
send()
and recv()
defined by POSIX.1-2001 with compatibility to the 4.2BSD implementation regarding flags).NULL
on error Definition at line 615 of file compression.c.
References CMPR_ALG_DEFLATE, CMPR_BUFSIZE, and PRINT_ERROR.
void cmpr_stream_destructor | ( | void * | stream | ) |
Destroy compressed data stream object allocated by compression module.
[in] | stream | Pointer to object |
NULL
and no operation is performed in this case. Definition at line 768 of file compression.c.
References CMPR_ALG_DEFLATE, and PRINT_ERROR.
int cmpr_terminate | ( | void * | stream | ) |
Flush TX direction and terminate data stream.
[in] | stream | Pointer to stream object pointer |
Definition at line 410 of file compression.c.
References MAIN_ERR_PREFIX.