memrchr.cc \
memrchr.h \
mswindows.cc \
+ netdb.cc \
+ netdb.h \
os/aix.h \
os/android.h \
os/dragonfly.h \
os/sunos.h \
osdetect.h \
pipe.h \
+ select.cc \
+ select.h \
shm.cc \
shm.h \
+ socket.cc \
+ socket.h \
statvfs.cc \
statvfs.h \
stdio.h \
strtoll.h \
tempnam.h \
types.h \
+ unistd.cc \
+ unistd.h \
valgrind.h \
win32_maperror.cc \
win32_maperror.h \
+ wserrno.cc \
+ wserrno.h \
xalloc.cc \
xalloc.h \
xis.h \
#include "squid.h"
+#include "compat/unistd.h"
+
// The following code section is part of an EXPERIMENTAL native Windows NT/2000 Squid port.
// Compiles only on MS Visual C++
// CygWin appears not to need any of these
int
WIN32_truncate(const char *pathname, off_t length)
{
- int fd;
int res = -1;
- fd = open(pathname, O_RDWR);
+ const auto fd = xopen(pathname, O_RDWR);
if (fd == -1)
errno = EBADF;
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+
+#if _SQUID_WINDOWS_ || _SQUID_MINGW_
+
+#include "compat/netdb.h"
+#include "compat/wserrno.h"
+
+struct hostent *
+xgethostbyname(const char * const name)
+{
+ const auto result = gethostbyname(name);
+ if (!result)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+struct servent *
+xgetservbyname(const char * const name, const char * const proto)
+{
+ const auto result = getservbyname(name, proto);
+ if (!result)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+#endif /* _SQUID_WINDOWS_ || _SQUID_MINGW_ */
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_COMPAT_NETDB_H
+#define SQUID_COMPAT_NETDB_H
+
+#if HAVE_NETDB_H
+#include <netdb.h>
+#endif
+
+/// POSIX gethostbyname(3) equivalent
+struct hostent * xgethostbyname(const char * name);
+
+/// POSIX getservbyname(3) equivalent
+struct servent * xgetservbyname(const char * name, const char * proto);
+
+#if !(_SQUID_WINDOWS_ || _SQUID_MINGW_)
+
+inline struct hostent *
+xgethostbyname(const char *name)
+{
+ return gethostbyname(name);
+}
+
+inline struct servent *
+xgetservbyname(const char *name, const char *proto)
+{
+ return getservbyname(name, proto);
+}
+
+#endif /* !(_SQUID_WINDOWS_ || _SQUID_MINGW_) */
+#endif /* SQUID_COMPAT_NETDB_H */
#include <io.h>
-#ifndef _PATH_DEVNULL
-#define _PATH_DEVNULL "NUL"
-#endif
-
#ifndef EISCONN
#define EISCONN WSAEISCONN
#endif
#if defined(__cplusplus)
-inline int
-close(int fd)
-{
- char l_so_type[sizeof(int)];
- int l_so_type_siz = sizeof(l_so_type);
- SOCKET sock = _get_osfhandle(fd);
-
- if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0) {
- int result = 0;
- if (closesocket(sock) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- result = 1;
- }
- _free_osfhnd(fd);
- _osfile(fd) = 0;
- return result;
- } else
- return _close(fd);
-}
-
#if defined(_MSC_VER) /* Microsoft C Compiler ONLY */
-#ifndef _S_IREAD
-#define _S_IREAD 0x0100
#endif
-#ifndef _S_IWRITE
-#define _S_IWRITE 0x0080
-#endif
-
-inline int
-open(const char *filename, int oflag, int pmode = 0)
-{
- return _open(filename, oflag, pmode & (_S_IREAD | _S_IWRITE));
-}
-#endif
-
-inline int
-read(int fd, void * buf, size_t siz)
-{
- char l_so_type[sizeof(int)];
- int l_so_type_siz = sizeof(l_so_type);
- SOCKET sock = _get_osfhandle(fd);
-
- if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
- return ::recv(sock, (char FAR *) buf, (int)siz, 0);
- else
- return _read(fd, buf, (unsigned int)siz);
-}
-
-inline int
-write(int fd, const void * buf, size_t siz)
-{
- char l_so_type[sizeof(int)];
- int l_so_type_siz = sizeof(l_so_type);
- SOCKET sock = _get_osfhandle(fd);
-
- if (::getsockopt(sock, SOL_SOCKET, SO_TYPE, l_so_type, &l_so_type_siz) == 0)
- return ::send(sock, (char FAR *) buf, siz, 0);
- else
- return _write(fd, buf, siz);
-}
-
// stdlib <functional> definitions are required before std API redefinitions.
#include <functional>
* - map the FD value used by Squid to the socket handes used by Windows.
*/
-inline int
-accept(int s, struct sockaddr * a, socklen_t * l)
-{
- SOCKET result;
- if ((result = ::accept(_get_osfhandle(s), a, l)) == INVALID_SOCKET) {
- if (WSAEMFILE == (errno = WSAGetLastError()))
- errno = EMFILE;
- return -1;
- } else
- return _open_osfhandle(result, 0);
-}
-#define accept(s,a,l) Squid::accept(s,a,reinterpret_cast<socklen_t*>(l))
-
-inline int
-bind(int s, const struct sockaddr * n, socklen_t l)
-{
- if (::bind(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return 0;
-}
-#define bind(s,n,l) Squid::bind(s,n,l)
-
-inline int
-connect(int s, const struct sockaddr * n, socklen_t l)
-{
- if (::connect(_get_osfhandle(s),n,l) == SOCKET_ERROR) {
- if (WSAEMFILE == (errno = WSAGetLastError()))
- errno = EMFILE;
- return -1;
- } else
- return 0;
-}
-#define connect(s,n,l) Squid::connect(s,n,l)
-
-inline struct hostent *
-gethostbyname(const char *n) {
- HOSTENT FAR * result;
- if ((result = ::gethostbyname(n)) == NULL)
- errno = WSAGetLastError();
- return result;
-}
-#define gethostbyname(n) Squid::gethostbyname(n)
-
-inline SERVENT FAR *
-getservbyname(const char * n, const char * p)
-{
- SERVENT FAR * result;
- if ((result = ::getservbyname(n, p)) == NULL)
- errno = WSAGetLastError();
- return result;
-}
-#define getservbyname(n,p) Squid::getservbyname(n,p)
-
-inline HOSTENT FAR *
-gethostbyaddr(const void * a, size_t l, int t)
-{
- HOSTENT FAR * result;
- if ((result = ::gethostbyaddr((const char*)a, l, t)) == NULL)
- errno = WSAGetLastError();
- return result;
-}
-#define gethostbyaddr(a,l,t) Squid::gethostbyaddr(a,l,t)
-
-inline int
-getsockname(int s, struct sockaddr * n, socklen_t * l)
-{
- int i=*l;
- if (::getsockname(_get_osfhandle(s), n, &i) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return 0;
-}
-#define getsockname(s,a,l) Squid::getsockname(s,a,reinterpret_cast<socklen_t*>(l))
-
-inline int
-gethostname(char * n, size_t l)
-{
- if ((::gethostname(n, l)) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return 0;
-}
-#define gethostname(n,l) Squid::gethostname(n,l)
-
-inline int
-getsockopt(int s, int l, int o, void * v, socklen_t * n)
-{
- Sleep(1);
- if ((::getsockopt(_get_osfhandle(s), l, o,(char *) v, n)) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return 0;
-}
-#define getsockopt(s,l,o,v,n) Squid::getsockopt(s,l,o,v,n)
-
-/* Simple ioctl() emulation */
inline int
ioctl(int s, int c, void * a)
{
}
#define ioctlsocket(s,c,a) Squid::ioctlsocket(s,c,a)
-inline int
-listen(int s, int b)
-{
- if (::listen(_get_osfhandle(s), b) == SOCKET_ERROR) {
- if (WSAEMFILE == (errno = WSAGetLastError()))
- errno = EMFILE;
- return -1;
- } else
- return 0;
-}
-#define listen(s,b) Squid::listen(s,b)
-
-inline ssize_t
-recv(int s, void * b, size_t l, int f)
-{
- ssize_t result;
- if ((result = ::recv(_get_osfhandle(s), (char *)b, l, f)) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return result;
-}
-#define recv(s,b,l,f) Squid::recv(s,b,l,f)
-
-inline ssize_t
-recvfrom(int s, void * b, size_t l, int f, struct sockaddr * fr, socklen_t * fl)
-{
- ssize_t result;
- int ifl=*fl;
- if ((result = ::recvfrom(_get_osfhandle(s), (char *)b, l, f, fr, &ifl)) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return result;
-}
-#define recvfrom(s,b,l,f,r,n) Squid::recvfrom(s,b,l,f,r,reinterpret_cast<socklen_t*>(n))
-
-inline int
-select(int n, fd_set * r, fd_set * w, fd_set * e, struct timeval * t)
-{
- int result;
- if ((result = ::select(n,r,w,e,t)) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return result;
-}
-#define select(n,r,w,e,t) Squid::select(n,r,w,e,t)
-
-inline ssize_t
-send(int s, const char * b, size_t l, int f)
-{
- ssize_t result;
- if ((result = ::send(_get_osfhandle(s), b, l, f)) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return result;
-}
-#define send(s,b,l,f) Squid::send(s,reinterpret_cast<const char*>(b),l,f)
-
-inline ssize_t
-sendto(int s, const void * b, size_t l, int f, const struct sockaddr * t, socklen_t tl)
-{
- ssize_t result;
- if ((result = ::sendto(_get_osfhandle(s), (char *)b, l, f, t, tl)) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return result;
-}
-#define sendto(a,b,l,f,t,n) Squid::sendto(a,b,l,f,t,n)
-
-inline int
-setsockopt(SOCKET s, int l, int o, const void * v, socklen_t n)
-{
- SOCKET socket;
-
- socket = ((s == INVALID_SOCKET) ? s : (SOCKET)_get_osfhandle((int)s));
-
- if (::setsockopt(socket, l, o, (const char *)v, n) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return 0;
-}
-#define setsockopt(s,l,o,v,n) Squid::setsockopt(s,l,o,v,n)
-
inline int
shutdown(int s, int h)
{
}
#define shutdown(s,h) Squid::shutdown(s,h)
-inline int
-socket(int f, int t, int p)
-{
- SOCKET result;
- if ((result = ::socket(f, t, p)) == INVALID_SOCKET) {
- if (WSAEMFILE == (errno = WSAGetLastError()))
- errno = EMFILE;
- return -1;
- } else
- return _open_osfhandle(result, 0);
-}
-#define socket(f,t,p) Squid::socket(f,t,p)
-
-inline int
-WSAAsyncSelect(int s, HWND h, unsigned int w, long e)
-{
- if (::WSAAsyncSelect(_get_osfhandle(s), h, w, e) == SOCKET_ERROR) {
- errno = WSAGetLastError();
- return -1;
- } else
- return 0;
-}
-#define WSAAsyncSelect(s,h,w,e) Squid::WSAAsyncSelect(s,h,w,e)
-
#undef WSADuplicateSocket
inline int
WSADuplicateSocket(int s, DWORD n, LPWSAPROTOCOL_INFO l)
} /* namespace Squid */
#else /* #ifdef __cplusplus */
-#define connect(s,n,l) \
- (SOCKET_ERROR == connect(_get_osfhandle(s),n,l) ? \
- (WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1, -1) : 0)
-#define gethostbyname(n) \
- (NULL == ((HOSTENT FAR*)(ws32_result = (int)gethostbyname(n))) ? \
- (errno = WSAGetLastError()), (HOSTENT FAR*)NULL : (HOSTENT FAR*)ws32_result)
-#define gethostname(n,l) \
- (SOCKET_ERROR == gethostname(n,l) ? \
- (errno = WSAGetLastError()), -1 : 0)
-#define recv(s,b,l,f) \
- (SOCKET_ERROR == (ws32_result = recv(_get_osfhandle(s),b,l,f)) ? \
- (errno = WSAGetLastError()), -1 : ws32_result)
-#define sendto(s,b,l,f,t,tl) \
- (SOCKET_ERROR == (ws32_result = sendto(_get_osfhandle(s),b,l,f,t,tl)) ? \
- (errno = WSAGetLastError()), -1 : ws32_result)
-#define select(n,r,w,e,t) \
- (SOCKET_ERROR == (ws32_result = select(n,r,w,e,t)) ? \
- (errno = WSAGetLastError()), -1 : ws32_result)
-#define socket(f,t,p) \
- (INVALID_SOCKET == ((SOCKET)(ws32_result = (int)socket(f,t,p))) ? \
- ((WSAEMFILE == (errno = WSAGetLastError()) ? errno = EMFILE : -1), -1) : \
- (SOCKET)_open_osfhandle(ws32_result,0))
#define write _write /* Needed in util.c */
#define open _open /* Needed in win32lib.c */
#endif /* #ifdef __cplusplus */
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "compat/select.h"
+#include "compat/wserrno.h"
+
+#if _SQUID_WINDOWS_ || _SQUID_MINGW_
+
+int
+xselect(int nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, struct timeval * timeout)
+{
+ const auto result = select(nfds, readfds, writefds, exceptfds, timeout);
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+#endif /* _SQUID_WINDOWS_ || _SQUID_MINGW_ */
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_COMPAT_SELECT_H
+#define SQUID_COMPAT_SELECT_H
+
+#if HAVE_SYS_SELECT_H
+#include <sys/select.h>
+#endif
+
+/// POSIX select(2) equivalent
+int xselect(int nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, struct timeval * timeout);
+
+#if !(_SQUID_WINDOWS_ || _SQUID_MINGW_)
+
+inline int
+xselect(int nfds, fd_set * readfds, fd_set * writefds, fd_set * exceptfds, struct timeval * timeout)
+{
+ return select(nfds, readfds, writefds, exceptfds, timeout);
+}
+
+#endif /* !(_SQUID_WINDOWS_ || _SQUID_MINGW_) */
+
+#endif /* SQUID_COMPAT_SELECT_H */
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "compat/socket.h"
+#include "compat/wserrno.h"
+
+#if _SQUID_WINDOWS_ || _SQUID_MINGW_
+#include <unordered_map>
+
+int
+xaccept(int socketFd, struct sockaddr *sa, socklen_t *saLength)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ int al = 0;
+ int *alp = nullptr;
+ if (saLength) {
+ assert(*saLength <= INT_MAX);
+ al = static_cast<int>(*saLength);
+ alp = &al;
+ }
+ const auto result = accept(handle, sa, alp);
+ if (result == INVALID_SOCKET) {
+ SetErrnoFromWsaError();
+ return SOCKET_ERROR;
+ }
+ const auto rv = _open_osfhandle(result, 0);
+ if (rv == -1)
+ errno = EBADF;
+ if (saLength)
+ *saLength = static_cast<socklen_t>(al);
+ return rv;
+}
+
+int
+xbind(int socketFd, const struct sockaddr *sa, socklen_t saLength)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ assert(saLength <= INT_MAX);
+ const auto result = bind(handle, sa, static_cast<int>(saLength));
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+int
+xconnect(int socketFd, const struct sockaddr *sa, socklen_t saLength)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ assert(saLength <= INT_MAX);
+ const auto result = connect(handle, sa, static_cast<int>(saLength));
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+int
+xgetsockname(int socketFd, struct sockaddr * sa, socklen_t * saLength)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ int al = 0;
+ int *alp = nullptr;
+ if (saLength) {
+ assert(*saLength <= INT_MAX);
+ al = static_cast<int>(*saLength);
+ alp = &al;
+ }
+ const auto result = getsockname(handle, sa, alp);
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ if (saLength)
+ *saLength = static_cast<socklen_t>(al);
+ return result;
+}
+
+int
+xgetsockopt(int socketFd, int level, int optionName, void * optionValue, socklen_t * optionLength)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ int ol = 0;
+ int *olp = nullptr;
+ if (optionLength) {
+ assert(*optionLength <= INT_MAX);
+ ol = static_cast<int>(*optionLength);
+ olp = &ol;
+ }
+ const auto result = getsockopt(handle, level, optionName, static_cast<char *>(optionValue), olp);
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ if (optionLength)
+ *optionLength = static_cast<socklen_t>(ol);
+ return result;
+}
+
+int
+xlisten(int socketFd, int backlog)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ const auto result = listen(handle, backlog);
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+ssize_t
+xrecv(int socketFd, void * buf, size_t bufLength, int flags)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ assert(bufLength <= INT_MAX);
+ const auto result = recv(handle, static_cast<char *>(buf), static_cast<int>(bufLength), flags);
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+ssize_t
+xrecvfrom(int socketFd, void * buf, size_t bufLength, int flags, struct sockaddr * from, socklen_t * fromLength)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ assert(bufLength <= INT_MAX);
+ int fl = 0;
+ int *flp = nullptr;
+ if (fromLength) {
+ assert(*fromLength <= INT_MAX);
+ fl = static_cast<int>(*fromLength);
+ flp = &fl;
+ }
+ const auto result = recvfrom(handle, static_cast<char *>(buf), static_cast<int>(bufLength), flags, from, flp);
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ if (fromLength)
+ *fromLength = static_cast<socklen_t>(fl);
+ return result;
+}
+
+ssize_t
+xsend(int socketFd, const void * buf, size_t bufLength, int flags)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ assert(bufLength <= INT_MAX);
+ const auto result = send(handle, static_cast<const char *>(buf), static_cast<int>(bufLength), flags);
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+ssize_t
+xsendto(int socketFd, const void * buf, size_t bufLength, int flags, const struct sockaddr * to, socklen_t toLength)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ assert(bufLength <= INT_MAX);
+ assert(toLength <= INT_MAX);
+ const auto result = sendto(handle, static_cast<const char *>(buf), static_cast<int>(bufLength), flags, to, static_cast<int>(toLength));
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+int
+xsetsockopt(int socketFd, int level, int option, const void *value, socklen_t valueLength)
+{
+ const auto handle = _get_osfhandle(socketFd);
+ if (!isValidSocketHandle(handle)) {
+ // errno is already set by _get_osfhandle()
+ return SOCKET_ERROR;
+ }
+ assert(option <= INT_MAX);
+ const auto result = setsockopt(handle, level, option, static_cast<const char *>(value), static_cast<int>(valueLength));
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+int
+xsocket(int domain, int type, int protocol)
+{
+ const auto result = socket(domain, type, protocol);
+ if (result == INVALID_SOCKET) {
+ SetErrnoFromWsaError();
+ return SOCKET_ERROR;
+ }
+ const auto rv = _open_osfhandle(result, 0);
+ if (rv == -1)
+ errno = EBADF;
+ return rv;
+}
+
+#endif /* _SQUID_WINDOWS_ || _SQUID_MINGW_ */
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_COMPAT_SOCKET_H
+#define SQUID_COMPAT_SOCKET_H
+
+#if HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+
+/// POSIX accept(2) equivalent
+int xaccept(int socketFd, struct sockaddr *sa, socklen_t *saLength);
+
+/// POSIX bind(2) equivalent
+int xbind(int socketFd, const struct sockaddr *sa, socklen_t saLength);
+
+/// POSIX connect(2) equivalent
+int xconnect(int socketFd, const struct sockaddr *sa, socklen_t saLength);
+
+/// POSIX getsockopt(2) equivalent
+int xgetsockopt(int socketFd, int level, int optionName, void * optionValue, socklen_t * optionLength);
+
+/// POSIX getsockname(2) equivalent
+int xgetsockname(int socketFd, struct sockaddr * sa, socklen_t * saLength);
+
+/// POSIX listen(2) equivalent
+int xlisten(int socketFd, int backlog);
+
+/// POSIX recv(2) equivalent
+ssize_t xrecv(int socketFd, void * buf, size_t bufLength, int flags);
+
+/// POSIX recvfrom(2) equivalent
+ssize_t xrecvfrom(int socketFd, void * buf, size_t bufLength, int flags, struct sockaddr * from, socklen_t * fromLength);
+
+/// POSIX send(2) equivalent
+ssize_t xsend(int socketFd, const void * buf, size_t bufLength, int flags);
+
+/// POSIX sendto(2) equivalent
+ssize_t xsendto(int socketFd, const void * buf, size_t bufLength, int flags, const struct sockaddr * to, socklen_t toLength);
+
+/// POSIX setsockopt(2) equivalent
+int xsetsockopt(int socketFd, int level, int option, const void * value, socklen_t valueLength);
+
+/// POSIX socket(2) equivalent
+int xsocket(int domain, int type, int protocol);
+
+// Solaris and possibly others lack MSG_NOSIGNAL optimization
+// TODO: move this into compat/? Use a dedicated compat file to avoid dragging
+// sys/socket.h into the rest of Squid??
+#ifndef MSG_NOSIGNAL
+#define MSG_NOSIGNAL 0
+#endif
+
+#if !(_SQUID_WINDOWS_ || _SQUID_MINGW_)
+
+inline int
+xaccept(int socketFd, struct sockaddr *sa, socklen_t *saLength)
+{
+ return accept(socketFd, sa, saLength);
+}
+
+inline int
+xbind(int socketFd, const struct sockaddr *sa, socklen_t saLength)
+{
+ return bind(socketFd, sa, saLength);
+}
+
+inline int
+xconnect(int socketFd, const struct sockaddr *sa, socklen_t saLength)
+{
+ return connect(socketFd, sa, saLength);
+}
+
+inline int
+xgetsockname(int socketFd, struct sockaddr * sa, socklen_t * saLength)
+{
+ return getsockname(socketFd, sa, saLength);
+}
+
+inline int
+xlisten(int socketFd, int backlog)
+{
+ return listen(socketFd, backlog);
+}
+
+inline int
+xgetsockopt(int socketFd, int level, int optionName, void * optionValue, socklen_t * optionLength)
+{
+ return getsockopt(socketFd, level, optionName, optionValue, optionLength);
+}
+
+inline ssize_t
+xrecv(int socketFd, void * buf, size_t bufLength, int flags)
+{
+ return recv(socketFd, buf, bufLength, flags);
+}
+
+inline ssize_t
+xrecvfrom(int socketFd, void * buf, size_t bufLength, int flags, struct sockaddr * from, socklen_t * fromLength)
+{
+ return recvfrom(socketFd, buf, bufLength, flags, from, fromLength);
+}
+
+inline ssize_t
+xsend(int socketFd, const void * buf, size_t bufLength, int flags)
+{
+ return send(socketFd, buf, bufLength, flags);
+}
+
+inline ssize_t
+xsendto(int socketFd, const void * buf, size_t bufLength, int flags, const struct sockaddr * to, socklen_t l)
+{
+ return sendto(socketFd, buf, bufLength, flags, to, l);
+}
+
+inline int
+xsetsockopt(int socketFd, int level, int option, const void *value, socklen_t valueLength)
+{
+ return setsockopt(socketFd, level, option, value, valueLength);
+}
+
+inline int
+xsocket(int domain, int type, int protocol)
+{
+ return socket(domain, type, protocol);
+}
+
+#else
+
+static_assert(SOCKET_ERROR == -1);
+
+inline bool
+isValidSocketHandle(intptr_t handle)
+{
+ return handle != intptr_t(INVALID_HANDLE_VALUE);
+}
+
+#endif /* !(_SQUID_WINDOWS_ || _SQUID_MINGW_) */
+
+#endif /* SQUID_COMPAT_SOCKET_H */
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+
+#if _SQUID_WINDOWS_ || _SQUID_MINGW_
+
+#include "compat/socket.h"
+#include "compat/unistd.h"
+#include "compat/wserrno.h"
+
+// 2025 MinGW and pre-2022 MSVC do not define these
+#ifndef _S_IREAD
+#define _S_IREAD 0x0100
+#endif
+
+#ifndef _S_IWRITE
+#define _S_IWRITE 0x0080
+#endif
+
+/// returns true if handle is a valid socket. Preserves errno.
+static bool
+isSocket(intptr_t handle)
+{
+ if (!isValidSocketHandle(handle)) {
+ // isValidSocketHandle does not touch errno
+ return false;
+ }
+
+ int value = 0;
+ int valueSize = sizeof(value);
+ const auto savedErrno = errno;
+ // use Windows API directly
+ const auto result = (getsockopt(handle, SOL_SOCKET, SO_TYPE, reinterpret_cast<char *>(&value), &valueSize) == 0);
+ errno = savedErrno;
+ return result;
+}
+
+int
+xclose(int fd)
+{
+ const auto sock = _get_osfhandle(fd);
+ if (sock == intptr_t(INVALID_HANDLE_VALUE)) {
+ // errno is already set by _get_osfhandle()
+ return -1;
+ }
+
+ if (isSocket(sock)) {
+ const auto result = closesocket(sock);
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+ } else {
+ const auto result = _close(fd);
+ if (result)
+ SetErrnoFromWsaError();
+ return result;
+ }
+}
+
+int
+xgethostname(char *name, size_t nameLength)
+{
+ assert(nameLength <= INT_MAX);
+ const auto result = gethostname(name, static_cast<int>(nameLength));
+ if (result == SOCKET_ERROR)
+ SetErrnoFromWsaError();
+ return result;
+}
+
+int
+xopen(const char *filename, int oflag, int pmode)
+{
+ return _open(filename, oflag, pmode & (_S_IREAD | _S_IWRITE));
+}
+
+int
+xread(int fd, void * buf, size_t bufSize)
+{
+ const auto sock = _get_osfhandle(fd);
+ if (sock == intptr_t(INVALID_HANDLE_VALUE)) {
+ // errno is already set by _get_osfhandle()
+ return -1;
+ }
+
+ assert(bufSize <= UINT_MAX);
+ if (isSocket(sock))
+ return xrecv(sock, buf, bufSize, 0);
+ else
+ return _read(fd, buf, static_cast<unsigned int>(bufSize));
+}
+
+int
+xwrite(int fd, const void * buf, size_t bufSize)
+{
+ const auto sock = _get_osfhandle(fd);
+ if (sock == intptr_t(INVALID_HANDLE_VALUE)) {
+ // errno is already set by _get_osfhandle()
+ return -1;
+ }
+
+ assert(bufSize <= UINT_MAX);
+ if (isSocket(sock))
+ return xsend(sock, buf, bufSize, 0);
+ else
+ return _write(fd, buf, static_cast<unsigned int>(bufSize));
+}
+
+#endif /* _SQUID_WINDOWS_ || _SQUID_MINGW_ */
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_COMPAT_UNISTD_H
+#define SQUID_COMPAT_UNISTD_H
+
+#if HAVE_PATHS_H
+#include <paths.h>
+#endif
+#if HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+/// POSIX close(2) equivalent
+int xclose(int fd);
+
+/// POSIX gethostname(2) equivalent
+int xgethostname(char *name, size_t nameLength);
+
+/// POSIX open(2) equivalent
+int xopen(const char *filename, int oflag, int pmode = 0);
+
+/// POSIX read(2) equivalent
+int xread(int fd, void * buf, size_t bufSize);
+
+/// POSIX write(2) equivalent
+int xwrite(int fd, const void * buf, size_t bufSize);
+
+#if _SQUID_WINDOWS_ || _SQUID_MINGW_
+
+#if !defined(_PATH_DEVNULL)
+#define _PATH_DEVNULL "NUL"
+#endif
+
+#else /* _SQUID_WINDOWS_ || _SQUID_MINGW_ */
+
+inline int
+xclose(int fd)
+{
+ return close(fd);
+}
+
+inline int
+xgethostname(char *name, size_t nameLength)
+{
+ return gethostname(name, nameLength);
+}
+
+inline int
+xopen(const char *filename, int oflag, int pmode)
+{
+ return open(filename, oflag, pmode);
+}
+
+inline int
+xread(int fd, void * buf, size_t bufSize)
+{
+ return read(fd, buf, bufSize);
+}
+
+inline int
+xwrite(int fd, const void * buf, size_t bufSize)
+{
+ return write(fd, buf, bufSize);
+}
+
+#endif /* _SQUID_WINDOWS_ || _SQUID_MINGW_ */
+#endif /* SQUID_COMPAT_UNISTD_H */
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "compat/wserrno.h"
+
+#if _SQUID_WINDOWS_ || _SQUID_MINGW_
+
+#include <unordered_map>
+
+void
+SetErrnoFromWsaError()
+{
+ // POSIX codes which socket API users may care about
+ static const auto *CodeMap = new std::unordered_map<int, int> {
+ { WSAECONNABORTED, ECONNABORTED },
+ { WSAEINPROGRESS, EINPROGRESS },
+ { WSAEAFNOSUPPORT, EAFNOSUPPORT },
+ { WSAEINVAL, EINVAL },
+ { WSAEISCONN, EISCONN },
+ { WSAEWOULDBLOCK, EWOULDBLOCK },
+ // no Windows error code maps to EAGAIN
+ { WSAEALREADY, EALREADY },
+ { WSAEINTR, EINTR },
+ // no Windows error code maps to ERESTART
+ { WSAEMFILE, EMFILE },
+ // no Windows error code maps to ENFILE
+ { WSAECONNRESET, ECONNRESET }
+ };
+
+ const auto wsa = WSAGetLastError();
+ const auto itr = CodeMap->find(wsa);
+ if (itr != CodeMap->cend())
+ errno = itr->second;
+ else
+ errno = wsa;
+}
+
+#endif /* _SQUID_WINDOWS_ || _SQUID_MINGW_ */
--- /dev/null
+/*
+ * Copyright (C) 1996-2025 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#ifndef SQUID_COMPAT_WSERRNO_H
+#define SQUID_COMPAT_WSERRNO_H
+
+#if _SQUID_WINDOWS_ || _SQUID_MINGW_
+
+/**
+ * Squid socket code is written to handle POSIX errno codes.
+ * Set errno to the relevant POSIX or WSA code.
+ */
+void SetErrnoFromWsaError();
+
+#endif /* _SQUID_WINDOWS_ || _SQUID_MINGW_ */
+
+#endif /* SQUID_COMPAT_WSERRNO_H */
#include "squid.h"
#include "comm.h"
#include "comm/Loops.h"
+#include "compat/select.h"
#include "ConfigOption.h"
#include "diomsg.h"
#include "DiskdFile.h"
struct timeval delay = {0, 1};
while (away > magic2) {
- select(0, nullptr, nullptr, nullptr, &delay);
+ xselect(0, nullptr, nullptr, nullptr, &delay);
Store::Root().callback();
if (delay.tv_usec < 1000000)
/* DEBUG: section -- External DISKD process implementation. */
#include "squid.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "DiskIO/DiskDaemon/diomsg.h"
#include "hash.h"
static int
do_open(diomsg * r, int, const char *buf)
{
- int fd;
file_state *fs;
/*
* note r->offset holds open() flags
*/
- fd = open(buf, r->offset, 0600);
+ const auto fd = xopen(buf, r->offset, 0600);
if (fd < 0) {
DEBUG(1) {
fs);
}
xfree(fs);
- return close(fd);
+ return xclose(fd);
}
static int
do_read(diomsg * r, int, char *buf)
{
- int x;
int readlen = r->size;
file_state *fs;
fs = (file_state *) hash_lookup(hash, &r->id);
}
}
- x = read(fs->fd, buf, readlen);
+ const auto x = xread(fs->fd, buf, readlen);
DEBUG(2) {
fprintf(stderr, "%d READ %d,%d,%" PRId64 " ret %d\n", (int) mypid,
fs->fd, readlen, (int64_t)r->offset, x);
do_write(diomsg * r, int, const char *buf)
{
int wrtlen = r->size;
- int x;
file_state *fs;
fs = (file_state *) hash_lookup(hash, &r->id);
fprintf(stderr, "%d WRITE %d,%d,%" PRId64 "\n", (int) mypid,
fs->fd, wrtlen, (int64_t)r->offset);
}
- x = write(fs->fd, buf, wrtlen);
+ const auto x = xwrite(fs->fd, buf, wrtlen);
if (x < 0) {
DEBUG(1) {
if (rlen < 0) {
if (EINTR == errno) {
- if (read(0, rbuf, 512) <= 0) {
+ if (xread(0, rbuf, 512) <= 0) {
if (EWOULDBLOCK == errno)
(void) 0;
else if (EAGAIN == errno)
#include "squid.h"
#include "comm/Loops.h"
#include "compat/pipe.h"
+#include "compat/unistd.h"
#include "DiskIO/DiskThreads/CommIO.h"
#include "fd.h"
#include "globals.h"
{
/* Close done pipe signal */
FlushPipe();
- close(DoneFD);
- close(DoneReadFD);
+ xclose(DoneFD);
+ xclose(DoneReadFD);
fd_close(DoneFD);
fd_close(DoneReadFD);
Initialized = false;
#endif
#include "squid.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "DiskIO/DiskThreads/CommIO.h"
#include "DiskThreads.h"
#include "SquidConfig.h"
case _AIO_OP_OPEN:
if (cancelled && requestp->ret >= 0)
/* The open() was cancelled but completed */
- close(requestp->ret);
+ xclose(requestp->ret);
squidaio_xstrfree(requestp->path);
case _AIO_OP_CLOSE:
if (cancelled && requestp->ret < 0)
/* The close() was cancelled and never got executed */
- close(requestp->fd);
+ xclose(requestp->fd);
break;
squidaio_do_read(squidaio_request_t * requestp)
{
if (lseek(requestp->fd, requestp->offset, requestp->whence) >= 0)
- requestp->ret = read(requestp->fd, requestp->bufferp, requestp->buflen);
+ requestp->ret = xread(requestp->fd, requestp->bufferp, requestp->buflen);
else
requestp->ret = -1;
requestp->err = errno;
static void
squidaio_do_write(squidaio_request_t * requestp)
{
- requestp->ret = write(requestp->fd, requestp->bufferp, requestp->buflen);
+ requestp->ret = xwrite(requestp->fd, requestp->bufferp, requestp->buflen);
requestp->err = errno;
}
static void
squidaio_do_close(squidaio_request_t * requestp)
{
- requestp->ret = close(requestp->fd);
+ requestp->ret = xclose(requestp->fd);
requestp->err = errno;
}
/* DEBUG: section 43 Windows AIOPS */
#include "squid.h"
+#include "compat/unistd.h"
#include "compat/win32_maperror.h"
#include "DiskIO/DiskThreads/CommIO.h"
#include "DiskThreads.h"
case _AIO_OP_OPEN:
if (cancelled && requestp->ret >= 0)
/* The open() was cancelled but completed */
- close(requestp->ret);
+ xclose(requestp->ret);
squidaio_xstrfree(requestp->path);
case _AIO_OP_CLOSE:
if (cancelled && requestp->ret < 0)
/* The close() was cancelled and never got executed */
- close(requestp->fd);
+ xclose(requestp->fd);
break;
static void
squidaio_do_close(squidaio_request_t * requestp)
{
- if ((requestp->ret = close(requestp->fd)) < 0) {
+ if ((requestp->ret = xclose(requestp->fd)) < 0) {
debugs(43, DBG_CRITICAL, "squidaio_do_close: FD " << requestp->fd << ", errno " << errno);
- close(requestp->fd);
+ xclose(requestp->fd);
}
requestp->err = errno;
#include "adaptation/icap/ServiceRep.h"
#include "base/TextException.h"
#include "comm/Connection.h"
+#include "compat/netdb.h"
#include "ConfigParser.h"
#include "debug/Stream.h"
#include "fde.h"
if (!have_port) {
struct servent *serv;
if (cfg().protocol.caseCmp("icaps") == 0)
- serv = getservbyname("icaps", "tcp");
+ serv = xgetservbyname("icaps", "tcp");
else
- serv = getservbyname("icap", "tcp");
+ serv = xgetservbyname("icap", "tcp");
if (serv) {
writeableCfg().port = htons(serv->s_port);
#include "auth/basic/RADIUS/radius-util.h"
#include "auth/basic/RADIUS/radius.h"
#include "base/Random.h"
+#include "compat/netdb.h"
+#include "compat/select.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "helper/protocol_defines.h"
#include "md5.h"
#include <cerrno>
#include <cstring>
#include <ctime>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
#if _SQUID_WINDOWS_
#include <io.h>
#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#if HAVE_NETDB_H
-#include <netdb.h>
-#endif
#if HAVE_PWD_H
#include <pwd.h>
#endif
* Send the request we've built.
*/
gettimeofday(&sent, nullptr);
- if (send(socket_fd, (char *) auth, total_length, 0) < 0) {
+ if (xsend(socket_fd, auth, total_length, 0) < 0) {
int xerrno = errno;
// EAGAIN is expected at high traffic, just retry
// TODO: block/sleep a few ms to let the apparently full buffer drain ?
}
FD_ZERO(&readfds);
FD_SET(socket_fd, &readfds);
- if (select(socket_fd + 1, &readfds, nullptr, nullptr, &tv) == 0) /* Select timeout */
+ if (xselect(socket_fd + 1, &readfds, nullptr, nullptr, &tv) == 0) /* Select timeout */
break;
salen = sizeof(saremote);
- len = recvfrom(socket_fd, recv_buffer, sizeof(i_recv_buffer),
- 0, (struct sockaddr *) &saremote, &salen);
+ len = xrecvfrom(socket_fd, recv_buffer, sizeof(i_recv_buffer),
+ 0, (struct sockaddr *) &saremote, &salen);
if (len < 0)
continue;
{
struct sockaddr_in salocal;
struct sockaddr_in saremote;
- struct servent *svp;
unsigned short svc_port;
char username[MAXPWNAM];
char passwd[MAXPASS];
/*
* Open a connection to the server.
*/
- svp = getservbyname(svc_name, "udp");
+ const auto svp = xgetservbyname(svc_name, "udp");
if (svp != nullptr)
svc_port = ntohs((unsigned short) svp->s_port);
else
fprintf(stderr, "FATAL: %s: Couldn't find host %s\n", argv[0], server);
exit(EXIT_FAILURE);
}
- sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+ sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
perror("socket");
exit(EXIT_FAILURE);
saremote.sin_addr.s_addr = htonl(auth_ipaddr);
saremote.sin_port = htons(svc_port);
- if (connect(sockfd, (struct sockaddr *) &saremote, sizeof(saremote)) < 0) {
+ if (xconnect(sockfd, (struct sockaddr *) &saremote, sizeof(saremote)) < 0) {
perror("connect");
exit(EXIT_FAILURE);
}
salen = sizeof(salocal);
- if (getsockname(sockfd, (struct sockaddr *) &salocal, &salen) < 0) {
+ if (xgetsockname(sockfd, (struct sockaddr *) &salocal, &salen) < 0) {
perror("getsockname");
exit(EXIT_FAILURE);
}
authenticate(sockfd, username, passwd);
}
- close(sockfd);
+ xclose(sockfd);
return EXIT_SUCCESS;
}
#include "squid.h"
#include "auth/basic/RADIUS/radius-util.h"
+#include "compat/netdb.h"
+#include "compat/socket.h"
#include "md5.h"
#include <cctype>
#include <csignal>
#include <ctime>
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
-#if HAVE_NETDB_H
-#include <netdb.h>
-#endif
#if HAVE_PWD_H
#include <pwd.h>
#endif
if (good_ipaddr(host) == 0) {
return(ipstr2long(host));
- } else if ((hp = gethostbyname(host)) == (struct hostent *)nullptr) {
+ } else if (!(hp = xgethostbyname(host))) {
return((uint32_t)0);
}
return(ntohl(*(uint32_t *)hp->h_addr));
#if HAVE_GSSAPI
+#include "compat/unistd.h"
#include "negotiate_kerberos.h"
#if HAVE_SYS_STAT_H
#include "sys/stat.h"
#endif
-#if HAVE_UNISTD_H
-#include "unistd.h"
-#endif
#if HAVE_KRB5_MEMORY_KEYTAB
typedef struct _krb5_kt_list {
struct addrinfo *hres = nullptr, *hres_list;
int rc;
- rc = gethostname(hostname, sizeof(hostname)-1);
+ rc = xgethostname(hostname, sizeof(hostname)-1);
if (rc) {
debug((char *) "%s| %s: ERROR: resolving hostname '%s' failed\n", LogTime(), PROGRAM, hostname);
fprintf(stderr, "%s| %s: ERROR: resolving hostname '%s' failed\n",
#include "squid.h"
#include "base64.h"
#include "compat/pipe.h"
+#include "compat/unistd.h"
#include <cerrno>
#include <cstring>
#include <cstdlib>
#include <ctime>
-#if HAVE_NETDB_H
-#include <netdb.h>
-#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#if !defined(HAVE_DECL_XMALLOC) || !HAVE_DECL_XMALLOC
#define xmalloc malloc
if ( fpid == 0 ) {
/* First Child for Kerberos helper */
- close(pkin[1]);
+ xclose(pkin[1]);
dup2(pkin[0],STDIN_FILENO);
- close(pkin[0]);
+ xclose(pkin[0]);
- close(pkout[0]);
+ xclose(pkout[0]);
dup2(pkout[1],STDOUT_FILENO);
- close(pkout[1]);
+ xclose(pkout[1]);
setbuf(stdin, nullptr);
setbuf(stdout, nullptr);
exit(EXIT_FAILURE);
}
- close(pkin[0]);
- close(pkout[1]);
+ xclose(pkin[0]);
+ xclose(pkout[1]);
if (pipe(pnin) < 0) {
fprintf(stderr, "%s| %s: Could not assign streams for pnin\n", LogTime(), PROGRAM);
if ( fpid == 0 ) {
/* Second Child for NTLM helper */
- close(pnin[1]);
+ xclose(pnin[1]);
dup2(pnin[0],STDIN_FILENO);
- close(pnin[0]);
+ xclose(pnin[0]);
- close(pnout[0]);
+ xclose(pnout[0]);
dup2(pnout[1],STDOUT_FILENO);
- close(pnout[1]);
+ xclose(pnout[1]);
setbuf(stdin, nullptr);
setbuf(stdout, nullptr);
exit(EXIT_FAILURE);
}
- close(pnin[0]);
- close(pnout[1]);
+ xclose(pnin[0]);
+ xclose(pnout[1]);
FILE *FDKIN=fdopen(pkin[1],"w");
FILE *FDKOUT=fdopen(pkout[0],"r");
#include "squid.h"
#include "base/File.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "debug/Stream.h"
#include "sbuf/Stream.h"
#include "tools.h"
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
/* FileOpeningConfig */
enter_suid();
if (cfg.creationMask)
oldCreationMask = umask(cfg.creationMask); // XXX: Why here? Should not this be set for the whole Squid?
- fd_ = ::open(filename, cfg.openFlags, cfg.openMode);
+ fd_ = xopen(filename, cfg.openFlags, cfg.openMode);
const auto savedErrno = errno;
if (cfg.creationMask)
umask(oldCreationMask);
debugs(54, DBG_IMPORTANT, sysCallFailure("CloseHandle", WindowsErrorMessage(savedError)));
}
#else
- if (::close(fd_) != 0) {
+ if (xclose(fd_) != 0) {
const auto savedErrno = errno;
debugs(54, DBG_IMPORTANT, sysCallError("close", savedErrno));
}
throw TexcHere(sysCallFailure("ReadFile", WindowsErrorMessage(savedError)));
}
#else
- const auto result = ::read(fd_, rawBuf, readLimit);
+ const auto result = xread(fd_, rawBuf, readLimit);
if (result < 0) {
const auto savedErrno = errno;
throw TexcHere(sysCallError("read", savedErrno));
}
const auto bytesWritten = static_cast<size_t>(nBytesWritten);
#else
- const auto result = ::write(fd_, data.rawContent(), data.length());
+ const auto result = xwrite(fd_, data.rawContent(), data.length());
if (result < 0) {
const auto savedErrno = errno;
throw TexcHere(sysCallError("write", savedErrno));
#include "cache_cf.h"
#include "CachePeer.h"
#include "CachePeers.h"
+#include "compat/netdb.h"
+#include "compat/socket.h"
#include "ConfigOption.h"
#include "ConfigParser.h"
#include "CpuAffinityMap.h"
#if HAVE_GRP_H
#include <grp.h>
#endif
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
}
/** Returns either the service port number from /etc/services */
if ( !isUnsignedNumeric(token, strlen(token)) )
- port = getservbyname(token, proto);
+ port = xgetservbyname(token, proto);
if (port != nullptr) {
return ntohs((unsigned short)port->s_port);
}
#include "comm/TcpAcceptor.h"
#include "comm/Write.h"
#include "CommCalls.h"
+#include "compat/socket.h"
#include "debug/Messages.h"
#include "error/ExceptionErrorDetail.h"
#include "errorpage.h"
(transparent() || port->disable_pmtu_discovery == DISABLE_PMTU_ALWAYS)) {
#if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
int i = IP_PMTUDISC_DONT;
- if (setsockopt(clientConnection->fd, SOL_IP, IP_MTU_DISCOVER, &i, sizeof(i)) < 0) {
+ if (xsetsockopt(clientConnection->fd, SOL_IP, IP_MTU_DISCOVER, &i, sizeof(i)) < 0) {
int xerrno = errno;
debugs(33, 2, "WARNING: Path MTU discovery disabling failed on " << clientConnection << " : " << xstrerr(xerrno));
}
#include "comm/Read.h"
#include "comm/TcpAcceptor.h"
#include "CommCalls.h"
+#include "compat/socket.h"
#include "compat/strtoll.h"
#include "errorpage.h"
#include "fd.h"
if (fallback) {
int on = 1;
errno = 0;
- if (setsockopt(ftpState->ctrl.conn->fd, SOL_SOCKET, SO_REUSEADDR,
- (char *) &on, sizeof(on)) == -1) {
+ if (xsetsockopt(ftpState->ctrl.conn->fd, SOL_SOCKET, SO_REUSEADDR,
+ &on, sizeof(on)) == -1) {
int xerrno = errno;
// SO_REUSEADDR is only an optimization, no need to be verbose about error
debugs(9, 4, "setsockopt failed: " << xstrerr(xerrno));
#include "comm/TcpAcceptor.h"
#include "comm/Write.h"
#include "compat/cmsg.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "DescriptorSet.h"
#include "event.h"
#include "fd.h"
debugs(5,8, "comm_udp_recvfrom: FD " << fd << " from " << from);
struct addrinfo *AI = nullptr;
Ip::Address::InitAddr(AI);
- int x = recvfrom(fd, buf, len, flags, AI->ai_addr, &AI->ai_addrlen);
+ int x = xrecvfrom(fd, buf, len, flags, AI->ai_addr, &AI->ai_addrlen);
from = *AI;
Ip::Address::FreeAddr(AI);
return x;
ssize_t
comm_udp_send(int s, const void *buf, size_t len, int flags)
{
- return send(s, buf, len, flags);
+ return xsend(s, buf, len, flags);
}
bool
Ip::Address::InitAddr(addr);
- if (getsockname(fd, addr->ai_addr, &(addr->ai_addrlen)) ) {
+ if (xgetsockname(fd, addr->ai_addr, &(addr->ai_addrlen)) ) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, "ERROR: " << MYNAME << "Failed to retrieve TCP/UDP port number for socket: FD " << fd << ": " << xstrerr(xerrno));
Ip::Address::FreeAddr(addr);
{
#if defined(IP_BIND_ADDRESS_NO_PORT)
int flag = 1;
- if (setsockopt(fd, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, reinterpret_cast<char*>(&flag), sizeof(flag)) < 0) {
+ if (xsetsockopt(fd, IPPROTO_IP, IP_BIND_ADDRESS_NO_PORT, &flag, sizeof(flag)) < 0) {
const auto savedErrno = errno;
debugs(50, DBG_IMPORTANT, "ERROR: setsockopt(IP_BIND_ADDRESS_NO_PORT) failure: " << xstrerr(savedErrno));
}
{
++ statCounter.syscalls.sock.binds;
- if (bind(s, inaddr.ai_addr, inaddr.ai_addrlen) == 0) {
+ if (xbind(s, inaddr.ai_addr, inaddr.ai_addrlen) == 0) {
debugs(50, 6, "bind socket FD " << s << " to " << fd_table[s].local_addr);
return Comm::OK;
}
comm_set_v6only(int fd, int tos)
{
#ifdef IPV6_V6ONLY
- if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) < 0) {
+ if (xsetsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &tos, sizeof(int)) < 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, MYNAME << "setsockopt(IPV6_V6ONLY) " << (tos?"ON":"OFF") << " for FD " << fd << ": " << xstrerr(xerrno));
}
#if defined(soLevel) && defined(soFlag)
int tos = 1;
- if (setsockopt(fd, soLevel, soFlag, (char *) &tos, sizeof(int)) < 0) {
+ if (xsetsockopt(fd, soLevel, soFlag, &tos, sizeof(int)) < 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, MYNAME << "setsockopt(TPROXY) on FD " << fd << ": " << xstrerr(xerrno));
} else {
debugs(50, 3, "comm_openex: Attempt open socket for: " << addr );
- new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
+ new_socket = xsocket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
const auto firstErrNo = errno;
/* under IPv6 there is the possibility IPv6 is present but disabled. */
AI->ai_socktype = sock_type;
AI->ai_protocol = proto;
debugs(50, 3, "Attempt fallback open socket for: " << addr );
- new_socket = socket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
+ new_socket = xsocket(AI->ai_family, AI->ai_socktype, AI->ai_protocol);
// TODO: Report failures of this second socket() call.
// if both socket() calls fail, we use firstErrNo
debugs(50, 2, "attempt open " << note << " socket on: " << addr);
#if defined(SO_REUSEPORT)
if (flags & COMM_REUSEPORT) {
int on = 1;
- if (setsockopt(new_socket, SOL_SOCKET, SO_REUSEPORT, reinterpret_cast<char*>(&on), sizeof(on)) < 0) {
+ if (xsetsockopt(new_socket, SOL_SOCKET, SO_REUSEPORT, &on, sizeof(on)) < 0) {
const auto savedErrno = errno;
const auto errorMessage = ToSBuf("cannot enable SO_REUSEPORT socket option when binding to ",
addr, ": ", xstrerr(savedErrno));
++ statCounter.syscalls.sock.connects;
errno = 0;
- if ((x = connect(sock, AI->ai_addr, AI->ai_addrlen)) < 0) {
+ x = xconnect(sock, AI->ai_addr, AI->ai_addrlen);
+ if (x < 0) {
xerrno = errno;
debugs(5,5, "sock=" << sock << ", addrinfo(" <<
" flags=" << AI->ai_flags <<
} else {
errno = 0;
errlen = sizeof(err);
- x = getsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &errlen);
+ x = xgetsockopt(sock, SOL_SOCKET, SO_ERROR, &err, &errlen);
if (x == 0)
xerrno = err;
fd_table[fd].flags.harshClosureRequested = (l.l_onoff && !l.l_linger); // close(2) sends TCP RST if true
- if (setsockopt(fd, SOL_SOCKET, SO_LINGER, reinterpret_cast<char*>(&l), sizeof(l)) < 0) {
+ if (xsetsockopt(fd, SOL_SOCKET, SO_LINGER, &l, sizeof(l)) < 0) {
const auto xerrno = errno;
debugs(50, DBG_CRITICAL, "ERROR: Failed to set closure behavior (SO_LINGER) for FD " << fd << ": " << xstrerr(xerrno));
}
F->ssl.reset();
F->dynamicTlsContext.reset();
fd_close(fd); /* update fdstat */
- close(fd);
+ xclose(fd);
++ statCounter.syscalls.sock.closes;
struct addrinfo *AI = nullptr;
to_addr.getAddrInfo(AI, fd_table[fd].sock_family);
- int x = sendto(fd, buf, len, 0, AI->ai_addr, AI->ai_addrlen);
+ int x = xsendto(fd, buf, len, 0, AI->ai_addr, AI->ai_addrlen);
int xerrno = errno;
Ip::Address::FreeAddr(AI);
commSetReuseAddr(int fd)
{
int on = 1;
- if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *) &on, sizeof(on)) < 0) {
+ if (xsetsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) < 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, MYNAME << "FD " << fd << ": " << xstrerr(xerrno));
}
static void
commSetTcpRcvbuf(int fd, int size)
{
- if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *) &size, sizeof(size)) < 0) {
+ if (xsetsockopt(fd, SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)) < 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, MYNAME << "FD " << fd << ", SIZE " << size << ": " << xstrerr(xerrno));
}
- if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *) &size, sizeof(size)) < 0) {
+ if (xsetsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) < 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, MYNAME << "FD " << fd << ", SIZE " << size << ": " << xstrerr(xerrno));
}
#ifdef TCP_WINDOW_CLAMP
- if (setsockopt(fd, SOL_TCP, TCP_WINDOW_CLAMP, (char *) &size, sizeof(size)) < 0) {
+ if (xsetsockopt(fd, SOL_TCP, TCP_WINDOW_CLAMP, &size, sizeof(size)) < 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, MYNAME << "FD " << fd << ", SIZE " << size << ": " << xstrerr(xerrno));
}
{
int on = 1;
- if (setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, (char *) &on, sizeof(on)) < 0) {
+ if (xsetsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &on, sizeof(on)) < 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, MYNAME << "FD " << fd << ": " << xstrerr(xerrno));
}
debugs(50, 3, "Attempt open socket for: " << addr->sun_path);
- if ((new_socket = socket(AI.ai_family, AI.ai_socktype, AI.ai_protocol)) < 0) {
+ if ((new_socket = xsocket(AI.ai_family, AI.ai_socktype, AI.ai_protocol)) < 0) {
int xerrno = errno;
/* Increase the number of reserved fd's if calls to socket()
* are failing because the open file table is full. This
#include "comm/Connection.h"
#include "comm/ConnOpener.h"
#include "comm/Loops.h"
+#include "compat/socket.h"
#include "fd.h"
#include "fde.h"
#include "globals.h"
{
struct sockaddr_storage addr = {};
socklen_t len = sizeof(addr);
- if (getsockname(conn_->fd, reinterpret_cast<struct sockaddr *>(&addr), &len) != 0) {
+ if (xgetsockname(conn_->fd, reinterpret_cast<struct sockaddr *>(&addr), &len) != 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, "ERROR: Failed to retrieve TCP/UDP details for socket: " << conn_ << ": " << xstrerr(xerrno));
return;
#include "base/IoManip.h"
#include "comm/Loops.h"
+#include "compat/unistd.h"
#include "fd.h"
#include "fde.h"
#include "mgr/Registration.h"
static void
comm_flush_updates(void)
{
- int i;
if (devpoll_update.cur == -1)
return; /* array of changes to make is empty */
(devpoll_update.cur + 1) << " fds queued"
);
- i = write(
- devpoll_fd, /* open handle to /dev/poll */
- devpoll_update.pfds, /* pointer to array of struct pollfd */
- (devpoll_update.cur + 1) * sizeof(struct pollfd) /* bytes to process */
- );
+ const auto i = xwrite(
+ devpoll_fd, /* open handle to /dev/poll */
+ devpoll_update.pfds, /* pointer to array of struct pollfd */
+ (devpoll_update.cur + 1) * sizeof(struct pollfd) /* bytes to process */
+ );
assert(i > 0);
assert(static_cast<size_t>(i) == (sizeof(struct pollfd) * (devpoll_update.cur + 1)));
devpoll_update.cur = -1; /* reset size of array, no elements remain */
);
/* attempt to open /dev/poll device */
- devpoll_fd = open("/dev/poll", O_RDWR);
+ devpoll_fd = xopen("/dev/poll", O_RDWR);
if (devpoll_fd < 0) {
int xerrno = errno;
fatalf("comm_select_init: can't open /dev/poll: %s\n", xstrerr(xerrno));
#include "anyp/PortCfg.h"
#include "comm/Connection.h"
#include "comm/Loops.h"
+#include "compat/select.h"
#include "fde.h"
#include "globals.h"
#include "ICP.h"
++ statCounter.syscalls.selects;
- if (select(maxfd, &read_mask, &write_mask, nullptr, &zero_tv) < 1)
+ if (xselect(maxfd, &read_mask, &write_mask, nullptr, &zero_tv) < 1)
return incoming_sockets_accepted;
for (i = 0; i < nfds; ++i) {
poll_time.tv_sec = msec / 1000;
poll_time.tv_usec = (msec % 1000) * 1000;
++ statCounter.syscalls.selects;
- num = select(maxfd, &readfds, &writefds, nullptr, &poll_time);
+ num = xselect(maxfd, &readfds, &writefds, nullptr, &poll_time);
int xerrno = errno;
++ statCounter.select_loops;
#include "squid.h"
#include "comm/Tcp.h"
+#include "compat/socket.h"
#include "debug/Stream.h"
#if HAVE_NETINET_TCP_H
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#include <type_traits>
-/// setsockopt(2) wrapper
+/// xsetsockopt(2) wrapper
template <typename Option>
static bool
SetSocketOption(const int fd, const int level, const int optName, const Option &optValue)
{
static_assert(std::is_trivially_copyable<Option>::value, "setsockopt() expects POD-like options");
static_assert(!std::is_same<Option, bool>::value, "setsockopt() uses int to represent boolean options");
- if (setsockopt(fd, level, optName, reinterpret_cast<const char *>(&optValue), sizeof(optValue)) < 0) {
+ if (xsetsockopt(fd, level, optName, &optValue, sizeof(optValue)) < 0) {
const auto xerrno = errno;
debugs(5, DBG_IMPORTANT, "ERROR: setsockopt(2) failure: " << xstrerr(xerrno));
// TODO: Generalize to throw on errors when some callers need that.
#include "comm/Loops.h"
#include "comm/TcpAcceptor.h"
#include "CommCalls.h"
+#include "compat/socket.h"
#include "eui/Config.h"
#include "fd.h"
#include "fde.h"
Comm::TcpAcceptor::setListen()
{
errcode = errno = 0;
- if (listen(conn->fd, Squid_MaxFD >> 2) < 0) {
+ if (xlisten(conn->fd, Squid_MaxFD >> 2) < 0) {
errcode = errno;
debugs(50, DBG_CRITICAL, "ERROR: listen(..., " << (Squid_MaxFD >> 2) << ") system call failed: " << xstrerr(errcode));
return;
bzero(&afa, sizeof(afa));
debugs(5, DBG_IMPORTANT, "Installing accept filter '" << Config.accept_filter << "' on " << conn);
xstrncpy(afa.af_name, Config.accept_filter, sizeof(afa.af_name));
- if (setsockopt(conn->fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa)) < 0) {
+ if (xsetsockopt(conn->fd, SOL_SOCKET, SO_ACCEPTFILTER, &afa, sizeof(afa)) < 0) {
int xerrno = errno;
debugs(5, DBG_CRITICAL, "WARNING: SO_ACCEPTFILTER '" << Config.accept_filter << "': '" << xstrerr(xerrno));
}
int seconds = 30;
if (strncmp(Config.accept_filter, "data=", 5) == 0)
seconds = atoi(Config.accept_filter + 5);
- if (setsockopt(conn->fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &seconds, sizeof(seconds)) < 0) {
+ if (xsetsockopt(conn->fd, IPPROTO_TCP, TCP_DEFER_ACCEPT, &seconds, sizeof(seconds)) < 0) {
int xerrno = errno;
debugs(5, DBG_CRITICAL, "WARNING: TCP_DEFER_ACCEPT '" << Config.accept_filter << "': '" << xstrerr(xerrno));
}
errcode = 0; // reset local errno copy.
struct sockaddr_storage remoteAddress = {};
socklen_t remoteAddressSize = sizeof(remoteAddress);
- const auto rawSock = accept(conn->fd, reinterpret_cast<struct sockaddr *>(&remoteAddress), &remoteAddressSize);
+ const auto rawSock = xaccept(conn->fd, reinterpret_cast<struct sockaddr *>(&remoteAddress), &remoteAddressSize);
if (rawSock < 0) {
errcode = errno; // store last accept errno locally.
if (ignoreErrno(errcode) || errcode == ECONNABORTED) {
// lookup the local-end details of this new connection
struct sockaddr_storage localAddress = {};
socklen_t localAddressSize = sizeof(localAddress);
- if (getsockname(sock, reinterpret_cast<struct sockaddr *>(&localAddress), &localAddressSize) != 0) {
+ if (xgetsockname(sock, reinterpret_cast<struct sockaddr *>(&localAddress), &localAddressSize) != 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, "ERROR: Closing accepted TCP connection after failing to obtain its local IP address" <<
Debug::Extra << "accepted connection: " << details <<
#if USE_SQUID_EUI
#include "base/IoManip.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "debug/Stream.h"
#include "eui/Eui48.h"
#include "globals.h"
int offset;
/* IPv6 builds do not provide the first http_port as an IPv4 socket for ARP */
- int tmpSocket = socket(AF_INET,SOCK_STREAM,0);
+ auto tmpSocket = xsocket(AF_INET,SOCK_STREAM,0);
if (tmpSocket < 0) {
int xerrno = errno;
debugs(28, DBG_IMPORTANT, "ERROR: Attempt to open socket for EUI retrieval failed: " << xstrerr(xerrno));
debugs(28, 4, "id=" << (void*)this << " query ARP table");
if (ioctl(tmpSocket, SIOCGARP, &arpReq) != -1) {
/* Skip non-ethernet interfaces */
- close(tmpSocket);
+ xclose(tmpSocket);
if (arpReq.arp_ha.sa_family != ARPHRD_ETHER) {
debugs(28, 4, "id=" << (void*)this << " ... not an Ethernet interface: " << arpReq.arp_ha.sa_data);
int xerrno = errno;
debugs(28, DBG_IMPORTANT, "ERROR: Attempt to retrieve interface list failed: " << xstrerr(xerrno));
clear();
- close(tmpSocket);
+ xclose(tmpSocket);
return false;
}
if (ifc.ifc_len > (int)sizeof(ifbuffer)) {
debugs(28, DBG_IMPORTANT, "Interface list too long - " << ifc.ifc_len);
clear();
- close(tmpSocket);
+ xclose(tmpSocket);
return false;
}
*/
/* AYJ: 2009-10-06: for now we have to. We can only store one EUI at a time. */
- close(tmpSocket);
+ xclose(tmpSocket);
return true;
}
- close(tmpSocket);
+ xclose(tmpSocket);
#elif _SQUID_SOLARIS_
/* IPv6 builds do not provide the first http_port as an IPv4 socket for ARP */
- int tmpSocket = socket(AF_INET,SOCK_STREAM,0);
+ auto tmpSocket = xsocket(AF_INET,SOCK_STREAM,0);
if (tmpSocket < 0) {
int xerrno = errno;
debugs(28, DBG_IMPORTANT, "ERROR: Attempt to open socket for EUI retrieval failed: " << xstrerr(xerrno));
* Solaris (at least 2.6/x86) does not use arp_ha.sa_family -
* it returns 00:00:00:00:00:00 for non-ethernet media
*/
- close(tmpSocket);
+ xclose(tmpSocket);
if (arpReq.arp_ha.sa_data[0] == 0 &&
arpReq.arp_ha.sa_data[1] == 0 &&
set(arpReq.arp_ha.sa_data, 6);
return true;
} else {
- close(tmpSocket);
+ xclose(tmpSocket);
}
#elif _SQUID_FREEBSD_ || _SQUID_NETBSD_ || _SQUID_OPENBSD_ || _SQUID_DRAGONFLY_ || _SQUID_KFREEBSD_
#include "squid.h"
#include "comm/Loops.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "debug/Messages.h"
#include "debug/Stream.h"
#include "fatal.h"
#include "fde.h"
#include "globals.h"
-// Solaris and possibly others lack MSG_NOSIGNAL optimization
-// TODO: move this into compat/? Use a dedicated compat file to avoid dragging
-// sys/socket.h into the rest of Squid??
-#ifndef MSG_NOSIGNAL
-#define MSG_NOSIGNAL 0
-#endif
-
int default_read_method(int, char *, int);
int default_write_method(int, const char *, int);
#if _SQUID_WINDOWS_
int
socket_read_method(int fd, char *buf, int len)
{
- return recv(fd, (void *) buf, len, 0);
+ return xrecv(fd, (void *) buf, len, 0);
}
int
int
socket_write_method(int fd, const char *buf, int len)
{
- return send(fd, (const void *) buf, len, 0);
+ return xsend(fd, buf, len, 0);
}
int
int
default_read_method(int fd, char *buf, int len)
{
- return read(fd, buf, len);
+ return xread(fd, buf, len);
}
int
default_write_method(int fd, const char *buf, int len)
{
- return write(fd, buf, len);
+ return xwrite(fd, buf, len);
}
int
#include "squid.h"
#include "base/AsyncJobCalls.h"
+#include "compat/unistd.h"
#include "debug/Messages.h"
#include "fs/rock/RockDbCell.h"
#include "fs/rock/RockRebuild.h"
failure("cannot open db", errno);
char hdrBuf[SwapDir::HeaderSize];
- if (read(fd, hdrBuf, sizeof(hdrBuf)) != SwapDir::HeaderSize)
+ if (xread(fd, hdrBuf, sizeof(hdrBuf)) != SwapDir::HeaderSize)
failure("cannot read db header", errno);
// slot prefix of SM_PAGE_SIZE should fit both core entry header and ours
#include "base/IoManip.h"
#include "cache_cf.h"
#include "CollapsedForwarding.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "ConfigOption.h"
#include "DiskIO/DiskIOModule.h"
#include "DiskIO/DiskIOStrategy.h"
}
debugs (47, DBG_IMPORTANT, "Creating Rock db: " << filePath);
- const int swap = open(filePath, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600);
+ const auto swap = xopen(filePath, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY, 0600);
if (swap < 0)
createError("create");
memset(block, '\0', sizeof(block));
for (off_t offset = 0; offset < maxSize(); offset += sizeof(block)) {
- if (write(swap, block, sizeof(block)) != sizeof(block))
+ if (xwrite(swap, block, sizeof(block)) != sizeof(block))
createError("write");
}
#else
char header[HeaderSize];
memset(header, '\0', sizeof(header));
- if (write(swap, header, sizeof(header)) != sizeof(header))
+ if (xwrite(swap, header, sizeof(header)) != sizeof(header))
createError("write");
#endif
- close(swap);
+ xclose(swap);
}
// report Rock DB creation error and exit
#include "squid.h"
#include "comm/Loops.h"
+#include "compat/unistd.h"
#include "fd.h"
#include "fde.h"
#include "fs_io.h"
int
file_open(const char *path, int mode)
{
- int fd;
-
if (FILE_MODE(mode) == O_WRONLY)
mode |= O_APPEND;
errno = 0;
- fd = open(path, mode, 0644);
+ auto fd = xopen(path, mode, 0644);
++ statCounter.syscalls.disk.opens;
*/
assert(F->write_handler == nullptr);
- close(fd);
+ xclose(fd);
debugs(6, F->flags.close_request ? 2 : 5, "file_close: FD " << fd << " really closing");
/* DEBUG: section 37 ICMP Routines */
#include "squid.h"
+#include "compat/unistd.h"
#include "debug/Stream.h"
#include "Icmp.h"
#include "time/gadgets.h"
{
#if USE_ICMP
if (icmp_sock > 0)
- close(icmp_sock);
+ xclose(icmp_sock);
icmp_sock = -1;
icmp_ident = 0;
#endif
#if USE_ICMP
+#include "compat/socket.h"
#include "debug/Stream.h"
#include "Icmp4.h"
#include "IcmpPinger.h"
int
Icmp4::Open(void)
{
- icmp_sock = socket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
+ icmp_sock = xsocket(PF_INET, SOCK_RAW, IPPROTO_ICMP);
if (icmp_sock < 0) {
int xerrno = errno;
debugs(42, 5, "Send ICMP packet to " << to << ".");
- x = sendto(icmp_sock,
- (const void *) pkt,
- icmp_pktsize,
- 0,
- S->ai_addr,
- S->ai_addrlen);
+ x = xsendto(icmp_sock,
+ pkt,
+ icmp_pktsize,
+ 0,
+ S->ai_addr,
+ S->ai_addrlen);
if (x < 0) {
int xerrno = errno;
pkt = (char *)xmalloc(MAX_PKT4_SZ);
Ip::Address::InitAddr(from);
- n = recvfrom(icmp_sock,
- (void *)pkt,
- MAX_PKT4_SZ,
- 0,
- from->ai_addr,
- &from->ai_addrlen);
+ n = xrecvfrom(icmp_sock,
+ pkt,
+ MAX_PKT4_SZ,
+ 0,
+ from->ai_addr,
+ &from->ai_addrlen);
if (n <= 0) {
debugs(42, DBG_CRITICAL, "ERROR: when calling recvfrom() on ICMP socket.");
#if USE_ICMP
+#include "compat/socket.h"
#include "debug/Stream.h"
#include "Icmp6.h"
#include "IcmpPinger.h"
int
Icmp6::Open(void)
{
- icmp_sock = socket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
+ icmp_sock = xsocket(PF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
if (icmp_sock < 0) {
int xerrno = errno;
debugs(42, 5, "Send Icmp6 packet to " << to << ".");
- x = sendto(icmp_sock,
- (const void *) pkt,
- icmp6_pktsize,
- 0,
- S->ai_addr,
- S->ai_addrlen);
+ x = xsendto(icmp_sock,
+ pkt,
+ icmp6_pktsize,
+ 0,
+ S->ai_addr,
+ S->ai_addrlen);
if (x < 0) {
int xerrno = errno;
Ip::Address::InitAddr(from);
- n = recvfrom(icmp_sock,
- (void *)pkt,
- MAX_PKT6_SZ,
- 0,
- from->ai_addr,
- &from->ai_addrlen);
+ n = xrecvfrom(icmp_sock,
+ pkt,
+ MAX_PKT6_SZ,
+ 0,
+ from->ai_addr,
+ &from->ai_addrlen);
if (n <= 0) {
debugs(42, DBG_CRITICAL, "ERROR: when calling recvfrom() on ICMPv6 socket.");
#if USE_ICMP
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "debug/Stream.h"
#include "Icmp4.h"
#include "Icmp6.h"
setmode(0, O_BINARY);
setmode(1, O_BINARY);
- x = read(0, buf, sizeof(wpi));
+ x = xread(0, buf, sizeof(wpi));
if (x < (int)sizeof(wpi)) {
xerrno = errno;
getCurrentTime();
debugs(42, DBG_CRITICAL, MYNAME << " read: FD 0: " << xstrerr(xerrno));
- write(1, "ERR\n", 4);
+ xwrite(1, "ERR\n", 4);
return -1;
}
memcpy(&wpi, buf, sizeof(wpi));
- write(1, "OK\n", 3);
- x = read(0, buf, sizeof(PS));
+ xwrite(1, "OK\n", 3);
+ x = xread(0, buf, sizeof(PS));
if (x < (int)sizeof(PS)) {
xerrno = errno;
getCurrentTime();
debugs(42, DBG_CRITICAL, MYNAME << " read: FD 0: " << xstrerr(xerrno));
- write(1, "ERR\n", 4);
+ xwrite(1, "ERR\n", 4);
return -1;
}
xerrno = errno;
getCurrentTime();
debugs(42, DBG_CRITICAL, MYNAME << "WSASocket: " << xstrerr(xerrno));
- write(1, "ERR\n", 4);
+ xwrite(1, "ERR\n", 4);
return -1;
}
- x = connect(icmp_sock, (struct sockaddr *) &PS, sizeof(PS));
+ x = xconnect(icmp_sock, (struct sockaddr *) &PS, sizeof(PS));
- if (SOCKET_ERROR == x) {
+ if (x != 0) {
xerrno = errno;
getCurrentTime();
debugs(42, DBG_CRITICAL, MYNAME << "connect: " << xstrerr(xerrno));
- write(1, "ERR\n", 4);
+ xwrite(1, "ERR\n", 4);
return -1;
}
- write(1, "OK\n", 3);
+ xwrite(1, "OK\n", 3);
memset(buf, 0, sizeof(buf));
- x = recv(icmp_sock, (void *) buf, sizeof(buf), 0);
+ x = xrecv(icmp_sock, buf, sizeof(buf), 0);
if (x < 3) {
xerrno = errno;
return -1;
}
- x = send(icmp_sock, (const void *) buf, strlen(buf), 0);
+ x = xsend(icmp_sock, buf, strlen(buf), 0);
xerrno = errno;
if (x < 3 || strncmp("OK\n", buf, 3)) {
#if _SQUID_WINDOWS_
shutdown(icmp_sock, SD_BOTH);
- close(icmp_sock);
+ xclose(icmp_sock);
icmp_sock = -1;
#endif
int guess_size;
pecho = pingerEchoData();
- n = recv(socket_from_squid, &pecho, sizeof(pecho), 0);
+ n = xrecv(socket_from_squid, &pecho, sizeof(pecho), 0);
if (n < 0) {
debugs(42, DBG_IMPORTANT, "Pinger exiting.");
{
debugs(42, 2, "return result to squid. len=" << len);
- if (send(socket_to_squid, &preply, len, 0) < 0) {
+ if (xsend(socket_to_squid, &preply, len, 0) < 0) {
int xerrno = errno;
debugs(42, DBG_CRITICAL, "FATAL: send failure: " << xstrerr(xerrno));
Close();
#include "squid.h"
#include "comm.h"
#include "comm/Loops.h"
+#include "compat/socket.h"
#include "defines.h"
#include "fd.h"
#include "icmp/IcmpConfig.h"
#if _SQUID_WINDOWS_
- send(icmp_sock, (const void *) "$shutdown\n", 10, 0);
+ xsend(icmp_sock, (const void *) "$shutdown\n", 10, 0);
#endif
#if USE_ICMP
#include "base/Stopwatch.h"
+#include "compat/select.h"
+#include "compat/socket.h"
#include "Icmp4.h"
#include "Icmp6.h"
#include "IcmpPinger.h"
main(int, char **)
{
fd_set R;
- int x;
int max_fd = 0;
/*
FD_SET(squid_link, &R);
Stopwatch timer;
timer.resume();
- x = select(max_fd+1, &R, nullptr, nullptr, &tv);
+ const auto x = xselect(max_fd+1, &R, nullptr, nullptr, &tv);
getCurrentTime();
if (x < 0) {
const auto delay = std::chrono::duration_cast<std::chrono::seconds>(timer.total());
if (delay >= PingerTimeout) {
- if (send(LINK_TO_SQUID, &tv, 0, 0) < 0) {
+ if (xsend(LINK_TO_SQUID, &tv, 0, 0) < 0) {
debugs(42, DBG_CRITICAL, "Closing. No requests in last " << delay.count() << " seconds.");
control.Close();
exit(EXIT_FAILURE);
#include <ostream>
int
-main(int argc, char *argv[])
+main(int, char *argv[])
{
std::cerr << argv[0] << ": ICMP support not compiled in." << std::endl;
return EXIT_FAILURE;
#include "squid.h"
#include "comm/Connection.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "fde.h"
#include "ip/Intercept.h"
#include "ip/tools.h"
#endif /* IPF_TRANSPARENT required headers */
#if PF_TRANSPARENT
-#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <net/if.h>
/** \par
* Try NAT lookup for REDIRECT or DNAT targets. */
- if ( getsockopt(newConn->fd,
- newConn->local.isIPv6() ? IPPROTO_IPV6 : IPPROTO_IP,
- newConn->local.isIPv6() ? IP6T_SO_ORIGINAL_DST : SO_ORIGINAL_DST,
- &lookup,
- &len) != 0) {
+ if ( xgetsockopt(newConn->fd,
+ newConn->local.isIPv6() ? IPPROTO_IPV6 : IPPROTO_IP,
+ newConn->local.isIPv6() ? IP6T_SO_ORIGINAL_DST : SO_ORIGINAL_DST,
+ &lookup,
+ &len) != 0) {
const auto xerrno = errno;
debugs(89, DBG_IMPORTANT, "ERROR: NF getsockopt(ORIGINAL_DST) failed on " << newConn << ": " << xstrerr(xerrno));
return false;
int save_errno;
enter_suid();
#ifdef IPNAT_NAME
- natfd = open(IPNAT_NAME, O_RDONLY, 0);
+ natfd = xopen(IPNAT_NAME, O_RDONLY, 0);
#else
- natfd = open(IPL_NAT, O_RDONLY, 0);
+ natfd = xopen(IPL_NAT, O_RDONLY, 0);
#endif
save_errno = errno;
leave_suid();
const auto xerrno = errno;
if (xerrno != ESRCH) {
debugs(89, DBG_IMPORTANT, "ERROR: IPF (IPFilter) NAT lookup failed: ioctl(SIOCGNATL) (v=" << IPFILTER_VERSION << "): " << xstrerr(xerrno));
- close(natfd);
+ xclose(natfd);
natfd = -1;
}
static int pffd = -1;
if (pffd < 0)
- pffd = open("/dev/pf", O_RDONLY);
+ pffd = xopen("/dev/pf", O_RDONLY);
if (pffd < 0) {
const auto xerrno = errno;
const auto xerrno = errno;
if (xerrno != ENOENT) {
debugs(89, DBG_IMPORTANT, "ERROR: PF lookup failed: ioctl(DIOCNATLOOK): " << xstrerr(xerrno));
- close(pffd);
+ xclose(pffd);
pffd = -1;
}
debugs(89, 9, "address: " << newConn);
tmp.port(0);
tmp.getSockAddr(tmp_ip6);
- if ( (tmp_sock = socket(PF_INET6, SOCK_STREAM, IPPROTO_TCP)) >= 0 &&
- setsockopt(tmp_sock, soLevel, soFlag, (char *)&tos, sizeof(int)) == 0 &&
- bind(tmp_sock, (struct sockaddr*)&tmp_ip6, sizeof(struct sockaddr_in6)) == 0 ) {
+ if ( (tmp_sock = xsocket(PF_INET6, SOCK_STREAM, IPPROTO_TCP)) >= 0 &&
+ xsetsockopt(tmp_sock, soLevel, soFlag, &tos, sizeof(int)) == 0 &&
+ xbind(tmp_sock, (struct sockaddr*)&tmp_ip6, sizeof(struct sockaddr_in6)) == 0 ) {
debugs(3, 3, "IPv6 TPROXY support detected. Using.");
- close(tmp_sock);
+ xclose(tmp_sock);
if (doneSuid)
leave_suid();
return true;
}
if (tmp_sock >= 0) {
- close(tmp_sock);
+ xclose(tmp_sock);
tmp_sock = -1;
}
}
tmp.port(0);
tmp.getSockAddr(tmp_ip4);
- if ( (tmp_sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) >= 0 &&
- setsockopt(tmp_sock, soLevel, soFlag, (char *)&tos, sizeof(int)) == 0 &&
- bind(tmp_sock, (struct sockaddr*)&tmp_ip4, sizeof(struct sockaddr_in)) == 0 ) {
+ if ( (tmp_sock = xsocket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) >= 0 &&
+ xsetsockopt(tmp_sock, soLevel, soFlag, &tos, sizeof(int)) == 0 &&
+ xbind(tmp_sock, (struct sockaddr*)&tmp_ip4, sizeof(struct sockaddr_in)) == 0 ) {
debugs(3, 3, "IPv4 TPROXY support detected. Using.");
- close(tmp_sock);
+ xclose(tmp_sock);
if (doneSuid)
leave_suid();
return true;
}
if (tmp_sock >= 0) {
- close(tmp_sock);
+ xclose(tmp_sock);
}
}
#include "cache_cf.h"
#include "comm/Connection.h"
#include "compat/cmsg.h"
+#include "compat/socket.h"
#include "ConfigParser.h"
#include "fde.h"
#include "globals.h"
tos_t tos = 1;
int tos_len = sizeof(tos);
clientFde->tosFromServer = 0;
- if (setsockopt(server->fd,SOL_IP,IP_RECVTOS,&tos,tos_len)==0) {
+ if (xsetsockopt(server->fd,SOL_IP,IP_RECVTOS,&tos,tos_len)==0) {
unsigned char buf[512];
int len = 512;
- if (getsockopt(server->fd,SOL_IP,IP_PKTOPTIONS,buf,(socklen_t*)&len) == 0) {
+ if (xgetsockopt(server->fd,SOL_IP,IP_PKTOPTIONS,buf,(socklen_t*)&len) == 0) {
/* Parse the PKTOPTIONS structure to locate the TOS data message
* prepared in the kernel by the ZPH incoming TCP TOS preserving
* patch.
if (type == AF_INET) {
#if defined(IP_TOS)
- const int x = setsockopt(fd, IPPROTO_IP, IP_TOS, &bTos, sizeof(bTos));
+ const int x = xsetsockopt(fd, IPPROTO_IP, IP_TOS, &bTos, sizeof(bTos));
if (x < 0) {
int xerrno = errno;
debugs(50, 2, "setsockopt(IP_TOS) on " << fd << ": " << xstrerr(xerrno));
#endif
} else { // type == AF_INET6
#if defined(IPV6_TCLASS)
- const int x = setsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &bTos, sizeof(bTos));
+ const int x = xsetsockopt(fd, IPPROTO_IPV6, IPV6_TCLASS, &bTos, sizeof(bTos));
if (x < 0) {
int xerrno = errno;
debugs(50, 2, "setsockopt(IPV6_TCLASS) on " << fd << ": " << xstrerr(xerrno));
{
#if HAVE_LIBCAP && SO_MARK
debugs(50, 3, "for FD " << fd << " to " << mark);
- const int x = setsockopt(fd, SOL_SOCKET, SO_MARK, &mark, sizeof(nfmark_t));
+ const int x = xsetsockopt(fd, SOL_SOCKET, SO_MARK, &mark, sizeof(nfmark_t));
if (x < 0) {
int xerrno = errno;
debugs(50, 2, "setsockopt(SO_MARK) on " << fd << ": " << xstrerr(xerrno));
/* DEBUG: section 21 Misc Functions */
#include "squid.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "debug/Messages.h"
#include "ip/Address.h"
#include "ip/tools.h"
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#if HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
#if HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
Ip::ProbeTransport()
{
// check for usable IPv6 sockets
- int s = socket(PF_INET6, SOCK_STREAM, 0);
+ auto s = xsocket(PF_INET6, SOCK_STREAM, 0);
if (s < 0) {
debugs(3, 2, "IPv6 not supported on this machine. Auto-Disabled.");
EnableIpv6 = IPV6_OFF;
// (AKA. the operating system supports RFC 3493 section 5.3)
#if defined(IPV6_V6ONLY)
int tos = 0;
- if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &tos, sizeof(int)) == 0) {
+ if (xsetsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, &tos, sizeof(int)) == 0) {
debugs(3, 2, "Detected IPv6 hybrid or v4-mapping stack...");
EnableIpv6 |= IPV6_SPECIAL_V4MAPPING;
} else {
if (ip.isIPv6()) { // paranoid; always succeeds if we got this far
struct sockaddr_in6 sin;
ip.getSockAddr(sin);
- if (bind(s, reinterpret_cast<struct sockaddr *>(&sin), sizeof(sin)) != 0) {
+ if (xbind(s, reinterpret_cast<struct sockaddr *>(&sin), sizeof(sin)) != 0) {
debugs(3, Critical(66), "WARNING: BCP 177 violation. Detected non-functional IPv6 loopback.");
EnableIpv6 = IPV6_OFF;
} else {
}
}
- close(s);
+ xclose(s);
#if USE_IPV6
debugs(3, 2, "IPv6 transport " << (EnableIpv6?"Enabled":"Disabled"));
#include "squid.h"
#include "comm/Connection.h"
#include "compat/pipe.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "fd.h"
#include "fde.h"
#include "globals.h"
#include <thread>
#include <cstdlib>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
static const char *hello_string = "hi there\n";
#ifndef HELLO_BUF_SZ
#define HELLO_BUF_SZ 32
}
errno = 0;
- if (setsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, (void *) &buflen, sizeof(buflen)) == -1) {
+ if (xsetsockopt(fds[0], SOL_SOCKET, SO_SNDBUF, &buflen, sizeof(buflen)) == -1) {
xerrno = errno;
debugs(54, DBG_IMPORTANT, "ERROR: setsockopt failed: " << xstrerr(xerrno));
errno = 0;
}
- if (setsockopt(fds[0], SOL_SOCKET, SO_RCVBUF, (void *) &buflen, sizeof(buflen)) == -1) {
+ if (xsetsockopt(fds[0], SOL_SOCKET, SO_RCVBUF, &buflen, sizeof(buflen)) == -1) {
xerrno = errno;
debugs(54, DBG_IMPORTANT, "ERROR: setsockopt failed: " << xstrerr(xerrno));
errno = 0;
}
- if (setsockopt(fds[1], SOL_SOCKET, SO_SNDBUF, (void *) &buflen, sizeof(buflen)) == -1) {
+ if (xsetsockopt(fds[1], SOL_SOCKET, SO_SNDBUF, &buflen, sizeof(buflen)) == -1) {
xerrno = errno;
debugs(54, DBG_IMPORTANT, "ERROR: setsockopt failed: " << xstrerr(xerrno));
errno = 0;
}
- if (setsockopt(fds[1], SOL_SOCKET, SO_RCVBUF, (void *) &buflen, sizeof(buflen)) == -1) {
+ if (xsetsockopt(fds[1], SOL_SOCKET, SO_RCVBUF, &buflen, sizeof(buflen)) == -1) {
xerrno = errno;
debugs(54, DBG_IMPORTANT, "ERROR: setsockopt failed: " << xstrerr(xerrno));
errno = 0;
if (type == IPC_TCP_SOCKET || type == IPC_UDP_SOCKET) {
Ip::Address::InitAddr(AI);
- if (getsockname(pwfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
+ if (xgetsockname(pwfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
xerrno = errno;
Ip::Address::FreeAddr(AI);
debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerr(xerrno));
Ip::Address::InitAddr(AI);
- if (getsockname(crfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
+ if (xgetsockname(crfd, AI->ai_addr, &AI->ai_addrlen) < 0) {
xerrno = errno;
Ip::Address::FreeAddr(AI);
debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerr(xerrno));
}
if (type == IPC_TCP_SOCKET) {
- if (listen(crfd, 1) < 0) {
+ if (xlisten(crfd, 1) < 0) {
xerrno = errno;
debugs(54, DBG_IMPORTANT, "ipcCreate: listen FD " << crfd << ": " << xstrerr(xerrno));
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
if (type == IPC_UDP_SOCKET)
x = comm_udp_recv(prfd, hello_buf, sizeof(hello_buf)-1, 0);
else
- x = read(prfd, hello_buf, sizeof(hello_buf)-1);
+ x = xread(prfd, hello_buf, sizeof(hello_buf)-1);
xerrno = errno;
if (x >= 0)
hello_buf[x] = '\0';
no_suid(); /* give up extra privileges */
/* close shared socket with parent */
- close(prfd);
+ xclose(prfd);
if (pwfd != prfd)
- close(pwfd);
+ xclose(pwfd);
pwfd = prfd = -1;
if (type == IPC_TCP_SOCKET) {
debugs(54, 3, "ipcCreate: calling accept on FD " << crfd);
- if ((fd = accept(crfd, nullptr, nullptr)) < 0) {
+ if ((fd = xaccept(crfd, nullptr, nullptr)) < 0) {
xerrno = errno;
debugs(54, DBG_CRITICAL, "ipcCreate: FD " << crfd << " accept: " << xstrerr(xerrno));
_exit(1);
}
debugs(54, 3, "ipcCreate: CHILD accepted new FD " << fd);
- close(crfd);
+ xclose(crfd);
cwfd = crfd = fd;
} else if (type == IPC_UDP_SOCKET) {
if (comm_connect_addr(crfd, PaS) == Comm::COMM_ERROR)
_exit(1);
}
} else {
- if (write(cwfd, hello_string, strlen(hello_string) + 1) < 0) {
+ if (xwrite(cwfd, hello_string, strlen(hello_string) + 1) < 0) {
xerrno = errno;
debugs(54, DBG_CRITICAL, "write FD " << cwfd << ": " << xstrerr(xerrno));
debugs(54, DBG_CRITICAL, "ERROR: ipcCreate: CHILD: hello write test failed");
x = dupOrExit(crfd);
} while (x < 3);
- close(x);
+ xclose(x);
t1 = dupOrExit(crfd);
assert(t1 > 2 && t2 > 2 && t3 > 2);
- close(crfd);
+ xclose(crfd);
- close(cwfd);
+ xclose(cwfd);
- close(fileno(DebugStream()));
+ xclose(fileno(DebugStream()));
dup2(t1, 0);
dup2(t3, 2);
- close(t1);
+ xclose(t1);
- close(t2);
+ xclose(t2);
- close(t3);
+ xclose(t3);
/* Make sure all other filedescriptors are closed */
for (x = 3; x < SQUID_MAXFD; ++x)
- close(x);
+ xclose(x);
#if HAVE_SETSID
if (opt_no_daemon)
#include "CacheManager.h"
#include "comm.h"
#include "comm/Connection.h"
+#include "compat/unistd.h"
#include "ipc/Coordinator.h"
#include "ipc/SharedListen.h"
#include "mgr/Inquirer.h"
#include <cerrno>
+#if HAVE_SYS_UNISTD_H
+#include <sys/unistd.h>
+#endif
+
CBDATA_NAMESPACED_CLASS_INIT(Ipc, Coordinator);
Ipc::Coordinator* Ipc::Coordinator::TheInstance = nullptr;
debugs(54, DBG_IMPORTANT, "ERROR: Squid BUG: cannot aggregate mgr:" <<
request.params.actionName << ": " << ex.what());
// TODO: Avoid half-baked Connections or teach them how to close.
- ::close(request.conn->fd);
+ xclose(request.conn->fd);
request.conn->fd = -1;
return; // the worker will timeout and close
}
#include "comm/Connection.h"
#include "comm/Write.h"
#include "CommCalls.h"
+#include "compat/socket.h"
#include "ipc/UdsOp.h"
Ipc::UdsOp::UdsOp(const String& pathAddr):
{
struct sockaddr_storage addr;
socklen_t len = sizeof(addr);
- if (getsockname(conn->fd, reinterpret_cast<sockaddr*>(&addr), &len) == 0) {
+ if (xgetsockname(conn->fd, reinterpret_cast<sockaddr*>(&addr), &len) == 0) {
conn->remote = addr;
struct addrinfo* addr_info = nullptr;
conn->remote.getAddrInfo(addr_info);
#include "squid.h"
#include "base/TextException.h"
#include "compat/shm.h"
+#include "compat/unistd.h"
#include "debug/Stream.h"
#include "fatal.h"
#include "Instance.h"
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
// test cases change this
const char *Ipc::Mem::Segment::BasePath = DEFAULT_STATEDIR;
{
if (theFD >= 0) {
detach();
- if (close(theFD) != 0) {
+ if (xclose(theFD) != 0) {
int xerrno = errno;
debugs(54, 5, "close " << theName << ": " << xstrerr(xerrno));
}
#include "cache_cf.h"
#include "comm.h"
#include "comm/Connection.h"
+#include "compat/socket.h"
+#include "compat/unistd.h"
#include "fd.h"
#include "fde.h"
#include "globals.h"
Ip::Address::InitAddr(aiPS);
- if (getsockname(pwfd, aiPS->ai_addr, &(aiPS->ai_addrlen) ) < 0) {
+ if (xgetsockname(pwfd, aiPS->ai_addr, &(aiPS->ai_addrlen) ) < 0) {
int xerrno = errno;
debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerr(xerrno));
Ip::Address::FreeAddr(aiPS);
Ip::Address::InitAddr(aiCS);
- if (getsockname(crfd, aiCS->ai_addr, &(aiCS->ai_addrlen) ) < 0) {
+ if (xgetsockname(crfd, aiCS->ai_addr, &(aiCS->ai_addrlen) ) < 0) {
int xerrno = errno;
debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerr(xerrno));
Ip::Address::FreeAddr(aiCS);
}
if (type == IPC_TCP_SOCKET) {
- if (listen(crfd, 1) < 0) {
+ if (xlisten(crfd, 1) < 0) {
int xerrno = errno;
debugs(54, DBG_IMPORTANT, "ipcCreate: listen FD " << crfd << ": " << xstrerr(xerrno));
return ipcCloseAllFD(prfd, pwfd, crfd, cwfd);
}
memset(hello_buf, '\0', HELLO_BUF_SZ);
- x = recv(prfd, (void *)hello_buf, HELLO_BUF_SZ - 1, 0);
+ x = xrecv(prfd, (void *)hello_buf, HELLO_BUF_SZ - 1, 0);
if (x < 0) {
int xerrno = errno;
return ipcCloseAllFD(prfd, pwfd, -1, -1);
}
- x = send(pwfd, (const void *)ok_string, strlen(ok_string), 0);
+ x = xsend(pwfd, ok_string, strlen(ok_string), 0);
if (x < 0) {
int xerrno = errno;
}
memset(hello_buf, '\0', HELLO_BUF_SZ);
- x = recv(prfd, (void *)hello_buf, HELLO_BUF_SZ - 1, 0);
+ x = xrecv(prfd, (void *)hello_buf, HELLO_BUF_SZ - 1, 0);
if (x < 0) {
int xerrno = errno;
static int
ipcSend(int cwfd, const char *buf, int len)
{
- int x = send(cwfd, (const void *)buf, len, 0);
+ const auto x = xsend(cwfd, buf, len, 0);
if (x < 0) {
int xerrno = errno;
if (type == IPC_TCP_SOCKET) {
debugs(54, 3, "ipcCreate: calling accept on FD " << crfd);
- if ((fd = accept(crfd, nullptr, nullptr)) < 0) {
+ if ((fd = xaccept(crfd, nullptr, nullptr)) < 0) {
int xerrno = errno;
debugs(54, DBG_CRITICAL, "ipcCreate: FD " << crfd << " accept: " << xstrerr(xerrno));
goto cleanup;
goto cleanup;
}
- x = send(cwfd, (const void *)hello_string, strlen(hello_string) + 1, 0);
+ x = xsend(cwfd, hello_string, strlen(hello_string) + 1, 0);
if (x < 0) {
int xerrno = errno;
PutEnvironment();
memset(buf1, '\0', bufSz);
- x = recv(crfd, (void *)buf1, bufSz-1, 0);
+ x = xrecv(crfd, (void *)buf1, bufSz-1, 0);
if (x < 0) {
int xerrno = errno;
Ip::Address::InitAddr(aiPS_ipc);
- if (getsockname(pwfd_ipc, aiPS_ipc->ai_addr, &(aiPS_ipc->ai_addrlen)) < 0) {
+ if (xgetsockname(pwfd_ipc, aiPS_ipc->ai_addr, &(aiPS_ipc->ai_addrlen)) < 0) {
int xerrno = errno;
debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerr(xerrno));
ipcSend(cwfd, err_string, strlen(err_string));
Ip::Address::InitAddr(aiCS_ipc);
- if (getsockname(crfd_ipc, aiCS_ipc->ai_addr, &(aiCS_ipc->ai_addrlen)) < 0) {
+ if (xgetsockname(crfd_ipc, aiCS_ipc->ai_addr, &(aiCS_ipc->ai_addrlen)) < 0) {
int xerrno = errno;
debugs(54, DBG_CRITICAL, "ipcCreate: getsockname: " << xstrerr(xerrno));
ipcSend(cwfd, err_string, strlen(err_string));
goto cleanup;
}
- x = write(c2p[1], (const char *) &wpi, sizeof(wpi));
+ x = xwrite(c2p[1], (const char *) &wpi, sizeof(wpi));
if (x < (ssize_t)sizeof(wpi)) {
int xerrno = errno;
goto cleanup;
}
- x = read(p2c[0], buf1, bufSz-1);
+ x = xread(p2c[0], buf1, bufSz-1);
if (x < 0) {
int xerrno = errno;
goto cleanup;
}
- x = write(c2p[1], (const char *) &PS_ipc, sizeof(PS_ipc));
+ x = xwrite(c2p[1], (const char *) &PS_ipc, sizeof(PS_ipc));
if (x < (ssize_t)sizeof(PS_ipc)) {
int xerrno = errno;
goto cleanup;
}
- x = read(p2c[0], buf1, bufSz-1);
+ x = xread(p2c[0], buf1, bufSz-1);
if (x < 0) {
int xerrno = errno;
goto cleanup;
}
- x = send(pwfd_ipc, (const void *)ok_string, strlen(ok_string), 0);
- x = recv(prfd_ipc, (void *)(buf1 + 200), bufSz -1 - 200, 0);
+ x = xsend(pwfd_ipc, ok_string, strlen(ok_string), 0);
+ x = xrecv(prfd_ipc, (void *)(buf1 + 200), bufSz -1 - 200, 0);
assert((size_t) x == strlen(ok_string)
&& !strncmp(ok_string, buf1 + 200, strlen(ok_string)));
} /* IPC_UDP_SOCKET */
/* cycle */
for (;;) {
- x = recv(crfd, (void *)buf1, bufSz-1, 0);
+ x = xrecv(crfd, (void *)buf1, bufSz-1, 0);
if (x <= 0) {
debugs(54, 3, "ipc(" << prog << "," << pid << "): " << x << " bytes received from parent. Exiting...");
debugs(54, 5, "ipc(" << prog << "," << pid << "): received from parent: " << rfc1738_escape_unescaped(buf1));
if (type == IPC_TCP_SOCKET)
- x = write(c2p[1], buf1, x);
+ x = xwrite(c2p[1], buf1, x);
else
- x = send(pwfd_ipc, (const void *)buf1, x, 0);
+ x = xsend(pwfd_ipc, buf1, x, 0);
if (x <= 0) {
debugs(54, 3, "ipc(" << prog << "," << pid << "): " << x << " bytes written to " << prog << ". Exiting...");
ipcCloseAllFD(-1, -1, crfd, cwfd);
if (prfd_ipc != -1) {
- send(crfd_ipc, (const void *)shutdown_string, strlen(shutdown_string), 0);
+ xsend(crfd_ipc, shutdown_string, strlen(shutdown_string), 0);
shutdown(crfd_ipc, SD_BOTH);
shutdown(prfd_ipc, SD_BOTH);
}
for (;;) {
if (type == IPC_TCP_SOCKET)
- x = read(rfd, buf2, bufSz-1);
+ x = xread(rfd, buf2, bufSz-1);
else
- x = recv(rfd, (void *)buf2, bufSz-1, 0);
+ x = xrecv(rfd, (void *)buf2, bufSz-1, 0);
if ((x <= 0 && type == IPC_TCP_SOCKET) ||
(x < 0 && type == IPC_UDP_SOCKET)) {
debugs(54, 5, "ipc(" << prog << "," << pid << "): received from child : " << rfc1738_escape_unescaped(buf2));
- x = send(send_fd, (const void *)buf2, x, 0);
+ x = xsend(send_fd, buf2, x, 0);
if ((x <= 0 && type == IPC_TCP_SOCKET) ||
(x < 0 && type == IPC_UDP_SOCKET)) {
#include "squid.h"
#include "comm.h"
#include "comm/Connection.h"
+#include "compat/unistd.h"
#include "fatal.h"
#include "fd.h"
#include "fs_io.h"
logfile_mod_udp_write(Logfile * lf, const char *buf, size_t len)
{
l_udp_t *ll = (l_udp_t *) lf->data;
- ssize_t s;
- s = write(ll->fd, (char const *) buf, len);
+ const auto s = xwrite(ll->fd, buf, len);
fd_bytes(ll->fd, s, IoDirection::Write);
#if 0
// TODO: Enable after polishing to properly log these errors.
#include "squid.h"
+#include "compat/unistd.h"
+
#include <cassert>
#include <cerrno>
#include <csignal>
#include <cstring>
-#if HAVE_UNISTD_H
-#include <unistd.h>
-#endif
#if HAVE_FCNTL_H
#include <fcntl.h>
#endif
/* XXX stderr should not be closed, but in order to support squid must be
* able to collect and manage modules' stderr first.
*/
- close(2);
- t = open(_PATH_DEVNULL, O_RDWR);
+ xclose(2);
+ t = xopen(_PATH_DEVNULL, O_RDWR);
assert(t > -1);
dup2(t, 2);
#include "client_side.h"
#include "comm.h"
#include "CommandLine.h"
+#include "compat/unistd.h"
#include "ConfigParser.h"
#include "CpuAffinity.h"
#include "debug/Messages.h"
pid_t pid;
#ifdef TIOCNOTTY
- int i;
#endif
- int nullfd;
-
// TODO: zero values are not supported because they result in
// misconfigured SMP Squid instances running forever, endlessly
// restarting each dying kid.
#ifdef TIOCNOTTY
- if ((i = open("/dev/tty", O_RDWR | O_TEXT)) >= 0) {
+ if ((const auto i = xopen("/dev/tty", O_RDWR | O_TEXT)) >= 0) {
ioctl(i, TIOCNOTTY, nullptr);
close(i);
}
* 1.1.3. execvp had a bit overflow error in a loop..
*/
/* Connect stdio to /dev/null in daemon mode */
- nullfd = open(_PATH_DEVNULL, O_RDWR | O_TEXT);
+ const auto nullfd = xopen(_PATH_DEVNULL, O_RDWR | O_TEXT);
if (nullfd < 0) {
int xerrno = errno;
#include "squid.h"
#include "CacheManager.h"
#include "comm/Connection.h"
+#include "compat/unistd.h"
#include "HttpReply.h"
#include "ipc/Port.h"
#include "mgr/Action.h"
// Assume most kid classes are fully aggregatable (i.e., they do not dump
// local info at all). Do not import the remote HTTP fd into our Comm
// space; collect and send an IPC msg with collected info to Coordinator.
- ::close(request.conn->fd);
+ xclose(request.conn->fd);
request.conn->fd = -1;
collect();
sendResponse(request.requestId);
#include "squid.h"
#include "comm/Connection.h"
+#include "compat/socket.h"
#include "debug/Stream.h"
// XXX: for icpIncomingConn - need to pass it as a generic parameter.
#include "ICP.h"
#ifdef IP_MULTICAST_TTL
char ttl = (char) mcast_ttl;
- if (setsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, 1) < 0) {
+ if (xsetsockopt(fd, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, 1) < 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, "mcastSetTtl: FD " << fd << ", TTL: " << mcast_ttl << ": " << xstrerr(xerrno));
}
mr.imr_interface.s_addr = INADDR_ANY;
- if (setsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *) &mr, sizeof(struct ip_mreq)) < 0)
+ if (xsetsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mr, sizeof(struct ip_mreq)) < 0)
debugs(7, DBG_IMPORTANT, "ERROR: Join failed for " << icpIncomingConn << ", Multicast IP=" << ip);
char c = 0;
- if (setsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1) < 0) {
+ if (xsetsockopt(icpIncomingConn->fd, IPPROTO_IP, IP_MULTICAST_LOOP, &c, 1) < 0) {
int xerrno = errno;
debugs(7, DBG_IMPORTANT, "ERROR: " << icpIncomingConn << " can't disable multicast loopback: " << xstrerr(xerrno));
}
#include "CachePeers.h"
#include "comm/Connection.h"
#include "comm/ConnOpener.h"
+#include "compat/netdb.h"
#include "debug/Messages.h"
#include "event.h"
#include "FwdState.h"
void
neighbors_init(void)
{
- struct servent *sep = nullptr;
const char *me = getMyHostname();
neighborsRegisterWithCacheManager();
peerDnsRefreshStart();
- sep = getservbyname("echo", "udp");
+ const auto sep = xgetservbyname("echo", "udp");
echo_port = sep ? ntohs((unsigned short) sep->s_port) : 7;
}
#include "squid.h"
#include "base/HardFun.h"
#include "base/TextException.h"
+#include "compat/unistd.h"
#include "sbuf/Stream.h"
#include "security/cert_generators/file/certificate_db.h"
hFile = CreateFile(TEXT(filename.c_str()), GENERIC_READ, 0, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if (hFile == INVALID_HANDLE_VALUE)
#else
- fd = open(filename.c_str(), O_RDWR);
+ fd = xopen(filename.c_str(), O_RDWR);
if (fd == -1)
#endif
throw TextException(ToSBuf("Failed to open file ", filename), Here());
#else
flock(fd, LOCK_UN);
#endif
- close(fd);
+ xclose(fd);
fd = -1;
}
#endif
#include "squid.h"
#include "compat/cppunit.h"
+#include "compat/netdb.h"
#include "ip/Address.h"
#include "ip/tools.h"
#include "unitTestMain.h"
#if HAVE_ARPA_INET_H
#include <arpa/inet.h>
#endif
-#if HAVE_NETDB_H
-#include <netdb.h>
-#endif
/*
* test the IP storage type
void
TestIpAddress::testHostentConstructor()
{
- struct hostent *hp = nullptr;
struct in_addr outval;
struct in_addr expectval;
expectval.s_addr = htonl(0xC0A8640C);
- hp = gethostbyname("192.168.100.12");
+ const auto hp = xgethostbyname("192.168.100.12");
CPPUNIT_ASSERT( hp != nullptr /* gethostbyname failure.*/ );
Ip::Address anIPA(*hp);
#include "anyp/PortCfg.h"
#include "base/Subscription.h"
#include "client_side.h"
+#include "compat/unistd.h"
#include "fatal.h"
#include "fde.h"
#include "fqdncache.h"
}
// still no host. fallback to gethostname()
- if (gethostname(host, SQUIDHOSTNAMELEN) < 0) {
+ if (xgethostname(host, SQUIDHOSTNAMELEN) < 0) {
int xerrno = errno;
debugs(50, DBG_IMPORTANT, "WARNING: gethostname failed: " << xstrerr(xerrno));
} else {
#include "squid.h"
#if USE_UNLINKD
+#include "compat/select.h"
+#include "compat/unistd.h"
#include "fd.h"
#include "fde.h"
#include "fs_io.h"
{
char buf[MAXPATHLEN];
int l;
- int bytes_written;
static int queuelen = 0;
if (unlinkd_wfd < 0) {
FD_SET(unlinkd_rfd, &R);
to.tv_sec = 0;
to.tv_usec = 100000;
- select(unlinkd_rfd + 1, &R, nullptr, nullptr, &to);
+ xselect(unlinkd_rfd + 1, &R, nullptr, nullptr, &to);
#endif
}
* decrement the queue size by the number of newlines read.
*/
if (queuelen > 0) {
- int bytes_read;
int i;
char rbuf[512];
- bytes_read = read(unlinkd_rfd, rbuf, 511);
+ const auto bytes_read = xread(unlinkd_rfd, rbuf, 511);
if (bytes_read > 0) {
rbuf[bytes_read] = '\0';
xstrncpy(buf, path, MAXPATHLEN);
buf[l] = '\n';
++l;
- bytes_written = write(unlinkd_wfd, buf, l);
+ const auto bytes_written = xwrite(unlinkd_wfd, buf, l);
if (bytes_written < 0) {
int xerrno = errno;
#include "squid.h"
+#include "compat/unistd.h"
+
#include <iostream>
#include <cstdio>
#if HAVE_PATHS_H
{
std::string sbuf;
close(2);
- if (open(_PATH_DEVNULL, O_RDWR) < 0) {
+ if (xopen(_PATH_DEVNULL, O_RDWR) < 0) {
; // the irony of having to close(2) earlier is that we cannot report this failure.
}
while (getline(std::cin, sbuf)) {
#include "comm.h"
#include "comm/Connection.h"
#include "comm/Loops.h"
+#include "compat/socket.h"
#include "event.h"
#include "fatal.h"
#include "SquidConfig.h"
struct sockaddr_in router;
Config.Wccp.router.getSockAddr(router);
- if (connect(theWccpConnection, (struct sockaddr*)&router, sizeof(router)))
+ if (xconnect(theWccpConnection, (struct sockaddr*)&router, sizeof(router)))
fatal("Unable to connect WCCP out socket");
struct sockaddr_in local;
memset(&local, '\0', sizeof(local));
socklen_t slen = sizeof(local);
- if (getsockname(theWccpConnection, (struct sockaddr*)&local, &slen))
+ if (xgetsockname(theWccpConnection, (struct sockaddr*)&local, &slen))
fatal("Unable to getsockname on WCCP out socket");
local_ip = local;
#include "comm.h"
#include "comm/Connection.h"
#include "comm/Loops.h"
+#include "compat/socket.h"
#include "ConfigParser.h"
#include "event.h"
#include "ip/Address.h"
#include "tools.h"
#include "wccp2.h"
-#if HAVE_NETDB_H
-#include <netdb.h>
-#endif
-
#define WCCP_PORT 2048
#define WCCP_RESPONSE_SIZE 12448
#define WCCP_BUCKETS 256
#if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT)
{
int i = IP_PMTUDISC_DONT;
- if (setsockopt(theWccp2Connection, SOL_IP, IP_MTU_DISCOVER, &i, sizeof i) < 0) {
+ if (xsetsockopt(theWccp2Connection, SOL_IP, IP_MTU_DISCOVER, &i, sizeof i) < 0) {
int xerrno = errno;
debugs(80, 2, "WARNING: Path MTU discovery could not be disabled on FD " << theWccp2Connection << ": " << xstrerr(xerrno));
}
router.sin_port = htons(WCCP_PORT);
router.sin_addr = router_list_ptr->router_sendto_address;
- if (connect(theWccp2Connection, (struct sockaddr *) &router, router_len))
+ if (xconnect(theWccp2Connection, (struct sockaddr *) &router, router_len))
fatal("Unable to connect WCCP out socket");
local_len = sizeof(local);
memset(&local, '\0', local_len);
- if (getsockname(theWccp2Connection, (struct sockaddr *) &local, &local_len))
+ if (xgetsockname(theWccp2Connection, (struct sockaddr *) &local, &local_len))
fatal("Unable to getsockname on WCCP out socket");
router_list_ptr->local_ip = local.sin_addr;
* but disconnects anyway so we have to just assume it worked
*/
if (wccp2_numrouters > 1) {
- (void)connect(theWccp2Connection, (struct sockaddr *) &null, router_len);
+ (void)xconnect(theWccp2Connection, (struct sockaddr *) &null, router_len);
}
}
&service_list_ptr->wccp_packet,
service_list_ptr->wccp_packet_size);
} else {
- if (send(theWccp2Connection, &service_list_ptr->wccp_packet, service_list_ptr->wccp_packet_size, 0) < static_cast<int>(service_list_ptr->wccp_packet_size)) {
+ if (xsend(theWccp2Connection, &service_list_ptr->wccp_packet, service_list_ptr->wccp_packet_size, 0) < static_cast<int>(service_list_ptr->wccp_packet_size)) {
int xerrno = errno;
debugs(80, 2, "ERROR: failed to send WCCPv2 HERE_I_AM packet to " << router << " : " << xstrerr(xerrno));
}
&wccp_packet,
offset);
} else {
- if (send(theWccp2Connection, &wccp_packet, offset, 0) < static_cast<int>(offset)) {
+ if (xsend(theWccp2Connection, &wccp_packet, offset, 0) < offset) {
int xerrno = errno;
debugs(80, 2, "ERROR: failed to send WCCPv2 HERE_I_AM packet to " << tmp_rtr << " : " << xstrerr(xerrno));
}