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;
94 void cmsg_send(reft *base, cmsg_t *mp, void (*callback)())
97 mp->size = mp->inp - mp->data; /* calc the real size */
98 mp->callback = callback; /* store the reply address */
99 chain_insert(base, mp);
105 void cmsg_priority_send(reft *base, cmsg_t *mp, void (*callback)())
108 mp->size = mp->inp - mp->data; /* calc the real size */
109 mp->callback = callback; /* store the reply address */
117 * get the next cmsg (from the front), this removes the message from the chain
120 cmsg_t *cmsg_next(reft *base)
122 cmsg_t *mp = chain_get_next(base, 0);
132 * get the prev cmsg (from the back), this removes the message from the chain
135 cmsg_t *cmsg_prev(reft *base)
137 cmsg_t *mp = chain_get_prev(base, 0);
146 void cmsg_callback(cmsg_t *m, int reply)
149 (m->callback)(m, reply);
153 void cmsg_free(cmsg_t *m)
157 if (m->sort > MAXSORT)
159 ++stats[m->sort].free;
165 void cmsg_flush(reft *base, int reply)
169 while (m = cmsg_next(base)) {
170 cmsg_callback(m, reply);
180 * Revision 1.2 2000-07-20 14:16:00 minima
181 * can use Sourceforge now!
182 * added user->qra cleaning
183 * added 4 digit qra to user broadcast dxspots if available
185 * Revision 1.1 2000/03/26 00:03:30 djk
186 * first cut of client
188 * Revision 1.12 1998/05/05 14:01:27 djk
189 * Tidied up various global variables in the hope that there is likely
190 * to be less undefined interaction between modules.
191 * Added some extra LINUX debugging to check for possible cmsg memory leaks.
193 * Revision 1.11 1998/01/02 19:39:58 djk
194 * made various changes to cope with glibc
195 * fixed problem with extended status in etsi_router
197 * Revision 1.10 1997/06/13 16:51:17 djk
198 * fixed various library problems
199 * got the taipstack and hayes to the point of half duplex reliability
200 * hayes now successfully communicates with taiptest and has part of the
201 * command level taip stuff in.
203 * Revision 1.9 1997/05/20 20:45:14 djk
204 * The 1.22 version more or less unchanged
206 * Revision 1.8 1997/03/25 18:12:55 djk
209 * Revision 1.7 1997/03/19 09:57:28 djk
210 * added a count to check for leaks
212 * Revision 1.6 1997/02/13 17:02:04 djk
215 * Revision 1.5 1997/02/04 17:47:04 djk
216 * brought into line with public2
218 * Revision 1.4 1997/02/04 01:27:37 djk
219 * altered size semantics on create (size now = 0 not creation size)
221 * Revision 1.3 1997/01/20 22:29:27 djk
224 * Revision 1.2 1997/01/13 23:34:29 djk
225 * The first working test version of smsd
227 * Revision 1.1 1997/01/03 23:42:21 djk
228 * added a general message handling module (still developing)
229 * added parity handling to ser.c