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 WSAPoll 74 # define THRIFT_POLLFD pollfd 75 # define THRIFT_POLLIN POLLIN 76 # define THRIFT_POLLOUT POLLOUT 77 # define THRIFT_SHUT_RDWR SD_BOTH 78 # if !defined(AI_ADDRCONFIG) 79 # define AI_ADDRCONFIG 0x00000400 80 # endif 81 #else //not _WIN32 82 # include <errno.h> 83 # define THRIFT_GET_SOCKET_ERROR errno 84 # define THRIFT_ERRNO errno 85 # define THRIFT_EINTR EINTR 86 # define THRIFT_EINPROGRESS EINPROGRESS 87 # define THRIFT_ECONNRESET ECONNRESET 88 # define THRIFT_ENOTCONN ENOTCONN 89 # define THRIFT_ETIMEDOUT ETIMEDOUT 90 # define THRIFT_EWOULDBLOCK EWOULDBLOCK 91 # define THRIFT_EAGAIN EAGAIN 92 # define THRIFT_EPIPE EPIPE 93 # define THRIFT_NO_SOCKET_CACHING SO_REUSEADDR 94 # define THRIFT_SOCKET int 95 # define THRIFT_INVALID_SOCKET (-1) 96 # define THRIFT_SOCKETPAIR socketpair 97 # define THRIFT_FCNTL fcntl 98 # define THRIFT_O_NONBLOCK O_NONBLOCK 99 # define THRIFT_F_GETFL F_GETFL 100 # define THRIFT_F_SETFL F_SETFL 101 # define THRIFT_GETTIMEOFDAY gettimeofday 102 # define THRIFT_CLOSESOCKET close 103 # define THRIFT_CLOSE close 104 # define THRIFT_OPEN open 105 # define THRIFT_FTRUNCATE ftruncate 106 # define THRIFT_FSYNC fsync 107 # define THRIFT_LSEEK lseek 108 # define THRIFT_WRITE write 109 # define THRIFT_READ read 110 # define THRIFT_IOCTL_SOCKET ioctl 111 # define THRIFT_IOCTL_SOCKET_NUM_BYTES_TYPE int 112 # define THRIFT_STAT stat 113 # define THRIFT_FSTAT fstat 114 # define THRIFT_GAI_STRERROR gai_strerror 115 # define THRIFT_SSIZET ssize_t 116 # define THRIFT_SNPRINTF snprintf 117 # define THRIFT_SLEEP_SEC sleep 118 # define THRIFT_SLEEP_USEC usleep 119 # define THRIFT_TIMESPEC timespec 120 # define THRIFT_CTIME_R ctime_r 121 # define THRIFT_POLL poll 122 # define THRIFT_POLLFD pollfd 123 # define THRIFT_POLLIN POLLIN 124 # define THRIFT_POLLOUT POLLOUT 125 # define THRIFT_SHUT_RDWR SHUT_RDWR 126 #endif 127 128 #endif // _THRIFT_TRANSPORT_PLATFORM_SOCKET_H_ 129