From 3534b428629be185e096be99e3bd5fdfe32d5544 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Sep 2014 18:55:44 +0000 Subject: initial commit with rc for skalibs-2.0.0.0 --- src/libstddjb/socket_accept4.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/libstddjb/socket_accept4.c (limited to 'src/libstddjb/socket_accept4.c') diff --git a/src/libstddjb/socket_accept4.c b/src/libstddjb/socket_accept4.c new file mode 100644 index 0000000..e504375 --- /dev/null +++ b/src/libstddjb/socket_accept4.c @@ -0,0 +1,39 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int socket_accept4_internal (int s, char *ip, uint16 *port, unsigned int options) +{ + struct sockaddr_in sa ; + socklen_t dummy = sizeof sa ; + register int fd ; + do +#ifdef SKALIBS_HASACCEPT4 + fd = accept4(s, (struct sockaddr *)&sa, &dummy, ((options & DJBUNIX_FLAG_NB) ? SOCK_NONBLOCK : 0) | ((options & DJBUNIX_FLAG_COE) ? SOCK_CLOEXEC : 0)) ; +#else + fd = accept(s, (struct sockaddr *)&sa, &dummy) ; +#endif + while ((fd < 0) && (errno == EINTR)) ; + if (fd < 0) return -1 ; +#ifndef SKALIBS_HASACCEPT4 + if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) + || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) + { + register int e = errno ; + fd_close(fd) ; + errno = e ; + return -1 ; + } +#endif + byte_copy(ip, 4, (char *)&sa.sin_addr.s_addr) ; + uint16_unpack_big((char *)&sa.sin_port, port) ; + return fd ; +} -- cgit v1.2.3