FreeBSD/contrib/ntp/ntpd/ntp_io.c
/*
 * Routine to read the refclock packets for a specific interface
 * Return the number of bytes read. That way we know if we should
 * read it again or go on to the next one if no bytes returned
 */
Routine to read the refclock packets for a specific interface
Return the number of bytes read. That way we know if we should
read it again or go on to the next one if no bytes returned
Routine to read the refclock packets for a specific interface Return the number of bytes read . That way we know if we should read it again or go on to the next one if no bytes returned
static inline int
read_refclock_packet(
	SOCKET			fd,
	struct refclockio *	rp,
	l_fp			ts
	)
{
	u_int			read_count;
	int			buflen;
	int			saved_errno;
	int			consumed;
	struct recvbuf *	rb;
	rb = get_free_recv_buffer();
	if (NULL == rb) {
		char buf[RX_BUFF_SIZE];
		buflen = read(fd, buf, sizeof buf);
		packets_dropped++;
		return (buflen);
	}
	if (rp->datalen <= 0 || (size_t)rp->datalen > sizeof(rb->recv_space))
		read_count = sizeof(rb->recv_space);
	else
		read_count = (u_int)rp->datalen;
	do {
		buflen = read(fd, (char *)&rb->recv_space, read_count);
	} while (buflen < 0 && EINTR == errno);
	if (buflen <= 0) {
		saved_errno = errno;
		freerecvbuf(rb);
		errno = saved_errno;
		return buflen;
	}
	rb->recv_length = buflen;
	rb->recv_peer = rp->srcclock;
	rb->dstadr = 0;
	rb->fd = fd;
	rb->recv_time = ts;
	rb->receiver = rp->clock_recv;
	consumed = indicate_refclock_packet(rp, rb);
	if (!consumed) {
		rp->recvcount++;
		packets_received++;
	}
	return buflen;
}
static inline int read_refclock_packet ( SOCKET fd , struct refclockio * rp , l_fp ts ) { u_int read_count ; int buflen ; int saved_errno ; int consumed ; struct recvbuf * rb ; rb = get_free_recv_buffer ( ) ; if ( NULL == rb ) { char buf [ RX_BUFF_SIZE ] ; buflen = read ( fd , buf , sizeof buf ) ; packets_dropped ++ ; return ( buflen ) ; } if ( rp -> datalen <= 0 || ( size_t ) rp -> datalen > sizeof ( rb -> recv_space ) ) read_count = sizeof ( rb -> recv_space ) ; else read_count = ( u_int ) rp -> datalen ; do { buflen = read ( fd , ( char * ) & rb -> recv_space , read_count ) ; } while ( buflen < 0 && EINTR == errno ) ; if ( buflen <= 0 ) { saved_errno = errno ; freerecvbuf ( rb ) ; errno = saved_errno ; return buflen ; } rb -> recv_length = buflen ; rb -> recv_peer = rp -> srcclock ; rb -> dstadr = 0 ; rb -> fd = fd ; rb -> recv_time = ts ; rb -> receiver = rp -> clock_recv ; consumed = indicate_refclock_packet ( rp , rb ) ; if ( ! consumed ) { rp -> recvcount ++ ; packets_received ++ ; } return buflen ; }
Routine to read the refclock packets for a specific interface
 Return the number of bytes read.
Routine to read the refclock packets for a specific interface Return the number of bytes read .
/*
		 * No buffer space available - just drop the packet
		 */ /* TALOS-CAN-0064: avoid signed/unsigned clashes that can lead
	 * to buffer overrun and memory corruption
	 */ /*
	 * Got one. Mark how and when it got here,
	 * put it on the full list and do bookkeeping.
	 */