1 |
/* |
/* |
2 |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
* ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd). |
|
* dbuf.h: A header for the dynamic buffers functions. |
|
3 |
* |
* |
4 |
* Copyright (C) 2002 by the past and present ircd coders, and others. |
* Copyright (C) 1990 Markku Savela |
5 |
|
* Copyright (C) 2013 by the Hybrid Development Team. |
6 |
* |
* |
7 |
* This program is free software; you can redistribute it and/or modify |
* This program is free software; you can redistribute it and/or modify |
8 |
* it under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
18 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
20 |
* USA |
* USA |
|
* |
|
|
* $Id$ |
|
21 |
*/ |
*/ |
22 |
|
|
23 |
#ifndef __DBUF_H_INCLUDED |
/*! \file dbuf.h |
24 |
#define __DBUF_H_INCLUDED |
* \brief Interfaces and declarations for dealing with data buffers. |
25 |
|
* \version $Id$ |
26 |
|
*/ |
27 |
|
|
28 |
#define DBUF_BLOCK_SIZE 1024 /* this is also our MTU used for sending */ |
#ifndef INCLUDED_dbuf_h |
29 |
|
#define INCLUDED_dbuf_h |
30 |
|
#ifndef INCLUDED_sys_types_h |
31 |
|
#include <sys/types.h> /* size_t */ |
32 |
|
#define INCLUDED_sys_types_h |
33 |
|
#endif |
34 |
|
|
35 |
#define dbuf_length(x) ((x)->total_size) |
/* |
36 |
#define dbuf_clear(x) dbuf_delete(x, dbuf_length(x)) |
* These two globals should be considered read only |
37 |
|
*/ |
38 |
|
extern int DBufAllocCount; |
39 |
|
extern int DBufUsedCount; |
40 |
|
|
41 |
struct dbuf_block |
struct DBufBuffer; |
|
{ |
|
|
size_t size; |
|
|
char data[DBUF_BLOCK_SIZE]; |
|
|
}; |
|
42 |
|
|
43 |
struct dbuf_queue |
/** Queue of data chunks. */ |
44 |
|
struct DBuf |
45 |
{ |
{ |
46 |
dlink_list blocks; |
unsigned int length; /**< Current number of bytes stored */ |
47 |
size_t total_size; |
struct DBufBuffer *head; /**< First data buffer, if length > 0 */ |
48 |
|
struct DBufBuffer *tail; /**< Last data buffer, if length > 0 */ |
49 |
}; |
}; |
50 |
|
|
51 |
extern void dbuf_init(void); |
/** Return number of bytes in a DBuf. */ |
52 |
extern void dbuf_put(struct dbuf_queue *, char *, size_t); |
#define DBufLength(dyn) ((dyn)->length) |
53 |
extern void dbuf_delete(struct dbuf_queue *, size_t); |
|
54 |
#endif |
/** Release the entire content of a DBuf. */ |
55 |
|
#define DBufClear(dyn) dbuf_delete((dyn), DBufLength(dyn)) |
56 |
|
|
57 |
|
/* |
58 |
|
* Prototypes |
59 |
|
*/ |
60 |
|
extern void dbuf_delete(struct DBuf *, unsigned int); |
61 |
|
extern int dbuf_put(struct DBuf *, const char *, unsigned int); |
62 |
|
extern const char *dbuf_map(const struct DBuf *, unsigned int *); |
63 |
|
extern unsigned int dbuf_get(struct DBuf *, char *, unsigned int); |
64 |
|
extern unsigned int dbuf_getmsg(struct DBuf *, char *, unsigned int); |
65 |
|
extern void dbuf_count_memory(size_t *, size_t *); |
66 |
|
#endif /* INCLUDED_dbuf_h */ |