source: trunk/minix/servers/inet/generic/buf.h@ 20

Last change on this file since 20 was 9, checked in by Mattia Monga, 14 years ago

Minix 3.1.2a

File size: 6.7 KB
Line 
1/*
2buf.h
3
4Copyright 1995 Philip Homburg
5*/
6
7#ifndef BUF_H
8#define BUF_H
9
10/* Note: BUF_S should be defined in const.h */
11
12#define MAX_BUFREQ_PRI 10
13
14#define ARP_PRI_REC 3
15#define ARP_PRI_SEND 3
16
17#define ETH_PRI_PORTBUFS 3
18#define ETH_PRI_FDBUFS_EXTRA 5
19#define ETH_PRI_FDBUFS 6
20
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
25
26#define ICMP_PRI_QUEUE 1
27
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
32
33#define UDP_PRI_FDBUFS_EXTRA 5
34#define UDP_PRI_FDBUFS 6
35
36#define PSIP_PRI_EXP_PROMISC 2
37
38struct acc;
39typedef void (*buffree_t) ARGS(( struct acc *acc ));
40typedef void (*bf_freereq_t) ARGS(( int priority ));
41
42#ifdef BUF_CONSISTENCY_CHECK
43typedef void (*bf_checkreq_t) ARGS(( void ));
44#endif
45
46typedef struct buf
47{
48 int buf_linkC;
49 buffree_t buf_free;
50 size_t buf_size;
51 char *buf_data_p;
52
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;
64
65typedef struct acc
66{
67 int acc_linkC;
68 int acc_offset, acc_length;
69 buf_t *acc_buffer;
70 struct acc *acc_next, *acc_ext_link;
71
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;
83
84extern acc_t *bf_temporary_acc;
85extern acc_t *bf_linkcheck_acc;
86
87/* For debugging... */
88
89#ifdef BUF_TRACK_ALLOC_FREE
90
91#ifndef BUF_IMPLEMENTATION
92
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)
107
108#else /* BUF_IMPLEMENTATION */
109
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)
117
118#endif /* !BUF_IMPLEMENTATION */
119
120#else
121
122#define bf_mark_1acc(acc) ((void)0)
123#define bf_mark_acc(acc) ((void)0)
124
125#endif /* BUF_TRACK_ALLOC_FREE */
126
127/* Prototypes */
128
129void bf_init ARGS(( void ));
130#ifndef BUF_CONSISTENCY_CHECK
131void bf_logon ARGS(( bf_freereq_t func ));
132#else
133void bf_logon ARGS(( bf_freereq_t func, bf_checkreq_t checkfunc ));
134#endif
135
136#ifndef BUF_TRACK_ALLOC_FREE
137acc_t *bf_memreq ARGS(( unsigned size));
138#else
139acc_t *_bf_memreq ARGS(( char *clnt_file, int clnt_line,
140 unsigned size));
141#endif
142/* the result is an acc with linkC == 1 */
143
144#ifndef BUF_TRACK_ALLOC_FREE
145acc_t *bf_dupacc ARGS(( acc_t *acc ));
146#else
147acc_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 */
151
152#ifndef BUF_TRACK_ALLOC_FREE
153void bf_afree ARGS(( acc_t *acc));
154#else
155void _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 */
159
160#ifndef BUF_TRACK_ALLOC_FREE
161acc_t *bf_pack ARGS(( acc_t *pack));
162#else
163acc_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 */
168
169#ifndef BUF_TRACK_ALLOC_FREE
170acc_t *bf_packIffLess ARGS(( acc_t *pack, int min_len ));
171#else
172acc_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 */
176
177size_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 */
180
181#ifndef BUF_TRACK_ALLOC_FREE
182acc_t *bf_cut ARGS(( acc_t *data, unsigned offset, unsigned length ));
183#else
184acc_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. */
190
191#ifndef BUF_TRACK_ALLOC_FREE
192acc_t *bf_delhead ARGS(( acc_t *data, unsigned offset ));
193#else
194acc_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. */
200
201#ifndef BUF_TRACK_ALLOC_FREE
202acc_t *bf_append ARGS(( acc_t *data_first, acc_t *data_second ));
203#else
204acc_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
212*/
213
214#ifndef BUF_TRACK_ALLOC_FREE
215acc_t *bf_align ARGS(( acc_t *acc, size_t size, size_t alignment ));
216#else
217acc_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.
223*/
224
225int bf_linkcheck ARGS(( acc_t *acc ));
226/* check if all link count are positive, and offsets and sizes are within
227 * the underlying buffer.
228 */
229
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]))
233
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)
237
238#ifdef BUF_CONSISTENCY_CHECK
239int bf_consistency_check ARGS(( void ));
240void bf_check_acc ARGS(( acc_t *acc ));
241void _bf_mark_1acc ARGS(( char *clnt_file, int clnt_line, acc_t *acc ));
242void _bf_mark_acc ARGS(( char *clnt_file, int clnt_line, acc_t *acc ));
243#endif
244
245#endif /* BUF_H */
246
247/*
248 * $PchId: buf.h,v 1.13 2003/09/10 08:52:09 philip Exp $
249 */
Note: See TracBrowser for help on using the repository browser.