Roger Meier | 84e4a3c | 2011-09-16 20:58:44 +0000 | [diff] [blame] | 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 | #ifndef _THRIFT_WINDOWS_CONFIG_H_ |
| 21 | #define _THRIFT_WINDOWS_CONFIG_H_ 1 |
| 22 | |
| 23 | #if defined(_MSC_VER) && (_MSC_VER > 1200) |
| 24 | #pragma once |
| 25 | #endif // _MSC_VER |
| 26 | |
| 27 | #ifndef _WIN32 |
| 28 | #error This is a MSVC header only. |
| 29 | #endif |
| 30 | |
Roger Meier | 8cd3b1a | 2011-09-23 14:25:22 +0000 | [diff] [blame] | 31 | #pragma warning(disable: 4996) // Depreciated posix name. |
| 32 | #pragma warning(disable: 4250) // Inherits via dominance. |
| 33 | |
Jake Farrell | 9901069 | 2011-11-30 02:09:46 +0000 | [diff] [blame] | 34 | #define VERSION "0.9.0-dev" |
Roger Meier | 8cd3b1a | 2011-09-23 14:25:22 +0000 | [diff] [blame] | 35 | #define HAVE_GETTIMEOFDAY 1 |
Roger Meier | 3faaedf | 2011-10-02 10:51:45 +0000 | [diff] [blame] | 36 | #define HAVE_SYS_STAT_H 1 |
Roger Meier | 8cd3b1a | 2011-09-23 14:25:22 +0000 | [diff] [blame] | 37 | |
Roger Meier | 84e4a3c | 2011-09-16 20:58:44 +0000 | [diff] [blame] | 38 | #include "TargetVersion.h" |
| 39 | #include "GetTimeOfDay.h" |
| 40 | #include "Operators.h" |
| 41 | #include "TWinsockSingleton.h" |
Roger Meier | 878a948 | 2011-10-11 19:02:37 +0000 | [diff] [blame] | 42 | #include "WinFcntl.h" |
Roger Meier | 84e4a3c | 2011-09-16 20:58:44 +0000 | [diff] [blame] | 43 | #include "SocketPair.h" |
| 44 | |
| 45 | // boost |
| 46 | #include <boost/cstdint.hpp> |
| 47 | |
| 48 | typedef boost::int64_t int64_t; |
| 49 | typedef boost::uint32_t uint32_t; |
| 50 | typedef boost::uint8_t uint8_t; |
| 51 | |
| 52 | // windows |
| 53 | #include <Winsock2.h> |
| 54 | #include <ws2tcpip.h> |
| 55 | #pragma comment(lib, "Ws2_32.lib") |
| 56 | |
| 57 | // pthreads |
Roger Meier | 3faaedf | 2011-10-02 10:51:45 +0000 | [diff] [blame] | 58 | #if 0 |
| 59 | # include <pthread.h> |
| 60 | #else |
| 61 | struct timespec { |
Roger Meier | 878a948 | 2011-10-11 19:02:37 +0000 | [diff] [blame] | 62 | int64_t tv_sec; |
| 63 | int64_t tv_nsec; |
Roger Meier | 3faaedf | 2011-10-02 10:51:45 +0000 | [diff] [blame] | 64 | }; |
| 65 | # define USE_BOOST_THREAD 1 |
| 66 | # define ctime_r( _clock, _buf ) \ |
| 67 | ( strcpy( (_buf), ctime( (_clock) ) ), \ |
| 68 | (_buf) ) |
| 69 | #endif |
Roger Meier | 84e4a3c | 2011-09-16 20:58:44 +0000 | [diff] [blame] | 70 | |
Roger Meier | 8cd3b1a | 2011-09-23 14:25:22 +0000 | [diff] [blame] | 71 | typedef ptrdiff_t ssize_t; |
Roger Meier | 84e4a3c | 2011-09-16 20:58:44 +0000 | [diff] [blame] | 72 | |
| 73 | // Missing functions. |
| 74 | #define usleep(ms) Sleep(ms) |
Roger Meier | 6c26fad | 2011-12-08 20:44:16 +0000 | [diff] [blame^] | 75 | inline int sleep(DWORD ms) |
| 76 | { |
| 77 | Sleep(ms); |
| 78 | return 0; |
| 79 | } |
Roger Meier | 84e4a3c | 2011-09-16 20:58:44 +0000 | [diff] [blame] | 80 | |
Roger Meier | 3faaedf | 2011-10-02 10:51:45 +0000 | [diff] [blame] | 81 | #if WINVER <= 0x0502 |
Roger Meier | 8cd3b1a | 2011-09-23 14:25:22 +0000 | [diff] [blame] | 82 | #define poll(fds, nfds, timeout) \ |
| 83 | poll_win32(fds, nfds, timeout) |
| 84 | |
| 85 | inline int poll_win32(LPWSAPOLLFD fdArray, ULONG fds, INT timeout) |
| 86 | { |
| 87 | fd_set read_fds; |
| 88 | fd_set write_fds; |
| 89 | fd_set except_fds; |
| 90 | |
| 91 | FD_ZERO(&read_fds); |
| 92 | FD_ZERO(&write_fds); |
| 93 | FD_ZERO(&except_fds); |
| 94 | |
| 95 | FD_SET(fdArray[0].fd, &read_fds); |
| 96 | FD_SET(fdArray[0].fd, &write_fds); |
| 97 | FD_SET(fdArray[0].fd, &except_fds); |
| 98 | |
| 99 | timeval time_out = {timeout * 0.001, timeout * 1000}; |
| 100 | return select(1, &read_fds, &write_fds, &except_fds, &time_out); |
| 101 | } |
Roger Meier | 3faaedf | 2011-10-02 10:51:45 +0000 | [diff] [blame] | 102 | #else |
Roger Meier | 878a948 | 2011-10-11 19:02:37 +0000 | [diff] [blame] | 103 | inline int poll(struct pollfd* fdArray, ULONG fds, INT timeout) { |
| 104 | return WSAPoll(fdArray, fds, timeout); |
| 105 | } |
Roger Meier | 3faaedf | 2011-10-02 10:51:45 +0000 | [diff] [blame] | 106 | #endif // WINVER |
Roger Meier | 84e4a3c | 2011-09-16 20:58:44 +0000 | [diff] [blame] | 107 | |
| 108 | inline void close(SOCKET socket) |
| 109 | { |
| 110 | ::closesocket(socket); |
| 111 | } |
| 112 | |
| 113 | #endif // _THRIFT_WINDOWS_CONFIG_H_ |