From: Frank Kardel Date: Sun, 17 Feb 2008 07:31:29 +0000 (+0000) Subject: recvbuff.c, recvbuff.h, ntp_io.c, ChangeLog: X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=58f4e642d61870f4d13b5264104a97d9e203389d;p=thirdparty%2Fntp.git recvbuff.c, recvbuff.h, ntp_io.c, ChangeLog: Bug 1000: Potentially insufficient number of receive buffers at startup bk: 47b7e2d1NrDhKFJTAI5thhil8SEErQ --- diff --git a/ChangeLog b/ChangeLog index c57ac210b0..5200f65d41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +* [Bug 1000] allow implicit receive buffer allocation for Windows + fixes startup for windows systems with many interfaces + reduces dropped packets on network bursts --- (4.2.4p4) Released by Harlan Stenn diff --git a/include/recvbuff.h b/include/recvbuff.h index 5feadc975b..771b90b94a 100644 --- a/include/recvbuff.h +++ b/include/recvbuff.h @@ -94,7 +94,8 @@ extern void freerecvbuf P((struct recvbuf *)); * The buffer is removed from the free list. Make sure * you put it back with freerecvbuf() or */ -extern struct recvbuf *get_free_recv_buffer P((void)); +extern struct recvbuf *get_free_recv_buffer P((void)); /* signal safe - no malloc */ +extern struct recvbuf *get_free_recv_buffer_alloc P((void)); /* signal unsafe - may malloc */ /* Add a buffer to the full list */ diff --git a/libntp/recvbuff.c b/libntp/recvbuff.c index 9511c8fe50..037d50e0e2 100644 --- a/libntp/recvbuff.c +++ b/libntp/recvbuff.c @@ -19,7 +19,8 @@ static u_long volatile full_recvbufs; /* number of recvbufs on fulllist */ static u_long volatile free_recvbufs; /* number of recvbufs on freelist */ static u_long volatile total_recvbufs; /* total recvbufs currently in use */ static u_long volatile lowater_adds; /* number of times we have added memory */ - +static u_long volatile buffer_shortfall;/* number of missed free receive buffers + between replenishments */ static ISC_LIST(recvbuf_t) full_recv_list; /* Currently used recv buffers */ static ISC_LIST(recvbuf_t) free_recv_list; /* Currently unused buffers */ @@ -74,19 +75,25 @@ initialise_buffer(recvbuf_t *buff) #endif } -static int +static void create_buffers(int nbufs) { register recvbuf_t *bufp; - int i; + int i, abuf; + + abuf = nbufs + buffer_shortfall; + buffer_shortfall = 0; - bufp = (recvbuf_t *) emalloc(nbufs*sizeof(recvbuf_t)); + bufp = (recvbuf_t *) emalloc(abuf*sizeof(recvbuf_t)); /* * If no memory available, Bail */ if (bufp == NULL) - return (0); - for (i = 0; i < nbufs; i++) + { + msyslog(LOG_ERR, "no more memory for receive buffers"); + } + + for (i = 0; i < abuf; i++) { memset((char *) bufp, 0, sizeof(recvbuf_t)); ISC_LIST_APPEND(free_recv_list, bufp, link); @@ -95,7 +102,6 @@ create_buffers(int nbufs) total_recvbufs++; } lowater_adds++; - return (nbufs); } void @@ -169,10 +175,26 @@ get_free_recv_buffer(void) initialise_buffer(buffer); (buffer->used)++; } + else + { + buffer_shortfall++; + } UNLOCK(); return (buffer); } +recvbuf_t * +get_free_recv_buffer_alloc(void) +{ + recvbuf_t * buffer = get_free_recv_buffer(); + if (buffer != NULL) + { + create_buffers(RECV_INC); + buffer = get_free_recv_buffer(); + } + return (buffer); +} + recvbuf_t * get_full_recv_buffer(void) { @@ -192,10 +214,7 @@ get_full_recv_buffer(void) /* * try to get us some more buffers */ - if (create_buffers(RECV_INC) <= 0) - { - msyslog(LOG_ERR, "No more memory for recvufs"); - } + create_buffers(RECV_INC); } /* diff --git a/ntpd/ntp_io.c b/ntpd/ntp_io.c index ae0208ae18..8ad84f7524 100644 --- a/ntpd/ntp_io.c +++ b/ntpd/ntp_io.c @@ -479,7 +479,7 @@ init_io(void) #ifdef SYS_WINNT if (!Win32InitSockets()) { - netsyslog(LOG_ERR, "No useable winsock.dll: %m"); +netsyslog(LOG_ERR, "No useable winsock.dll: %m"); exit(1); } init_transmitbuff(); @@ -2451,7 +2451,11 @@ open_socket( /* * Add the socket to the completion port */ - io_completion_port_add_socket(fd, interf); + if (io_completion_port_add_socket(fd, interf)) + { + msyslog(LOG_ERR, "unable to set up io completion port - EXITING"); + exit(1); + } #endif return fd; }