Ai
1 Star 0 Fork 0

wangcichen/urbackup_backend

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
socket_header.h 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
Martin 提交于 2020-01-17 23:18 +08:00 . Add accept4 fallback
#ifdef _WIN32
# include <ws2tcpip.h>
# include <windows.h>
# define MSG_NOSIGNAL 0
# define socklen_t _i32
#else
# include <signal.h>
# include <sys/socket.h>
# include <sys/types.h>
# include <poll.h>
# include <netinet/in.h>
# include <netinet/tcp.h>
# include <arpa/inet.h>
# include <netdb.h>
# include <unistd.h>
# include <fcntl.h>
# include <errno.h>
# define SOCKET_ERROR -1
# define closesocket close
# define SOCKET int
# define Sleep(x) usleep(x*1000)
#endif
#if defined(__sun__) || defined(__APPLE__)
# define MSG_NOSIGNAL 0
#endif
#ifdef SOCK_CLOEXEC
#ifndef VERSION
#include "config.h"
#endif
#ifdef HAVE_ACCEPT4
#define ACCEPT_CLOEXEC(sockfd, addr, addrlen) accept4_fb(sockfd, addr, addrlen, SOCK_CLOEXEC)
#else
#define EMULATE_ACCEPT_CLOEXEC
#endif
#else
#ifdef _WIN32
#define ACCEPT_CLOEXEC(sockfd, addr, addrlen) accept(sockfd, addr, addrlen)
#else
#define EMULATE_ACCEPT_CLOEXEC
#endif //!_WIN32
#endif //!SOCK_CLOEXEC
#ifdef EMULATE_ACCEPT_CLOEXEC
#ifndef ACCEPT_CLOEXEC_DEFINED
#define ACCEPT_CLOEXEC_DEFINED
namespace {
int ACCEPT_CLOEXEC(int sockfd, struct sockaddr *addr, socklen_t *addrlen) {
int rc = accept(sockfd, addr, addrlen);
if (rc) fcntl(rc, F_SETFD, fcntl(rc, F_GETFD, 0) | FD_CLOEXEC);
return rc;
}
}
#endif //ACCEPT_CLOEXEC_DEFINED
#endif //EMULATE_ACCEPT_CLOEXEC
#if !defined(EMULATE_ACCEPT_CLOEXEC) && defined(SOCK_CLOEXEC) && defined(HAVE_ACCEPT4) && !defined(ACCEPT_FB_DEFINED)
#define ACCEPT_FB_DEFINED
namespace {
int accept4_fb(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags)
{
int rc = accept4(sockfd, addr, addrlen, flags);
if (rc == -1 && errno == EINVAL)
{
rc = accept(sockfd, addr, addrlen);
if (rc) fcntl(rc, F_SETFD, fcntl(rc, F_GETFD, 0) | FD_CLOEXEC);
}
return rc;
}
}
#endif
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/wangcichen/urbackup_backend.git
git@gitee.com:wangcichen/urbackup_backend.git
wangcichen
urbackup_backend
urbackup_backend
dev

搜索帮助