4 * create and free message buffers
6 * Copyright 1996 (c) D-J Koopman
12 static char rcsid[] = "$Id$";
29 #define FN "msg_stats"
42 if (systime - t > INTERVAL) {
43 FILE *f = fopen(FN, "w");
47 fprintf(f, "\nMSG STATISTICS\n");
48 fprintf(f, "==============\n\n");
49 fprintf(f, "cmsg_count = %ld\n\n", cmsg_count);
50 for (i = 0; i < MAXSORT+1; ++i) {
51 if (stats[i].new == 0 && stats[i].free == 0)
53 fprintf(f, "%d new: %ld free: %ld outstanding: %ld\n", i, stats[i].new, stats[i].free, stats[i].new-stats[i].free);
56 fprintf(f, "\nmalloc total arena used: %ld used: %ld free: %ld\n\n", m.arena, m.uordblks, m.fordblks);
63 void cmsg_clear_stats()
65 memset(stats, 0, sizeof stats);
71 cmsg_t *cmsg_new(int size, int sort, void *pp)
75 mp = malloc(sizeof(cmsg_t) + size);
77 die("no room in cmsg_new");
79 mp->sort = sort & CMSG_SORTMASK;
81 mp->state = mp->reply = 0;
95 void cmsg_send(reft *base, cmsg_t *mp, void (*callback)())
98 mp->size = mp->inp - mp->data; /* calc the real size */
99 mp->callback = callback; /* store the reply address */
100 chain_insert(base, mp);
106 void cmsg_priority_send(reft *base, cmsg_t *mp, void (*callback)())
109 mp->size = mp->inp - mp->data; /* calc the real size */
110 mp->callback = callback; /* store the reply address */
118 * get the next cmsg (from the front), this removes the message from the chain
121 cmsg_t *cmsg_next(reft *base)
123 cmsg_t *mp = chain_get_next(base, 0);
133 * get the prev cmsg (from the back), this removes the message from the chain
136 cmsg_t *cmsg_prev(reft *base)
138 cmsg_t *mp = chain_get_prev(base, 0);
147 void cmsg_callback(cmsg_t *m, int reply)
150 (m->callback)(m, reply);
154 void cmsg_free(cmsg_t *m)
158 if (m->sort > MAXSORT)
160 ++stats[m->sort].free;
166 void cmsg_flush(reft *base, int reply)
170 while (m = cmsg_next(base)) {
171 cmsg_callback(m, reply);
181 * Revision 1.3 2000-10-29 11:00:07 minima
182 * added echo cancelling
183 * started new filter code, objectifyed old filter code
185 * Revision 1.2 2000/07/20 14:16:00 minima
186 * can use Sourceforge now!
187 * added user->qra cleaning
188 * added 4 digit qra to user broadcast dxspots if available
190 * Revision 1.1 2000/03/26 00:03:30 djk
191 * first cut of client
193 * Revision 1.12 1998/05/05 14:01:27 djk
194 * Tidied up various global variables in the hope that there is likely
195 * to be less undefined interaction between modules.
196 * Added some extra LINUX debugging to check for possible cmsg memory leaks.
198 * Revision 1.11 1998/01/02 19:39:58 djk
199 * made various changes to cope with glibc
200 * fixed problem with extended status in etsi_router
202 * Revision 1.10 1997/06/13 16:51:17 djk
203 * fixed various library problems
204 * got the taipstack and hayes to the point of half duplex reliability
205 * hayes now successfully communicates with taiptest and has part of the
206 * command level taip stuff in.
208 * Revision 1.9 1997/05/20 20:45:14 djk
209 * The 1.22 version more or less unchanged
211 * Revision 1.8 1997/03/25 18:12:55 djk
214 * Revision 1.7 1997/03/19 09:57:28 djk
215 * added a count to check for leaks
217 * Revision 1.6 1997/02/13 17:02:04 djk
220 * Revision 1.5 1997/02/04 17:47:04 djk
221 * brought into line with public2
223 * Revision 1.4 1997/02/04 01:27:37 djk
224 * altered size semantics on create (size now = 0 not creation size)
226 * Revision 1.3 1997/01/20 22:29:27 djk
229 * Revision 1.2 1997/01/13 23:34:29 djk
230 * The first working test version of smsd
232 * Revision 1.1 1997/01/03 23:42:21 djk
233 * added a general message handling module (still developing)
234 * added parity handling to ser.c