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_FSTAT _fstat
55# define THRIFT_STAT _stat
56# ifdef _WIN32_WCE
57# define THRIFT_GAI_STRERROR(...) thrift_wstr2str(gai_strerrorW(__VA_ARGS__))
58# else
59# define THRIFT_GAI_STRERROR gai_strerrorA
60# endif
61# define THRIFT_SSIZET ptrdiff_t
62# if (_MSC_VER < 1900)
63# define THRIFT_SNPRINTF _snprintf
64# else
65# define THRIFT_SNPRINTF snprintf
66# endif
67# define THRIFT_SLEEP_SEC thrift_sleep
68# define THRIFT_SLEEP_USEC thrift_usleep
69# define THRIFT_TIMESPEC thrift_timespec
70# define THRIFT_CTIME_R thrift_ctime_r
71# define THRIFT_POLL thrift_poll
72# if WINVER <= 0x0502 //XP, Server2003
73# define THRIFT_POLLFD thrift_pollfd
74# define THRIFT_POLLIN 0x0300
75# define THRIFT_POLLOUT 0x0010
76# else //Vista, Win7...
77# define THRIFT_POLLFD pollfd
78# define THRIFT_POLLIN POLLIN
79# define THRIFT_POLLOUT POLLOUT
80# endif //WINVER
81# define THRIFT_SHUT_RDWR SD_BOTH
82# if !defined(AI_ADDRCONFIG)
83# define AI_ADDRCONFIG 0x00000400
84# endif
85#else //not _WIN32
86# include <errno.h>
87# define THRIFT_GET_SOCKET_ERROR errno
88# define THRIFT_ERRNO errno
89# define THRIFT_EINTR EINTR
90# define THRIFT_EINPROGRESS EINPROGRESS
91# define THRIFT_ECONNRESET ECONNRESET
92# define THRIFT_ENOTCONN ENOTCONN
93# define THRIFT_ETIMEDOUT ETIMEDOUT
94# define THRIFT_EWOULDBLOCK EWOULDBLOCK
95# define THRIFT_EAGAIN EAGAIN
96# define THRIFT_EPIPE EPIPE
97# define THRIFT_NO_SOCKET_CACHING SO_REUSEADDR
98# define THRIFT_SOCKET int
99# define THRIFT_INVALID_SOCKET (-1)
100# define THRIFT_SOCKETPAIR socketpair
101# define THRIFT_FCNTL fcntl
102# define THRIFT_O_NONBLOCK O_NONBLOCK
103# define THRIFT_F_GETFL F_GETFL
104# define THRIFT_F_SETFL F_SETFL
105# define THRIFT_GETTIMEOFDAY gettimeofday
106# define THRIFT_CLOSESOCKET close
107# define THRIFT_CLOSE close
108# define THRIFT_OPEN open
109# define THRIFT_FTRUNCATE ftruncate
110# define THRIFT_FSYNC fsync
111# define THRIFT_LSEEK lseek
112# define THRIFT_WRITE write
113# define THRIFT_READ read
114# define THRIFT_STAT stat
115# define THRIFT_FSTAT fstat
116# define THRIFT_GAI_STRERROR gai_strerror
117# define THRIFT_SSIZET ssize_t
118# define THRIFT_SNPRINTF snprintf
119# define THRIFT_SLEEP_SEC sleep
120# define THRIFT_SLEEP_USEC usleep
121# define THRIFT_TIMESPEC timespec
122# define THRIFT_CTIME_R ctime_r
123# define THRIFT_POLL poll
124# define THRIFT_POLLFD pollfd
125# define THRIFT_POLLIN POLLIN
126# define THRIFT_POLLOUT POLLOUT
127# define THRIFT_SHUT_RDWR SHUT_RDWR
128#endif
129
130#endif // _THRIFT_TRANSPORT_PLATFORM_SOCKET_H_
131