54 lines
854 B
C
54 lines
854 B
C
#ifndef __HALO_INCLUDE_RING_
|
|
#define __HALO_INCLUDE_RING_
|
|
|
|
#include <stddef.h>
|
|
|
|
/*
|
|
* circular ring buffer for continous reading and writing
|
|
*/
|
|
|
|
struct ring_t {
|
|
/*
|
|
* the current length of the unread data in the buffer
|
|
*/
|
|
|
|
size_t buflen;
|
|
|
|
/*
|
|
* the full buffer
|
|
*/
|
|
|
|
char *buffer;
|
|
|
|
/*
|
|
* the beginning of the full buffer
|
|
*/
|
|
|
|
char *begin;
|
|
|
|
/*
|
|
* the ending of the full buffer
|
|
*/
|
|
|
|
char *end;
|
|
|
|
/*
|
|
* the beginning of the unread data in the buffer
|
|
*/
|
|
|
|
char *reader;
|
|
|
|
/*
|
|
* the end of the unread data in the buffer
|
|
*/
|
|
|
|
char *writer;
|
|
};
|
|
|
|
struct ring_t *ring_new(struct ring_t *buf, size_t len);
|
|
size_t ring_write(struct ring_t *buf, char *str, size_t orig_len);
|
|
char *ring_read(struct ring_t *buf, size_t *len);
|
|
char *ring_readln(struct ring_t *buf, size_t *len);
|
|
void ring_del(struct ring_t *buf);
|
|
|
|
#endif
|