41 lines
1.7 KiB
C
41 lines
1.7 KiB
C
/* ************************************************************************** */
|
|
/* _____ _ */
|
|
/* libg1m/buffer.h |_ _|__ _ _| |__ ___ _ _ */
|
|
/* | Project: libg1m | |/ _ \| | | | '_ \ / _ \ | | | */
|
|
/* | | (_) | |_| | | | | __/ |_| | */
|
|
/* By: thomas <thomas@touhey.fr> |_|\___/ \__,_|_| |_|\___|\__, |.fr */
|
|
/* Last updated: 2017/02/12 16:04:33 |___/ */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
#ifndef LIBG1M_BUFFER_H
|
|
# define LIBG1M_BUFFER_H
|
|
# include <stdlib.h>
|
|
# include <stdint.h>
|
|
|
|
/* This file is there so it is possible to use a custom buffer for file
|
|
* transferring. There are two use cases:
|
|
* - if you use a buffer to send data: the size of the element to send should
|
|
* be put in `size`, and the `read` function will be used;
|
|
* - if you use a buffer to receive data: if the `announce` function is set,
|
|
* it will be called with the size of the file to receive, in order to
|
|
* prepare space for the file. If the announce function returns an error,
|
|
* then the file will not be sent.
|
|
*
|
|
* Here are the used functions: */
|
|
|
|
typedef int (*g1m_buffer_read_t)(void*, unsigned char*, size_t);
|
|
typedef int (*g1m_buffer_write_t)(void*, const unsigned char*, size_t);
|
|
typedef int (*g1m_buffer_announce_t)(void*, uint_fast32_t size);
|
|
|
|
/* And here is the structure of a buffer: */
|
|
|
|
typedef struct {
|
|
void *cookie;
|
|
|
|
g1m_buffer_read_t read;
|
|
g1m_buffer_write_t write;
|
|
g1m_buffer_announce_t announce;
|
|
} g1m_buffer_t;
|
|
|
|
#endif /* LIBG1M_BUFFER_H */
|