#pragma once
#include <cstdint>
#include <folly/Portability.h>
#include <folly/net/NetworkSocket.h>
#include <folly/portability/IOVec.h>
#include <folly/portability/SysTypes.h>
#include <folly/portability/Time.h>
#include <folly/portability/Windows.h>
#ifdef _WIN32
#include <WS2tcpip.h>
using nfds_t = int;
using sa_family_t = ADDRESS_FAMILY;
#define SO_EE_ORIGIN_ZEROCOPY …
#define SO_ZEROCOPY …
#define SO_TXTIME …
#define MSG_ZEROCOPY …
#define SOL_UDP …
#define UDP_SEGMENT …
#define IP_BIND_ADDRESS_NO_PORT …
#define TCP_ZEROCOPY_RECEIVE …
#define MSG_DONTWAIT …
#define MSG_EOR …
struct msghdr {
void* msg_name;
socklen_t msg_namelen;
struct iovec* msg_iov;
size_t msg_iovlen;
void* msg_control;
size_t msg_controllen;
int msg_flags;
};
struct mmsghdr {
struct msghdr msg_hdr;
unsigned int msg_len;
};
struct sockaddr_un {
sa_family_t sun_family;
char sun_path[108];
};
#define SHUT_RD …
#define SHUT_WR …
#define SHUT_RDWR …
#define AF_LOCAL …
#define PF_LOCAL …
#define SO_REUSEPORT …
#undef s_host
#else
#if defined(__EMSCRIPTEN__)
#include <sys/types.h>
#endif
#include <netdb.h>
#include <poll.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <netinet/udp.h>
#include <sys/socket.h>
#include <sys/un.h>
#if !defined(__EMSCRIPTEN__)
#ifdef MSG_ERRQUEUE
#define FOLLY_HAVE_MSG_ERRQUEUE …
#ifdef SCM_TIMESTAMPING
#ifndef FOLLY_HAVE_SO_TIMESTAMPING
#define FOLLY_HAVE_SO_TIMESTAMPING …
#endif
#ifndef TCP_ZEROCOPY_RECEIVE
#define TCP_ZEROCOPY_RECEIVE …
#endif
#else
#ifndef TCP_ZEROCOPY_RECEIVE
#define TCP_ZEROCOPY_RECEIVE …
#endif
#endif
#include <linux/errqueue.h>
#endif
#endif
#ifndef SO_EE_ORIGIN_ZEROCOPY
#define SO_EE_ORIGIN_ZEROCOPY …
#endif
#ifndef SO_EE_CODE_ZEROCOPY_COPIED
#define SO_EE_CODE_ZEROCOPY_COPIED …
#endif
#ifndef SO_ZEROCOPY
#define SO_ZEROCOPY …
#endif
#ifndef SO_TXTIME
#define SO_TXTIME …
#define SCM_TXTIME …
#endif
#ifdef FOLLY_HAVE_MSG_ERRQUEUE
namespace folly {
namespace netops {
enum txtime_flags {
SOF_TXTIME_DEADLINE_MODE = (1 << 0),
SOF_TXTIME_REPORT_ERRORS = (1 << 1),
SOF_TXTIME_FLAGS_LAST = SOF_TXTIME_REPORT_ERRORS,
SOF_TXTIME_FLAGS_MASK = (SOF_TXTIME_FLAGS_LAST - 1) | SOF_TXTIME_FLAGS_LAST
};
enum timestamping_flags {
SOF_TIMESTAMPING_TX_HARDWARE = (1 << 0),
SOF_TIMESTAMPING_TX_SOFTWARE = (1 << 1),
SOF_TIMESTAMPING_RX_HARDWARE = (1 << 2),
SOF_TIMESTAMPING_RX_SOFTWARE = (1 << 3),
SOF_TIMESTAMPING_SOFTWARE = (1 << 4),
SOF_TIMESTAMPING_SYS_HARDWARE = (1 << 5),
SOF_TIMESTAMPING_RAW_HARDWARE = (1 << 6),
SOF_TIMESTAMPING_OPT_ID = (1 << 7),
SOF_TIMESTAMPING_TX_SCHED = (1 << 8),
SOF_TIMESTAMPING_TX_ACK = (1 << 9),
SOF_TIMESTAMPING_OPT_CMSG = (1 << 10),
SOF_TIMESTAMPING_OPT_TSONLY = (1 << 11),
SOF_TIMESTAMPING_OPT_STATS = (1 << 12),
SOF_TIMESTAMPING_OPT_PKTINFO = (1 << 13),
SOF_TIMESTAMPING_OPT_TX_SWHW = (1 << 14),
SOF_TIMESTAMPING_LAST = SOF_TIMESTAMPING_OPT_TX_SWHW,
SOF_TIMESTAMPING_MASK = (SOF_TIMESTAMPING_LAST - 1) | SOF_TIMESTAMPING_LAST
};
enum tstamp_flags {
SCM_TSTAMP_SND,
SCM_TSTAMP_SCHED,
SCM_TSTAMP_ACK,
};
struct sock_txtime {
__kernel_clockid_t clockid;
__u32 flags;
};
struct tcp_zerocopy_receive {
__u64 address;
__u32 length;
__u32 recv_skip_hint;
__u32 inq;
__s32 err;
__u64 copybuf_address;
__s32 copybuf_len;
__u32 flags;
__u64 msg_control;
__u64 msg_controllen;
__u32 msg_flags;
__u32 reserved;
};
}
}
#endif
#ifndef MSG_ZEROCOPY
#define MSG_ZEROCOPY …
#endif
#ifndef SOL_UDP
#define SOL_UDP …
#endif
#ifndef ETH_MAX_MTU
#define ETH_MAX_MTU …
#endif
#ifndef UDP_NO_CHECK6_TX
#define UDP_NO_CHECK6_TX …
#endif
#ifndef UDP_NO_CHECK6_RX
#define UDP_NO_CHECK6_RX …
#endif
#ifndef UDP_SEGMENT
#define UDP_SEGMENT …
#endif
#ifndef UDP_GRO
#define UDP_GRO …
#endif
#ifndef UDP_MAX_SEGMENTS
#define UDP_MAX_SEGMENTS …
#endif
#if !defined(MSG_WAITFORONE) && !defined(__wasm32__)
struct mmsghdr { … };
#endif
#ifndef IP_BIND_ADDRESS_NO_PORT
#define IP_BIND_ADDRESS_NO_PORT …
#endif
#endif
#ifdef _WIN32
#define XPLAT_MSGHDR …
#define XPLAT_CMSGHDR …
#define F_CMSG_LEN …
#define F_COPY_CMSG_INT_DATA …
#else
#define XPLAT_MSGHDR …
#define XPLAT_CMSGHDR …
#define F_CMSG_LEN …
#define F_COPY_CMSG_INT_DATA(cm, val, len) …
#endif
namespace folly {
namespace netops {
struct PollDescriptor { … };
class Msgheader { … };
NetworkSocket accept(NetworkSocket s, sockaddr* addr, socklen_t* addrlen);
int bind(NetworkSocket s, const sockaddr* name, socklen_t namelen);
int close(NetworkSocket s);
int connect(NetworkSocket s, const sockaddr* name, socklen_t namelen);
int getpeername(NetworkSocket s, sockaddr* name, socklen_t* namelen);
int getsockname(NetworkSocket s, sockaddr* name, socklen_t* namelen);
int getsockopt(
NetworkSocket s, int level, int optname, void* optval, socklen_t* optlen);
int inet_aton(const char* cp, in_addr* inp);
int listen(NetworkSocket s, int backlog);
int poll(PollDescriptor fds[], nfds_t nfds, int timeout);
ssize_t recv(NetworkSocket s, void* buf, size_t len, int flags);
ssize_t recvfrom(
NetworkSocket s,
void* buf,
size_t len,
int flags,
sockaddr* from,
socklen_t* fromlen);
ssize_t recvmsg(NetworkSocket s, msghdr* message, int flags);
int recvmmsg(
NetworkSocket s,
mmsghdr* msgvec,
unsigned int vlen,
unsigned int flags,
timespec* timeout);
#ifdef _WIN32
ssize_t wsaRecvMesg(NetworkSocket s, WSAMSG* wsaMsg);
#endif
ssize_t send(NetworkSocket s, const void* buf, size_t len, int flags);
ssize_t sendto(
NetworkSocket s,
const void* buf,
size_t len,
int flags,
const sockaddr* to,
socklen_t tolen);
ssize_t sendmsg(NetworkSocket socket, const msghdr* message, int flags);
#ifdef _WIN32
ssize_t wsaSendMsgDirect(NetworkSocket socket, WSAMSG* msg);
#endif
int sendmmsg(
NetworkSocket socket, mmsghdr* msgvec, unsigned int vlen, int flags);
int setsockopt(
NetworkSocket s,
int level,
int optname,
const void* optval,
socklen_t optlen);
int shutdown(NetworkSocket s, int how);
NetworkSocket socket(int af, int type, int protocol);
int socketpair(int domain, int type, int protocol, NetworkSocket sv[2]);
int set_socket_non_blocking(NetworkSocket s);
int set_socket_close_on_exec(NetworkSocket s);
#ifdef _WIN32
typedef int (*wsa_error_translator_ptr)(
NetworkSocket socket, intptr_t api, intptr_t ret, int wsa_error);
void set_wsa_error_translator(
wsa_error_translator_ptr translator, wsa_error_translator_ptr* previousOut);
#endif
}
}