cake
/
libp7
Archived
1
0
Fork 1
This repository has been archived on 2024-03-16. You can view files and clone it, but cannot push or open issues or pull requests.
libp7/include/libp7/buffer.h

55 lines
2.3 KiB
C

/* *****************************************************************************
* libp7/buffer.h -- the libp7 buffer interface.
* Copyright (C) 2016-2017 Thomas "Cakeisalie5" Touhey <thomas@touhey.fr>
*
* This file is part of libp7.
* libp7 is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3.0 of the License,
* or (at your option) any later version.
*
* libp7 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with libp7; if not, see <http://www.gnu.org/licenses/>.
*
* The libp7 buffer interface is an abstraction layer between libp7 and files
* or data on disk in general.
* ************************************************************************** */
#ifndef LIBP7_BUFFER_H
# define LIBP7_BUFFER_H
# include <libp7/types.h>
/* This interface is there so you can use a custom buffer for file/data
* transferring. There are two use cases:
* - you want to send data: the `size` of the element to send should be set,
* and the `read` callback will be used;
* - you want to receive data: if the `announce` callback 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` callback returns an error, then the file
* will not be received. If the announcement is successful, then the
* `write` callback is used.
*
* In each case, the `cookie` is sent as a first argument to your callbacks.
* Here are the prototypes your callbacks must have: */
typedef int p7_buffer_read_t(void*, unsigned char*, size_t);
typedef int p7_buffer_write_t(void*, const unsigned char*, size_t);
typedef int p7_buffer_announce_t(void*, p7uint_t);
/* And here's the buffer structure, using everything given above: */
typedef struct p7_buffer_s {
void *p7_buffer_cookie;
p7uint_t p7_buffer_size;
p7_buffer_read_t *p7_buffer_read;
p7_buffer_write_t *p7_buffer_write;
p7_buffer_announce_t *p7_buffer_announce;
} p7_buffer_t;
#endif /* LIBP7_BUFFER_H */