b7b5535dd5e93ab05d8a193fc75e590500f33bcd
[ircu2.10.12-pk.git] / include / msgq.h
1 #ifndef INCLUDED_msgq_h
2 #define INCLUDED_msgq_h
3 /*
4  * IRC - Internet Relay Chat, include/msgq.h
5  * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
6  *
7  * 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
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  *
21  * $Id$
22  */
23 #ifndef INCLUDED_ircd_defs_h
24 #include "ircd_defs.h"  /* BUFSIZE */
25 #endif
26 #ifndef INCLUDED_sys_types_h
27 #include <sys/types.h>
28 #define INCLUDED_sys_types_h
29 #endif
30 #ifndef INCLUDED_stdarg_h
31 #include <stdarg.h>
32 #define INCLUDED_stdarg_h
33 #endif
34
35 struct iovec;
36
37 struct Client;
38 struct StatDesc;
39
40 struct MsgCounts {
41   int alloc;
42   int used;
43 };
44
45 /*
46  * These should be considered read-only
47  */
48 extern struct MsgCounts msgBufCounts;   /* resource count for struct MsgBuf */
49 extern struct MsgCounts msgCounts;      /* resource count for struct Msg */
50
51 struct Msg;
52 struct MsgBuf;
53
54 struct MsgQList {
55   struct Msg *head;             /* First Msg in queue list */
56   struct Msg *tail;             /* Last Msg in queue list */
57 };
58
59 struct MsgQ {
60   unsigned int length;          /* Current number of bytes stored */
61   unsigned int count;           /* Current number of messages stored */
62   struct MsgQList queue;        /* Normal Msg queue */
63   struct MsgQList prio;         /* Priority Msg queue */
64 };
65
66 /*
67  * MsgQLength - Returns the current number of bytes stored in the buffer.
68  */
69 #define MsgQLength(mq) ((mq)->length)
70
71 /*
72  * MsgQCount - Returns the current number of messages stored in the buffer
73  */
74 #define MsgQCount(mq) ((mq)->count)
75
76 /*
77  * MsgQClear - Scratch the current content of the buffer.
78  * Release all allocated buffers and make it empty.
79  */
80 #define MsgQClear(mq) msgq_delete((mq), MsgQLength(mq))
81
82 /*
83  * Prototypes
84  */
85 extern void msgq_init(struct MsgQ *mq);
86 extern void msgq_delete(struct MsgQ *mq, unsigned int length);
87 extern int msgq_mapiov(const struct MsgQ *mq, struct iovec *iov, int count,
88                        unsigned int *len);
89 extern struct MsgBuf *msgq_make(struct Client *dest, const char *format, ...);
90 extern struct MsgBuf *msgq_vmake(struct Client *dest, const char *format,
91                                  va_list args);
92 extern void msgq_append(struct Client *dest, struct MsgBuf *mb,
93                         const char *format, ...);
94 extern void msgq_clean(struct MsgBuf *mb);
95 extern void msgq_add(struct MsgQ *mq, struct MsgBuf *mb, int prio);
96 extern void msgq_count_memory(struct Client *cptr,
97                               size_t *msg_alloc, size_t *msg_used);
98 extern void msgq_histogram(struct Client *cptr, struct StatDesc *sd, int stat,
99                            char *param);
100 extern unsigned int msgq_bufleft(struct MsgBuf *mb);
101
102 #endif /* INCLUDED_msgq_h */