add/re-enable at_wini debug output
[minix3.git] / servers / inet / generic / buf.h
blob95c89351080b2b8c2642d2a4420d93a971966f9c
1 /*
2 buf.h
4 Copyright 1995 Philip Homburg
5 */
7 #ifndef BUF_H
8 #define BUF_H
10 /* Note: BUF_S should be defined in const.h */
12 #define MAX_BUFREQ_PRI 10
14 #define ARP_PRI_REC 3
15 #define ARP_PRI_SEND 3
17 #define ETH_PRI_PORTBUFS 3
18 #define ETH_PRI_FDBUFS_EXTRA 5
19 #define ETH_PRI_FDBUFS 6
21 #define IP_PRI_PORTBUFS 3
22 #define IP_PRI_ASSBUFS 4
23 #define IP_PRI_FDBUFS_EXTRA 5
24 #define IP_PRI_FDBUFS 6
26 #define ICMP_PRI_QUEUE 1
28 #define TCP_PRI_FRAG2SEND 4
29 #define TCP_PRI_CONN_EXTRA 5
30 #define TCP_PRI_CONNwoUSER 7
31 #define TCP_PRI_CONN_INUSE 9
33 #define UDP_PRI_FDBUFS_EXTRA 5
34 #define UDP_PRI_FDBUFS 6
36 #define PSIP_PRI_EXP_PROMISC 2
38 struct acc;
39 typedef void (*buffree_t) ARGS(( struct acc *acc ));
40 typedef void (*bf_freereq_t) ARGS(( int priority ));
42 #ifdef BUF_CONSISTENCY_CHECK
43 typedef void (*bf_checkreq_t) ARGS(( void ));
44 #endif
46 typedef struct buf
48 int buf_linkC;
49 buffree_t buf_free;
50 size_t buf_size;
51 char *buf_data_p;
53 #ifdef BUF_TRACK_ALLOC_FREE
54 char *buf_alloc_file;
55 int buf_alloc_line;
56 char *buf_free_file;
57 int buf_free_line;
58 #endif
59 #ifdef BUF_CONSISTENCY_CHECK
60 unsigned buf_generation;
61 int buf_check_linkC;
62 #endif
63 } buf_t;
65 typedef struct acc
67 int acc_linkC;
68 int acc_offset, acc_length;
69 buf_t *acc_buffer;
70 struct acc *acc_next, *acc_ext_link;
72 #ifdef BUF_TRACK_ALLOC_FREE
73 char *acc_alloc_file;
74 int acc_alloc_line;
75 char *acc_free_file;
76 int acc_free_line;
77 #endif
78 #ifdef BUF_CONSISTENCY_CHECK
79 unsigned acc_generation;
80 int acc_check_linkC;
81 #endif
82 } acc_t;
84 extern acc_t *bf_temporary_acc;
85 extern acc_t *bf_linkcheck_acc;
87 /* For debugging... */
89 #ifdef BUF_TRACK_ALLOC_FREE
91 #ifndef BUF_IMPLEMENTATION
93 #define bf_memreq(a) _bf_memreq(this_file, __LINE__, a)
94 #define bf_cut(a,b,c) _bf_cut(this_file, __LINE__, a, b, c)
95 #define bf_delhead(a,b) _bf_delhead(this_file, __LINE__, a, b)
96 #define bf_packIffLess(a,b) _bf_packIffLess(this_file, __LINE__, \
97 a, b)
98 #define bf_afree(a) _bf_afree(this_file, __LINE__, a)
99 #define bf_pack(a) _bf_pack(this_file, __LINE__, a)
100 #define bf_append(a,b) _bf_append(this_file, __LINE__, a, b)
101 #define bf_dupacc(a) _bf_dupacc(this_file, __LINE__, a)
102 #if 0
103 #define bf_mark_1acc(a) _bf_mark_1acc(this_file, __LINE__, a)
104 #define bf_mark_acc(a) _bf_mark_acc(this_file, __LINE__, a)
105 #endif
106 #define bf_align(a,s,al) _bf_align(this_file, __LINE__, a, s, al)
108 #else /* BUF_IMPLEMENTATION */
110 #define bf_afree(a) _bf_afree(clnt_file, clnt_line, a)
111 #define bf_pack(a) _bf_pack(clnt_file, clnt_line, a)
112 #define bf_memreq(a) _bf_memreq(clnt_file, clnt_line, a)
113 #define bf_dupacc(a) _bf_dupacc(clnt_file, clnt_line, a)
114 #define bf_cut(a,b,c) _bf_cut(clnt_file, clnt_line, a, b, c)
115 #define bf_delhead(a,b) _bf_delhead(clnt_file, clnt_line, a, b)
116 #define bf_align(a,s,al) _bf_align(clnt_file, clnt_line, a, s, al)
118 #endif /* !BUF_IMPLEMENTATION */
120 #else
122 #define bf_mark_1acc(acc) ((void)0)
123 #define bf_mark_acc(acc) ((void)0)
125 #endif /* BUF_TRACK_ALLOC_FREE */
127 /* Prototypes */
129 void bf_init ARGS(( void ));
130 #ifndef BUF_CONSISTENCY_CHECK
131 void bf_logon ARGS(( bf_freereq_t func ));
132 #else
133 void bf_logon ARGS(( bf_freereq_t func, bf_checkreq_t checkfunc ));
134 #endif
136 #ifndef BUF_TRACK_ALLOC_FREE
137 acc_t *bf_memreq ARGS(( unsigned size));
138 #else
139 acc_t *_bf_memreq ARGS(( char *clnt_file, int clnt_line,
140 unsigned size));
141 #endif
142 /* the result is an acc with linkC == 1 */
144 #ifndef BUF_TRACK_ALLOC_FREE
145 acc_t *bf_dupacc ARGS(( acc_t *acc ));
146 #else
147 acc_t *_bf_dupacc ARGS(( char *clnt_file, int clnt_line,
148 acc_t *acc ));
149 #endif
150 /* the result is an acc with linkC == 1 identical to the given one */
152 #ifndef BUF_TRACK_ALLOC_FREE
153 void bf_afree ARGS(( acc_t *acc));
154 #else
155 void _bf_afree ARGS(( char *clnt_file, int clnt_line,
156 acc_t *acc));
157 #endif
158 /* this reduces the linkC off the given acc with one */
160 #ifndef BUF_TRACK_ALLOC_FREE
161 acc_t *bf_pack ARGS(( acc_t *pack));
162 #else
163 acc_t *_bf_pack ARGS(( char *clnt_file, int clnt_line,
164 acc_t *pack));
165 #endif
166 /* this gives a packed copy of the given acc, the linkC of the given acc is
167 reduced by one, the linkC of the result == 1 */
169 #ifndef BUF_TRACK_ALLOC_FREE
170 acc_t *bf_packIffLess ARGS(( acc_t *pack, int min_len ));
171 #else
172 acc_t *_bf_packIffLess ARGS(( char *clnt_file, int clnt_line,
173 acc_t *pack, int min_len ));
174 #endif
175 /* this performs a bf_pack iff pack->acc_length<min_len */
177 size_t bf_bufsize ARGS(( acc_t *pack));
178 /* this gives the length of the buffer specified by the given acc. The linkC
179 of the given acc remains the same */
181 #ifndef BUF_TRACK_ALLOC_FREE
182 acc_t *bf_cut ARGS(( acc_t *data, unsigned offset, unsigned length ));
183 #else
184 acc_t *_bf_cut ARGS(( char *clnt_file, int clnt_line,
185 acc_t *data, unsigned offset, unsigned length ));
186 #endif
187 /* the result is a cut of the buffer from offset with length length.
188 The linkC of the result == 1, the linkC of the given acc remains the
189 same. */
191 #ifndef BUF_TRACK_ALLOC_FREE
192 acc_t *bf_delhead ARGS(( acc_t *data, unsigned offset ));
193 #else
194 acc_t *_bf_delhead ARGS(( char *clnt_file, int clnt_line,
195 acc_t *data, unsigned offset ));
196 #endif
197 /* the result is a cut of the buffer from offset until the end.
198 The linkC of the result == 1, the linkC of the given acc is
199 decremented. */
201 #ifndef BUF_TRACK_ALLOC_FREE
202 acc_t *bf_append ARGS(( acc_t *data_first, acc_t *data_second ));
203 #else
204 acc_t *_bf_append ARGS(( char *clnt_file, int clnt_line,
205 acc_t *data_first, acc_t *data_second ));
206 #endif
207 /* data_second is appended after data_first, a link is returned to the
208 result and the linkCs of data_first and data_second are reduced.
209 further more, if the contents of the last part of data_first and
210 the first part of data_second fit in a buffer, both parts are
211 copied into a (possibly fresh) buffer
214 #ifndef BUF_TRACK_ALLOC_FREE
215 acc_t *bf_align ARGS(( acc_t *acc, size_t size, size_t alignment ));
216 #else
217 acc_t *_bf_align ARGS(( char *clnt_file, int clnt_line,
218 acc_t *acc, size_t size, size_t alignment ));
219 #endif
220 /* size bytes of acc (or all bytes of acc if the size buffer is smaller
221 than size) are aligned on an address that is multiple of alignment.
222 Size must be less than or equal to BUF_S.
225 int bf_linkcheck ARGS(( acc_t *acc ));
226 /* check if all link count are positive, and offsets and sizes are within
227 * the underlying buffer.
230 #define ptr2acc_data(/* acc_t * */ a) (bf_temporary_acc=(a), \
231 (&bf_temporary_acc->acc_buffer->buf_data_p[bf_temporary_acc-> \
232 acc_offset]))
234 #define bf_chkbuf(buf) ((buf)? (compare((buf)->acc_linkC,>,0), \
235 compare((buf)->acc_buffer, !=, 0), \
236 compare((buf)->acc_buffer->buf_linkC,>,0)) : (void)0)
238 #ifdef BUF_CONSISTENCY_CHECK
239 int bf_consistency_check ARGS(( void ));
240 void bf_check_acc ARGS(( acc_t *acc ));
241 void _bf_mark_1acc ARGS(( char *clnt_file, int clnt_line, acc_t *acc ));
242 void _bf_mark_acc ARGS(( char *clnt_file, int clnt_line, acc_t *acc ));
243 #endif
245 #endif /* BUF_H */
248 * $PchId: buf.h,v 1.13 2003/09/10 08:52:09 philip Exp $