blob: 95a5676ef5bc6dcc282ad43ca734e7a8d18be284 [file] [log] [blame]
Roger Meier84e4a3c2011-09-16 20:58:44 +00001/*
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 Meier8cd3b1a2011-09-23 14:25:22 +000031#pragma warning(disable: 4996) // Depreciated posix name.
32#pragma warning(disable: 4250) // Inherits via dominance.
Roger Meier12d70532011-12-14 23:35:28 +000033#pragma warning(disable: 4244) // conversion from '...' to '...', possible loss of data.
34#pragma warning(disable: 4267) // conversion from '...' to '...', possible loss of data.
Roger Meier8cd3b1a2011-09-23 14:25:22 +000035
Jake Farrell99010692011-11-30 02:09:46 +000036#define VERSION "0.9.0-dev"
Roger Meier8cd3b1a2011-09-23 14:25:22 +000037#define HAVE_GETTIMEOFDAY 1
Roger Meier3faaedf2011-10-02 10:51:45 +000038#define HAVE_SYS_STAT_H 1
Roger Meier8cd3b1a2011-09-23 14:25:22 +000039
Roger Meier84e4a3c2011-09-16 20:58:44 +000040#include "TargetVersion.h"
41#include "GetTimeOfDay.h"
42#include "Operators.h"
43#include "TWinsockSingleton.h"
Roger Meier878a9482011-10-11 19:02:37 +000044#include "WinFcntl.h"
Roger Meier84e4a3c2011-09-16 20:58:44 +000045#include "SocketPair.h"
46
47// boost
48#include <boost/cstdint.hpp>
49
50typedef boost::int64_t int64_t;
51typedef boost::uint32_t uint32_t;
52typedef boost::uint8_t uint8_t;
53
54// windows
55#include <Winsock2.h>
56#include <ws2tcpip.h>
57#pragma comment(lib, "Ws2_32.lib")
58
59// pthreads
Roger Meier3faaedf2011-10-02 10:51:45 +000060#if 0
61# include <pthread.h>
62#else
63struct timespec {
Roger Meier878a9482011-10-11 19:02:37 +000064 int64_t tv_sec;
65 int64_t tv_nsec;
Roger Meier3faaedf2011-10-02 10:51:45 +000066};
67# define USE_BOOST_THREAD 1
68# define ctime_r( _clock, _buf ) \
69 ( strcpy( (_buf), ctime( (_clock) ) ), \
70 (_buf) )
71#endif
Roger Meier84e4a3c2011-09-16 20:58:44 +000072
Roger Meier8cd3b1a2011-09-23 14:25:22 +000073typedef ptrdiff_t ssize_t;
Roger Meier84e4a3c2011-09-16 20:58:44 +000074
75// Missing functions.
76#define usleep(ms) Sleep(ms)
Roger Meier6c26fad2011-12-08 20:44:16 +000077inline int sleep(DWORD ms)
78{
79 Sleep(ms);
80 return 0;
81}
Roger Meier84e4a3c2011-09-16 20:58:44 +000082
Roger Meier3faaedf2011-10-02 10:51:45 +000083#if WINVER <= 0x0502
Roger Meier8cd3b1a2011-09-23 14:25:22 +000084#define poll(fds, nfds, timeout) \
85 poll_win32(fds, nfds, timeout)
86
87inline int poll_win32(LPWSAPOLLFD fdArray, ULONG fds, INT timeout)
88{
89 fd_set read_fds;
90 fd_set write_fds;
91 fd_set except_fds;
92
93 FD_ZERO(&read_fds);
94 FD_ZERO(&write_fds);
95 FD_ZERO(&except_fds);
96
97 FD_SET(fdArray[0].fd, &read_fds);
98 FD_SET(fdArray[0].fd, &write_fds);
99 FD_SET(fdArray[0].fd, &except_fds);
100
101 timeval time_out = {timeout * 0.001, timeout * 1000};
102 return select(1, &read_fds, &write_fds, &except_fds, &time_out);
103}
Roger Meier3faaedf2011-10-02 10:51:45 +0000104#else
Roger Meier878a9482011-10-11 19:02:37 +0000105 inline int poll(struct pollfd* fdArray, ULONG fds, INT timeout) {
106 return WSAPoll(fdArray, fds, timeout);
107 }
Roger Meier3faaedf2011-10-02 10:51:45 +0000108#endif // WINVER
Roger Meier84e4a3c2011-09-16 20:58:44 +0000109
Roger Meier12d70532011-12-14 23:35:28 +0000110inline int close(SOCKET socket)
Roger Meier84e4a3c2011-09-16 20:58:44 +0000111{
Roger Meier12d70532011-12-14 23:35:28 +0000112 return ::closesocket(socket);
Roger Meier84e4a3c2011-09-16 20:58:44 +0000113}
114
115#endif // _THRIFT_WINDOWS_CONFIG_H_