6 #include "ntp_machine.h"
8 #include "ntp_syslog.h"
9 #include "ntp_stdlib.h"
17 static u_long volatile full_recvbufs; /* number of recvbufs on fulllist */
18 static u_long volatile free_recvbufs; /* number of recvbufs on freelist */
19 static u_long volatile total_recvbufs; /* total recvbufs currently in use */
20 static u_long volatile lowater_adds; /* number of times we have added memory */
22 static struct recvbuf *volatile freelist; /* free buffers */
23 static struct recvbuf *volatile fulllist; /* lifo buffers with data */
24 static struct recvbuf *volatile beginlist; /* fifo buffers with data */
26 #if defined(HAVE_IO_COMPLETION_PORT)
27 static CRITICAL_SECTION RecvCritSection;
28 # define RECV_BLOCK_IO() EnterCriticalSection(&RecvCritSection)
29 # define RECV_UNBLOCK_IO() LeaveCriticalSection(&RecvCritSection)
31 # define RECV_BLOCK_IO()
32 # define RECV_UNBLOCK_IO()
48 total_recvbuffs (void)
54 lowater_additions(void)
60 initialise_buffer(struct recvbuf *buff)
62 memset((char *) buff, 0, sizeof(struct recvbuf));
64 #if defined HAVE_IO_COMPLETION_PORT
65 buff->iocompletioninfo.overlapped.hEvent = CreateEvent(NULL, FALSE,FALSE, NULL);
66 buff->wsabuff.len = RX_BUFF_SIZE;
67 buff->wsabuff.buf = (char *) buff->recv_buffer;
74 register struct recvbuf *buf;
76 buf = (struct recvbuf *)
77 emalloc(RECV_INC*sizeof(struct recvbuf));
78 for (i = 0; i < RECV_INC; i++)
80 initialise_buffer(buf);
81 buf->next = (struct recvbuf *) freelist;
86 free_recvbufs += RECV_INC;
87 total_recvbufs += RECV_INC;
92 init_recvbuff(int nbufs)
94 register struct recvbuf *buf;
98 * Init buffer free list and stat counters
102 buf = (struct recvbuf *)
103 emalloc(nbufs*sizeof(struct recvbuf));
104 for (i = 0; i < nbufs; i++)
106 initialise_buffer(buf);
107 buf->next = (struct recvbuf *) freelist;
113 free_recvbufs = total_recvbufs = nbufs;
114 full_recvbufs = lowater_adds = 0;
116 #if defined(HAVE_IO_COMPLETION_PORT)
117 InitializeCriticalSection(&RecvCritSection);
124 * getrecvbufs - get receive buffers which have data in them
132 struct recvbuf *rb = NULL; /* nothing has arrived */;
135 if (full_recvbufs == 0)
139 printf("getrecvbufs called, no action here\n");
145 * Get the fulllist chain and mark it empty
149 printf("getrecvbufs returning %ld buffers\n", full_recvbufs);
156 * Check to see if we're below the low water mark.
158 if (free_recvbufs <= RECV_LOWAT)
160 if (total_recvbufs >= RECV_TOOMANY)
161 msyslog(LOG_ERR, "too many recvbufs allocated (%ld)",
178 * freerecvbuf - make a single recvbuf available for reuse
187 rb->next = (struct recvbuf *) freelist;
196 add_full_recv_buffer(
201 if (full_recvbufs == 0)
208 rb->next = fulllist->next;
218 get_free_recv_buffer(void)
220 struct recvbuf * buffer = NULL;
222 if (free_recvbufs <= RECV_LOWAT)
224 if (total_recvbufs >= RECV_TOOMANY) {
225 msyslog(LOG_ERR, "too many recvbufs allocated (%ld)",
234 if (free_recvbufs > 0)
237 freelist = buffer->next;
247 get_full_recv_buffer(void)
249 struct recvbuf * buffer = NULL;
251 if (full_recvbufs > 0) {
254 beginlist = buffer->next;