12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- // SPDX-License-Identifier: GPL-3.0-or-later
- // Copyright © 2018 Ariadne Devos
- /* shttpd -- circular character buffers */
- #ifndef _sHT_PAPER_H
- #define _sHT_PAPER_H
- #include <stdint.h>
- /* Text that is passed around and scribbled is called 'paper'. */
- /* According to https://stackoverflow.com/questions/42258274/
- should-i-send-data-in-chunks-or-send-it-all-at-once, the exact buffer size
- doesn't really matter. So choose a convenient, round number that allows for
- many concurrent connections. (Increase this value if performance tests tell
- you to do so.)
- This is guaranteed to be a power of 2, and a multiple of 1024. */
- #define sHT_PAPER_SIZE 4096
- #define sHT_PAPER_SIZE_MAX 4095
- /** A single unsigned octet, which may or may not represent a character. */
- typedef unsigned char sHT_octet;
- /** A single unsigned octet, which should not be interpreted as a character.
- (E.g. from most image formats). */
- typedef sHT_octet sHT_byte;
- /** A character (or possibly, part of a UTF-8 sequence), represented by
- an unsigned octet. */
- typedef sHT_octet sHT_char;
- typedef uint_least16_t sHT_size;
- typedef sHT_octet *sHT_paper;
- /* Stack */
- struct sHT_paper_mill
- {
- unsigned int capacity;
- unsigned int length;
- sHT_octet **first;
- };
- /* May return NULL (allocation failure). */
- __attribute__((warn_unused_result))
- __attribute__((nonnull (1)))
- sHT_paper
- sHT_alloc_paper(struct sHT_paper_mill *mill);
- /* Assumes mill->length != mill->capacity. Cannot fail. */
- __attribute__((nonnull (1, 2)))
- void
- sHT_free_paper(struct sHT_paper_mill *mill, sHT_paper p);
- struct sHT_buffer
- {
- sHT_paper first;
- sHT_size offset;
- sHT_size length;
- };
- #endif
|