1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20// clang-format off
21
22#ifndef _THRIFT_TRANSPORT_PLATFORM_SOCKET_H_
23# define _THRIFT_TRANSPORT_PLATFORM_SOCKET_H_
24
25#ifdef _WIN32
26# include <winsock2.h>
27# define THRIFT_GET_SOCKET_ERROR ::WSAGetLastError()
28# define THRIFT_ERRNO (*_errno())
29# define THRIFT_EINPROGRESS WSAEINPROGRESS
30# define THRIFT_EAGAIN WSAEWOULDBLOCK
31# define THRIFT_EINTR WSAEINTR
32# define THRIFT_ECONNRESET WSAECONNRESET
33# define THRIFT_ENOTCONN WSAENOTCONN
34# define THRIFT_ETIMEDOUT WSAETIMEDOUT
35# define THRIFT_EWOULDBLOCK WSAEWOULDBLOCK
36# define THRIFT_EPIPE WSAECONNRESET
37# define THRIFT_NO_SOCKET_CACHING SO_EXCLUSIVEADDRUSE
38# define THRIFT_SOCKET SOCKET
39# define THRIFT_INVALID_SOCKET INVALID_SOCKET
40# define THRIFT_SOCKETPAIR thrift_socketpair
41# define THRIFT_FCNTL thrift_fcntl
42# define THRIFT_O_NONBLOCK 1
43# define THRIFT_F_GETFL 0
44# define THRIFT_F_SETFL 1
45# define THRIFT_GETTIMEOFDAY thrift_gettimeofday
46# define THRIFT_CLOSESOCKET closesocket
47# define THRIFT_CLOSE _close
48# define THRIFT_OPEN _open
49# define THRIFT_FTRUNCATE _chsize_s
50# define THRIFT_FSYNC _commit
51# define THRIFT_LSEEK _lseek
52# define THRIFT_WRITE _write
53# define THRIFT_READ _read
54# define THRIFT_IOCTL_SOCKET ioctlsocket
55# define THRIFT_IOCTL_SOCKET_NUM_BYTES_TYPE u_long
56# define THRIFT_FSTAT _fstat
57# define THRIFT_STAT _stat
58# ifdef _WIN32_WCE
59# define THRIFT_GAI_STRERROR(...) thrift_wstr2str(gai_strerrorW(__VA_ARGS__))
60# else
61# define THRIFT_GAI_STRERROR gai_strerrorA
62# endif
63# define THRIFT_SSIZET ptrdiff_t
64# if (_MSC_VER < 1900)
65# define THRIFT_SNPRINTF _snprintf
66# else
67# define THRIFT_SNPRINTF snprintf
68# endif
69# define THRIFT_SLEEP_SEC thrift_sleep
70# define THRIFT_SLEEP_USEC thrift_usleep
71# define THRIFT_TIMESPEC thrift_timespec
72# define THRIFT_CTIME_R thrift_ctime_r
73# define THRIFT_POLL thrift_poll
74# if WINVER <= 0x0502 //XP, Server2003
75# define THRIFT_POLLFD thrift_pollfd
76# define THRIFT_POLLIN 0x0300
77# define THRIFT_POLLOUT 0x0010
78# else //Vista, Win7...
79# define THRIFT_POLLFD pollfd
80# define THRIFT_POLLIN POLLIN
81# define THRIFT_POLLOUT POLLOUT
82# endif //WINVER
83# define THRIFT_SHUT_RDWR SD_BOTH
84# if !defined(AI_ADDRCONFIG)
85# define AI_ADDRCONFIG 0x00000400
86# endif
87#else //not _WIN32
88# include <errno.h>
89# define THRIFT_GET_SOCKET_ERROR errno
90# define THRIFT_ERRNO errno
91# define THRIFT_EINTR EINTR
92# define THRIFT_EINPROGRESS EINPROGRESS
93# define THRIFT_ECONNRESET ECONNRESET
94# define THRIFT_ENOTCONN ENOTCONN
95# define THRIFT_ETIMEDOUT ETIMEDOUT
96# define THRIFT_EWOULDBLOCK EWOULDBLOCK
97# define THRIFT_EAGAIN EAGAIN
98# define THRIFT_EPIPE EPIPE
99# define THRIFT_NO_SOCKET_CACHING SO_REUSEADDR
100# define THRIFT_SOCKET int
101# define THRIFT_INVALID_SOCKET (-1)
102# define THRIFT_SOCKETPAIR socketpair
103# define THRIFT_FCNTL fcntl
104# define THRIFT_O_NONBLOCK O_NONBLOCK
105# define THRIFT_F_GETFL F_GETFL
106# define THRIFT_F_SETFL F_SETFL
107# define THRIFT_GETTIMEOFDAY gettimeofday
108# define THRIFT_CLOSESOCKET close
109# define THRIFT_CLOSE close
110# define THRIFT_OPEN open
111# define THRIFT_FTRUNCATE ftruncate
112# define THRIFT_FSYNC fsync
113# define THRIFT_LSEEK lseek
114# define THRIFT_WRITE write
115# define THRIFT_READ read
116# define THRIFT_IOCTL_SOCKET ioctl
117# define THRIFT_IOCTL_SOCKET_NUM_BYTES_TYPE int
118# define THRIFT_STAT stat
119# define THRIFT_FSTAT fstat
120# define THRIFT_GAI_STRERROR gai_strerror
121# define THRIFT_SSIZET ssize_t
122# define THRIFT_SNPRINTF snprintf
123# define THRIFT_SLEEP_SEC sleep
124# define THRIFT_SLEEP_USEC usleep
125# define THRIFT_TIMESPEC timespec
126# define THRIFT_CTIME_R ctime_r
127# define THRIFT_POLL poll
128# define THRIFT_POLLFD pollfd
129# define THRIFT_POLLIN POLLIN
130# define THRIFT_POLLOUT POLLOUT
131# define THRIFT_SHUT_RDWR SHUT_RDWR
132#endif
133
134#endif // _THRIFT_TRANSPORT_PLATFORM_SOCKET_H_
135