mirror of
https://github.com/curl/curl.git
synced 2026-08-25 12:03:39 +03:00
socket: use accept4 when available
Linux, *BSD, and Solaris support accept4 system call that enables the caller to assign additional flags and save some extra system calls. It can come in handy when O_NONBLOCK or/and FD_CLOEXEC is/are required on a socket after being accepted. Ref: https://man7.org/linux/man-pages/man2/accept.2.html https://man.freebsd.org/cgi/man.cgi?query=accept4 https://man.dragonflybsd.org/?command=accept§ion=2 https://man.openbsd.org/accept.2 https://man.netbsd.org/accept.2 https://docs.oracle.com/cd/E88353_01/html/E37843/accept4-3c.html https://www.gnu.org/software/gnulib/manual/html_node/accept4.html Closes #16979
This commit is contained in:
parent
2f5e4e0db4
commit
3d02872be7
8 changed files with 52 additions and 2 deletions
|
|
@ -378,6 +378,24 @@ curl_socket_t curl_dbg_accept(curl_socket_t s, void *saddr, void *saddrlen,
|
|||
return sockfd;
|
||||
}
|
||||
|
||||
#ifdef HAVE_ACCEPT4
|
||||
curl_socket_t curl_dbg_accept4(curl_socket_t s, void *saddr, void *saddrlen,
|
||||
int flags,
|
||||
int line, const char *source)
|
||||
{
|
||||
struct sockaddr *addr = (struct sockaddr *)saddr;
|
||||
curl_socklen_t *addrlen = (curl_socklen_t *)saddrlen;
|
||||
|
||||
curl_socket_t sockfd = accept4(s, addr, addrlen, flags);
|
||||
|
||||
if(source && (sockfd != CURL_SOCKET_BAD))
|
||||
curl_dbg_log("FD %s:%d accept() = %" FMT_SOCKET_T "\n",
|
||||
source, line, sockfd);
|
||||
|
||||
return sockfd;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* separate function to allow libcurl to mark a "faked" close */
|
||||
void curl_dbg_mark_sclose(curl_socket_t sockfd, int line, const char *source)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue