003 File Manager
Current Path:
/usr/src/contrib/ntp/libntp
usr
/
src
/
contrib
/
ntp
/
libntp
/
📁
..
📄
Makefile.am
(3.27 KB)
📄
Makefile.in
(105.83 KB)
📄
README
(272 B)
📄
a_md5encrypt.c
(6.76 KB)
📄
adjtime.c
(10.29 KB)
📄
adjtimex.c
(334 B)
📄
atoint.c
(801 B)
📄
atolfp.c
(1.88 KB)
📄
atouint.c
(885 B)
📄
audio.c
(13.09 KB)
📄
authkeys.c
(19.92 KB)
📄
authreadkeys.c
(9.06 KB)
📄
authusekey.c
(748 B)
📄
bsd_strerror.c
(1.35 KB)
📄
buftvtots.c
(643 B)
📄
caljulian.c
(891 B)
📄
caltontp.c
(2.25 KB)
📄
calyearstart.c
(2.1 KB)
📄
clocktime.c
(4.49 KB)
📄
clocktypes.c
(3.69 KB)
📄
decodenetnum.c
(3.93 KB)
📄
dofptoa.c
(2.19 KB)
📄
dolfptoa.c
(3.14 KB)
📄
emalloc.c
(3.4 KB)
📄
findconfig.c
(1.46 KB)
📄
getopt.c
(2.21 KB)
📄
hextoint.c
(673 B)
📄
hextolfp.c
(1.35 KB)
📄
humandate.c
(1.1 KB)
📄
icom.c
(4.22 KB)
📄
iosignal.c
(12.27 KB)
📄
is_ip_address.c
(2.02 KB)
📄
lib_strbuf.c
(633 B)
📄
libssl_compat.c
(6.13 KB)
📄
machines.c
(13.05 KB)
📄
mktime.c
(8.29 KB)
📄
modetoa.c
(507 B)
📄
mstolfp.c
(2.01 KB)
📄
msyslog.c
(12.67 KB)
📄
netof.c
(1.17 KB)
📄
ntp_calendar.c
(58.49 KB)
📄
ntp_calgps.c
(15.73 KB)
📄
ntp_crypto_rnd.c
(2.11 KB)
📄
ntp_intres.c
(28.64 KB)
📄
ntp_libopts.c
(1.27 KB)
📄
ntp_lineedit.c
(3.88 KB)
📄
ntp_random.c
(17.63 KB)
📄
ntp_rfc2553.c
(14.85 KB)
📄
ntp_worker.c
(7.21 KB)
📄
numtoa.c
(963 B)
📄
numtohost.c
(908 B)
📄
octtoint.c
(578 B)
📄
prettydate.c
(5.53 KB)
📄
recvbuff.c
(7.3 KB)
📄
refidsmear.c
(1.05 KB)
📄
refnumtoa.c
(673 B)
📄
snprintf.c
(52.56 KB)
📄
socket.c
(4.88 KB)
📄
socktoa.c
(2.88 KB)
📄
socktohost.c
(2.54 KB)
📄
ssl_init.c
(5.09 KB)
📄
statestr.c
(11.4 KB)
📄
strdup.c
(854 B)
📄
strl_obsd.c
(3.65 KB)
📄
syssignal.c
(2.69 KB)
📄
systime.c
(17.51 KB)
📄
systime_s.c
(33 B)
📄
timespecops.c
(4.27 KB)
📄
timetoa.c
(2.75 KB)
📄
timevalops.c
(12.97 KB)
📄
timexsup.c
(1.17 KB)
📄
uglydate.c
(958 B)
📄
vint64ops.c
(5.1 KB)
📄
work_fork.c
(12.73 KB)
📄
work_thread.c
(22.88 KB)
📄
xsbprintf.c
(2.06 KB)
📄
ymd2yd.c
(582 B)
Editing: socket.c
/* * socket.c - low-level socket operations */ #ifdef HAVE_CONFIG_H # include <config.h> #endif #include <stdio.h> #include "ntp.h" #include "ntp_io.h" #include "ntp_net.h" #include "ntp_debug.h" /* * Windows C runtime ioctl() can't deal properly with sockets, * map to ioctlsocket for this source file. */ #ifdef SYS_WINNT #define ioctl(fd, opt, val) ioctlsocket(fd, opt, (u_long *)(val)) #endif /* * on Unix systems the stdio library typically * makes use of file descriptors in the lower * integer range. stdio usually will make use * of the file descriptors in the range of * [0..FOPEN_MAX) * in order to keep this range clean, for socket * file descriptors we attempt to move them above * FOPEN_MAX. This is not as easy as it sounds as * FOPEN_MAX changes from implementation to implementation * and may exceed to current file decriptor limits. * We are using following strategy: * - keep a current socket fd boundary initialized with * max(0, min(GETDTABLESIZE() - FD_CHUNK, FOPEN_MAX)) * - attempt to move the descriptor to the boundary or * above. * - if that fails and boundary > 0 set boundary * to min(0, socket_fd_boundary - FD_CHUNK) * -> retry * if failure and boundary == 0 return old fd * - on success close old fd return new fd * * effects: * - fds will be moved above the socket fd boundary * if at all possible. * - the socket boundary will be reduced until * allocation is possible or 0 is reached - at this * point the algrithm will be disabled */ SOCKET move_fd( SOCKET fd ) { #if !defined(SYS_WINNT) && defined(F_DUPFD) #ifndef FD_CHUNK #define FD_CHUNK 10 #endif #ifndef FOPEN_MAX #define FOPEN_MAX 20 #endif /* * number of fds we would like to have for * stdio FILE* available. * we can pick a "low" number as our use of * FILE* is limited to log files and temporarily * to data and config files. Except for log files * we don't keep the other FILE* open beyond the * scope of the function that opened it. */ #ifndef FD_PREFERRED_SOCKBOUNDARY #define FD_PREFERRED_SOCKBOUNDARY 48 #endif static SOCKET socket_boundary = -1; SOCKET newfd; REQUIRE((int)fd >= 0); /* * check whether boundary has be set up * already */ if (socket_boundary == -1) { socket_boundary = max(0, min(GETDTABLESIZE() - FD_CHUNK, min(FOPEN_MAX, FD_PREFERRED_SOCKBOUNDARY))); TRACE(1, ("move_fd: estimated max descriptors: %d, " "initial socket boundary: %d\n", GETDTABLESIZE(), socket_boundary)); } /* * Leave a space for stdio to work in. potentially moving the * socket_boundary lower until allocation succeeds. */ do { if (fd >= 0 && fd < socket_boundary) { /* inside reserved range: attempt to move fd */ newfd = fcntl(fd, F_DUPFD, socket_boundary); if (newfd != -1) { /* success: drop the old one - return the new one */ close(fd); return newfd; } } else { /* outside reserved range: no work - return the original one */ return fd; } socket_boundary = max(0, socket_boundary - FD_CHUNK); TRACE(1, ("move_fd: selecting new socket boundary: %d\n", socket_boundary)); } while (socket_boundary > 0); #else ENSURE((int)fd >= 0); #endif /* !defined(SYS_WINNT) && defined(F_DUPFD) */ return fd; } /* * make_socket_nonblocking() - set up descriptor to be non blocking */ void make_socket_nonblocking( SOCKET fd ) { /* * set non-blocking, */ #ifdef USE_FIONBIO /* in vxWorks we use FIONBIO, but the others are defined for old * systems, so all hell breaks loose if we leave them defined */ #undef O_NONBLOCK #undef FNDELAY #undef O_NDELAY #endif #if defined(O_NONBLOCK) /* POSIX */ if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) { msyslog(LOG_ERR, "fcntl(O_NONBLOCK) fails on fd #%d: %m", fd); exit(1); } #elif defined(FNDELAY) if (fcntl(fd, F_SETFL, FNDELAY) < 0) { msyslog(LOG_ERR, "fcntl(FNDELAY) fails on fd #%d: %m", fd); exit(1); } #elif defined(O_NDELAY) /* generally the same as FNDELAY */ if (fcntl(fd, F_SETFL, O_NDELAY) < 0) { msyslog(LOG_ERR, "fcntl(O_NDELAY) fails on fd #%d: %m", fd); exit(1); } #elif defined(FIONBIO) { int on = 1; if (ioctl(fd, FIONBIO, &on) < 0) { msyslog(LOG_ERR, "ioctl(FIONBIO) fails on fd #%d: %m", fd); exit(1); } } #elif defined(FIOSNBIO) if (ioctl(fd, FIOSNBIO, &on) < 0) { msyslog(LOG_ERR, "ioctl(FIOSNBIO) fails on fd #%d: %m", fd); exit(1); } #else # include "Bletch: Need non-blocking I/O!" #endif } #if 0 /* The following subroutines should probably be moved here */ static SOCKET open_socket( sockaddr_u * addr, int bcast, int turn_off_reuse, endpt * interf ) void sendpkt( sockaddr_u * dest, struct interface * ep, int ttl, struct pkt * pkt, int len ) static inline int read_refclock_packet(SOCKET fd, struct refclockio *rp, l_fp ts) static inline int read_network_packet( SOCKET fd, struct interface * itf, l_fp ts ) void kill_asyncio(int startfd) #endif /* 0 */
Upload File
Create Folder