Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / ntp / dist / include / recvbuff.h
blob17d7fc51fbba5f38bd07990ae30926abf6185594
1 /* $NetBSD$ */
3 #ifndef RECVBUFF_H
4 #define RECVBUFF_H
6 #ifdef HAVE_CONFIG_H
7 # include <config.h>
8 #endif
10 #include "ntp.h"
11 #include "ntp_fp.h"
12 #include "ntp_lists.h"
14 #include <isc/result.h>
17 * recvbuf memory management
19 #define RECV_INIT 10 /* 10 buffers initially */
20 #define RECV_LOWAT 3 /* when we're down to three buffers get more */
21 #define RECV_INC 5 /* get 5 more at a time */
22 #define RECV_TOOMANY 40 /* this is way too many buffers */
24 #if defined HAVE_IO_COMPLETION_PORT
25 # include "ntp_iocompletionport.h"
26 #include "ntp_timer.h"
28 # define RECV_BLOCK_IO() EnterCriticalSection(&RecvCritSection)
29 # define RECV_UNBLOCK_IO() LeaveCriticalSection(&RecvCritSection)
31 /* Return the event which is set when items are added to the full list
33 extern HANDLE get_recv_buff_event (void);
34 #else
35 # define RECV_BLOCK_IO()
36 # define RECV_UNBLOCK_IO()
37 #endif
41 * Format of a recvbuf. These are used by the asynchronous receive
42 * routine to store incoming packets and related information.
46 * the maximum length NTP packet contains the NTP header, one Autokey
47 * request, one Autokey response and the MAC. Assuming certificates don't
48 * get too big, the maximum packet length is set arbitrarily at 1000.
49 */
50 #define RX_BUFF_SIZE 1000 /* hail Mary */
53 typedef struct recvbuf recvbuf_t;
55 struct recvbuf {
56 ISC_LINK(recvbuf_t) link; /* next in list */
57 union {
58 sockaddr_u X_recv_srcadr;
59 caddr_t X_recv_srcclock;
60 struct peer *X_recv_peer;
61 } X_from_where;
62 #define recv_srcadr X_from_where.X_recv_srcadr
63 #define recv_srcclock X_from_where.X_recv_srcclock
64 #define recv_peer X_from_where.X_recv_peer
65 #ifndef HAVE_IO_COMPLETION_PORT
66 sockaddr_u srcadr; /* where packet came from */
67 #else
68 int recv_srcadr_len; /* filled in on completion */
69 #endif
70 struct interface *dstadr; /* interface datagram arrived thru */
71 SOCKET fd; /* fd on which it was received */
72 int msg_flags; /* Flags received about the packet */
73 l_fp recv_time; /* time of arrival */
74 void (*receiver) (struct recvbuf *); /* routine to receive buffer */
75 int recv_length; /* number of octets received */
76 union {
77 struct pkt X_recv_pkt;
78 u_char X_recv_buffer[RX_BUFF_SIZE];
79 } recv_space;
80 #define recv_pkt recv_space.X_recv_pkt
81 #define recv_buffer recv_space.X_recv_buffer
82 int used; /* reference count */
85 extern void init_recvbuff (int);
87 /* freerecvbuf - make a single recvbuf available for reuse
89 extern void freerecvbuf (struct recvbuf *);
91 /* Get a free buffer (typically used so an async
92 * read can directly place data into the buffer
94 * The buffer is removed from the free list. Make sure
95 * you put it back with freerecvbuf() or
97 extern struct recvbuf *get_free_recv_buffer (void); /* signal safe - no malloc */
98 extern struct recvbuf *get_free_recv_buffer_alloc (void); /* signal unsafe - may malloc */
100 /* Add a buffer to the full list
102 extern void add_full_recv_buffer (struct recvbuf *);
104 /*extern void process_recv_buffers (void); */
106 /* number of recvbufs on freelist */
107 extern u_long free_recvbuffs (void);
108 extern u_long full_recvbuffs (void);
109 extern u_long total_recvbuffs (void);
110 extern u_long lowater_additions (void);
112 /* Returns the next buffer in the full list.
115 extern struct recvbuf *get_full_recv_buffer (void);
118 * Checks to see if there are buffers to process
120 extern isc_boolean_t has_full_recv_buffer (void);
122 #endif /* RECVBUFF_H */