functions for buffering IO More...
Go to the source code of this file.
Data Structures | |
struct | GNUNET_BIO_ReadHandle |
Handle for buffered reading. More... | |
struct | GNUNET_BIO_WriteHandle |
Handle for buffered writing. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "util-bio", __VA_ARGS__) |
#define | PATH_MAX 4096 |
Assumed maximum path length (for source file names). More... | |
#define | BIO_BUFFER_SIZE 65536 |
Size for I/O buffers. More... | |
Enumerations | |
enum | IOType { IO_FILE = 0 , IO_BUFFER } |
Enum used internally to know how buffering is handled. More... | |
Functions | |
struct GNUNET_BIO_ReadHandle * | GNUNET_BIO_read_open_file (const char *fn) |
Open a file for reading. More... | |
struct GNUNET_BIO_ReadHandle * | GNUNET_BIO_read_open_buffer (void *buffer, size_t size) |
Create a handle from an existing allocated buffer. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_read_close (struct GNUNET_BIO_ReadHandle *h, char **emsg) |
Close an open handle. More... | |
void | GNUNET_BIO_read_set_error (struct GNUNET_BIO_ReadHandle *h, const char *emsg) |
Set read error to handle. More... | |
static int | read_from_file (struct GNUNET_BIO_ReadHandle *h, const char *what, char *result, size_t len) |
Function used internally to read the contents of a file into a buffer. More... | |
static int | read_from_buffer (struct GNUNET_BIO_ReadHandle *h, const char *what, char *result, size_t len) |
Function used internally to read the content of a buffer into a buffer. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_read (struct GNUNET_BIO_ReadHandle *h, const char *what, void *result, size_t len) |
Read some contents into a buffer. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_read_string (struct GNUNET_BIO_ReadHandle *h, const char *what, char **result, size_t max_length) |
Read 0-terminated string. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_read_float (struct GNUNET_BIO_ReadHandle *h, const char *what, float *f) |
Read a float. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_read_double (struct GNUNET_BIO_ReadHandle *h, const char *what, double *f) |
Read a double. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_read_int32 (struct GNUNET_BIO_ReadHandle *h, const char *what, int32_t *i) |
Read an (u)int32_t. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_read_int64 (struct GNUNET_BIO_ReadHandle *h, const char *what, int64_t *i) |
Read an (u)int64_t. More... | |
struct GNUNET_BIO_WriteHandle * | GNUNET_BIO_write_open_file (const char *fn) |
Open a file for writing. More... | |
struct GNUNET_BIO_WriteHandle * | GNUNET_BIO_write_open_buffer (void) |
Create a handle backed by an in-memory buffer. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_write_close (struct GNUNET_BIO_WriteHandle *h, char **emsg) |
Close an IO handle. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_flush (struct GNUNET_BIO_WriteHandle *h) |
Force a file-based buffered writer to flush its buffer. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_get_buffer_contents (struct GNUNET_BIO_WriteHandle *h, char **emsg, void **contents, size_t *size) |
Get the IO handle's contents. More... | |
static enum GNUNET_GenericReturnValue | write_to_file (struct GNUNET_BIO_WriteHandle *h, const char *what, const char *source, size_t len) |
Function used internally to write the contents of a buffer into a file. More... | |
static int | write_to_buffer (struct GNUNET_BIO_WriteHandle *h, const char *what, const char *source, size_t len) |
Function used internally to write the contents of a buffer to another buffer. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_write (struct GNUNET_BIO_WriteHandle *h, const char *what, const void *buffer, size_t n) |
Write a buffer to a handle. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_write_string (struct GNUNET_BIO_WriteHandle *h, const char *what, const char *s) |
Write a 0-terminated string. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_write_float (struct GNUNET_BIO_WriteHandle *h, const char *what, float f) |
Write a float. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_write_double (struct GNUNET_BIO_WriteHandle *h, const char *what, double f) |
Write a double. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_write_int32 (struct GNUNET_BIO_WriteHandle *h, const char *what, int32_t i) |
Write an (u)int32_t. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_write_int64 (struct GNUNET_BIO_WriteHandle *h, const char *what, int64_t i) |
Write an (u)int64_t. More... | |
static int | read_spec_handler_object (void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size) |
Function used internally to read some bytes from within a read spec. More... | |
struct GNUNET_BIO_ReadSpec | GNUNET_BIO_read_spec_object (const char *what, void *result, size_t len) |
Create the specification to read a certain amount of bytes. More... | |
static int | read_spec_handler_string (void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size) |
Function used internally to read a string from within a read spec. More... | |
struct GNUNET_BIO_ReadSpec | GNUNET_BIO_read_spec_string (const char *what, char **result, size_t max_length) |
Create the specification to read a 0-terminated string. More... | |
static int | read_spec_handler_int32 (void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size) |
Function used internally to read an (u)int32_t from within a read spec. More... | |
struct GNUNET_BIO_ReadSpec | GNUNET_BIO_read_spec_int32 (const char *what, int32_t *i) |
Create the specification to read an (u)int32_t. More... | |
static int | read_spec_handler_int64 (void *cls, struct GNUNET_BIO_ReadHandle *h, const char *what, void *target, size_t target_size) |
Function used internally to read an (u)int64_t from within a read spec. More... | |
struct GNUNET_BIO_ReadSpec | GNUNET_BIO_read_spec_int64 (const char *what, int64_t *i) |
Create the specification to read an (u)int64_t. More... | |
struct GNUNET_BIO_ReadSpec | GNUNET_BIO_read_spec_float (const char *what, float *f) |
Create the specification to read a float. More... | |
struct GNUNET_BIO_ReadSpec | GNUNET_BIO_read_spec_double (const char *what, double *f) |
Create the specification to read a double. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_read_spec_commit (struct GNUNET_BIO_ReadHandle *h, struct GNUNET_BIO_ReadSpec *rs) |
Execute the read specifications in order. More... | |
static int | write_spec_handler_object (void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size) |
Function used internally to write some bytes from within a write spec. More... | |
struct GNUNET_BIO_WriteSpec | GNUNET_BIO_write_spec_object (const char *what, void *source, size_t size) |
Create the specification to read some bytes. More... | |
static int | write_spec_handler_string (void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size) |
Function used internally to write a 0-terminated string from within a write spec. More... | |
struct GNUNET_BIO_WriteSpec | GNUNET_BIO_write_spec_string (const char *what, const char *s) |
Create the specification to write a 0-terminated string. More... | |
static int | write_spec_handler_int32 (void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size) |
Function used internally to write an (u)int32_t from within a write spec. More... | |
struct GNUNET_BIO_WriteSpec | GNUNET_BIO_write_spec_int32 (const char *what, int32_t *i) |
Create the specification to write an (u)int32_t. More... | |
static int | write_spec_handler_int64 (void *cls, struct GNUNET_BIO_WriteHandle *h, const char *what, void *source, size_t source_size) |
Function used internally to write an (u)int64_t from within a write spec. More... | |
struct GNUNET_BIO_WriteSpec | GNUNET_BIO_write_spec_int64 (const char *what, int64_t *i) |
Create the specification to write an (u)int64_t. More... | |
struct GNUNET_BIO_WriteSpec | GNUNET_BIO_write_spec_float (const char *what, float *f) |
Create the specification to write a float. More... | |
struct GNUNET_BIO_WriteSpec | GNUNET_BIO_write_spec_double (const char *what, double *f) |
Create the specification to write an double. More... | |
enum GNUNET_GenericReturnValue | GNUNET_BIO_write_spec_commit (struct GNUNET_BIO_WriteHandle *h, struct GNUNET_BIO_WriteSpec *ws) |
Execute the write specifications in order. More... | |
functions for buffering IO
Definition in file bio.c.
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "util-bio", __VA_ARGS__) |
#define PATH_MAX 4096 |
enum IOType |
|
static |
Function used internally to read the contents of a file into a buffer.
h | the IO handle to read from |
what | describes what is being read (for error message creation) |
result | the buffer to write the data to |
len | the number of bytes to read |
Definition at line 204 of file bio.c.
References _, GNUNET_asprintf(), GNUNET_assert, GNUNET_DISK_file_read(), GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, h, min, GNUNET_BIO_ReadHandle::pos, result, and ret.
Referenced by GNUNET_BIO_read().
|
static |
Function used internally to read the content of a buffer into a buffer.
h | the IO handle to read from |
what | describes what is being read (for error message creation) |
result | the buffer to write the result to |
len | the number of bytes to read |
Definition at line 262 of file bio.c.
References _, GNUNET_asprintf(), GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, h, and result.
Referenced by GNUNET_BIO_read().
|
static |
Function used internally to write the contents of a buffer into a file.
h | the IO handle to write to |
what | describes what is being written (for error message creation) |
source | the buffer to write |
len | the number of bytes to write |
Definition at line 673 of file bio.c.
References _, GNUNET_BIO_WriteHandle::buffer, GNUNET_asprintf(), GNUNET_assert, GNUNET_BIO_flush(), GNUNET_break, GNUNET_free, GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, h, min, and source.
Referenced by GNUNET_BIO_write().
|
static |
Function used internally to write the contents of a buffer to another buffer.
h | the IO handle to write to |
what | describes what is being written (for error message creation) |
source | the buffer to write |
len | the number of bytes to write |
Definition at line 729 of file bio.c.
References GNUNET_buffer_write(), GNUNET_OK, h, and source.
Referenced by GNUNET_BIO_write().
|
static |
Function used internally to read some bytes from within a read spec.
cls | ignored, always NULL |
h | the IO handle to read from |
what | what is being read (for error message creation) |
target | where to store the data |
target_size | how many bytes to read |
Definition at line 887 of file bio.c.
References GNUNET_BIO_read(), and h.
Referenced by GNUNET_BIO_read_spec_object().
|
static |
Function used internally to read a string from within a read spec.
cls | ignored, always NULL |
h | the IO handle to read from |
what | what is being read (for error message creation) |
target | where to store the data |
target_size | how many bytes to read |
Definition at line 933 of file bio.c.
References GNUNET_BIO_read_string(), h, result, GNUNET_BIO_ReadSpec::target, and GNUNET_BIO_ReadSpec::what.
Referenced by GNUNET_BIO_read_spec_string().
|
static |
Function used internally to read an (u)int32_t from within a read spec.
cls | ignored, always NULL |
h | the IO handle to read from |
what | what is being read (for error message creation) |
target | where to store the data |
target_size | ignored |
Definition at line 980 of file bio.c.
References GNUNET_BIO_read_int32(), h, result, GNUNET_BIO_ReadSpec::target, and GNUNET_BIO_ReadSpec::what.
Referenced by GNUNET_BIO_read_spec_float(), and GNUNET_BIO_read_spec_int32().
|
static |
Function used internally to read an (u)int64_t from within a read spec.
cls | ignored, always NULL |
h | the IO handle to read from |
what | what is being read (for error message creation) |
target | where to store the data |
target_size | ignored |
Definition at line 1024 of file bio.c.
References GNUNET_BIO_read_int64(), h, result, GNUNET_BIO_ReadSpec::target, and GNUNET_BIO_ReadSpec::what.
Referenced by GNUNET_BIO_read_spec_double(), and GNUNET_BIO_read_spec_int64().
|
static |
Function used internally to write some bytes from within a write spec.
cls | ignored, always NULL |
h | the IO handle to write to |
what | what is being written (for error message creation) |
source | the data to write |
source_size | how many bytes to write |
Definition at line 1133 of file bio.c.
References GNUNET_BIO_write(), h, source, and GNUNET_BIO_ReadSpec::what.
Referenced by GNUNET_BIO_write_spec_object().
|
static |
Function used internally to write a 0-terminated string from within a write spec.
cls | ignored, always NULL |
h | the IO handle to write to |
what | what is being written (for error message creation) |
source | the data to write |
source_size | ignored |
Definition at line 1180 of file bio.c.
References GNUNET_BIO_write_string(), h, source, and GNUNET_BIO_WriteSpec::what.
Referenced by GNUNET_BIO_write_spec_string().
|
static |
Function used internally to write an (u)int32_t from within a write spec.
cls | ignored, always NULL |
h | the IO handle to write to |
what | what is being written (for error message creation) |
source | the data to write |
source_size | ignored |
Definition at line 1225 of file bio.c.
References GNUNET_BIO_write_int32(), h, source, and GNUNET_BIO_WriteSpec::what.
Referenced by GNUNET_BIO_write_spec_float(), and GNUNET_BIO_write_spec_int32().
|
static |
Function used internally to write an (u)int64_t from within a write spec.
cls | ignored, always NULL |
h | the IO handle to write to |
what | what is being written (for error message creation) |
source | the data to write |
source_size | ignored |
Definition at line 1270 of file bio.c.
References GNUNET_BIO_write_int64(), h, source, and GNUNET_BIO_WriteSpec::what.
Referenced by GNUNET_BIO_write_spec_double(), and GNUNET_BIO_write_spec_int64().