libp7/doc/p7_buffer.3.txt

84 lines
1.9 KiB
Plaintext

P7_BUFFER(3)
============
Thomas "Cakeisalie5" Touhey
:Email: thomas@touhey.fr
:man source: libp7
:man manual: libp7 manual
NAME
----
p7_buffer - the libp7 buffer interface
SYNOPSIS
--------
[source,c]
----
#include <libp7.h>
p7_buffer_t buffer = {
.cookie = MY_COOKIE,
.size = MY_SIZE,
.read = MY_READ_CALLBACK
};
int err = p7_request(handle, &buffer, "dir", "file.ext", "fls0", NULL);
----
DESCRIPTION
-----------
The buffer interface replaces the *FILE* interface that was there before when
it came to exchange lots of data, generally related to file exchanges or
software components backup.
Here is the structure of the libp7 buffer:
[source,c]
----
typedef struct {
void *cookie;
p7uint_t size;
p7_buffer_read_t read;
p7_buffer_write_t write;
p7_buffer_announce_t announce;
} p7_buffer_t;
----
The *cookie* is the pointer that will be sent to your callbacks - use this, or
not, at all times. For the other parts, the interesting members of this
structure depends on what it is used for:
* *You want to get data.* Then you want to set the *write* member, which will be
the callback used for writing data to the buffer. Here is its prototype:
[source,c]
----
int my_buffer_write(void *cookie,
const unsigned char *data, size_t size);
----
If creating a file requires some preparation, you can use the *announce*
function (optional). If set, it will be called before the writes with the
file size. Here is its prototype:
[source,c]
----
int my_buffer_announce(void *cookie, p7uint_t filesize);
----
* *You want to send data.* Then you want to set the *size*, which will be the
filesize in bytes. You will also want to set the *read* member, which is the
function to read from the buffer. Here is its prototype:
[source,c]
----
int my_buffer_read(void *cookie,
unsigned char *dest, size_t size);
----
Notice that all of the callbacks return the libp7 error in case of error.
SEE ALSO
--------
*libp7*(3),
*p7_error*(3)