summaryrefslogtreecommitdiff
path: root/lib/cpp/src/thrift/windows
diff options
context:
space:
mode:
authorKonrad Grochowski <hcorg@apache.org>2014-11-13 15:33:38 +0100
committerKonrad Grochowski <hcorg@apache.org>2014-11-18 10:02:08 +0100
commit74260aa9099c3bb209bc8e524b0e8ba603f62c41 (patch)
tree07ff24e0bed1f74da57e56feb38ea6bae063629c /lib/cpp/src/thrift/windows
parentca7e97e0423e785bd7a6b7b8400e67897975e7f6 (diff)
downloadthrift-74260aa9099c3bb209bc8e524b0e8ba603f62c41.tar.gz
THRIFT-2729: C++ - .clang-format created and applied
Client: C++ Patch: Konrad Grochowski make style command added
Diffstat (limited to 'lib/cpp/src/thrift/windows')
-rw-r--r--lib/cpp/src/thrift/windows/GetTimeOfDay.cpp116
-rw-r--r--lib/cpp/src/thrift/windows/GetTimeOfDay.h4
-rw-r--r--lib/cpp/src/thrift/windows/Operators.h16
-rw-r--r--lib/cpp/src/thrift/windows/OverlappedSubmissionThread.cpp99
-rw-r--r--lib/cpp/src/thrift/windows/OverlappedSubmissionThread.h38
-rw-r--r--lib/cpp/src/thrift/windows/SocketPair.cpp108
-rw-r--r--lib/cpp/src/thrift/windows/Sync.h36
-rw-r--r--lib/cpp/src/thrift/windows/TWinsockSingleton.cpp48
-rw-r--r--lib/cpp/src/thrift/windows/TWinsockSingleton.h34
-rw-r--r--lib/cpp/src/thrift/windows/WinFcntl.cpp80
-rw-r--r--lib/cpp/src/thrift/windows/WinFcntl.h10
-rw-r--r--lib/cpp/src/thrift/windows/config.h48
12 files changed, 302 insertions, 335 deletions
diff --git a/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp b/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp
index c5667e422..654d00592 100644
--- a/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp
+++ b/lib/cpp/src/thrift/windows/GetTimeOfDay.cpp
@@ -24,89 +24,73 @@
#include <time.h>
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
-# define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
+#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
-# define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
+#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif
-struct timezone
-{
- int tz_minuteswest; /* minutes W of Greenwich */
- int tz_dsttime; /* type of dst correction */
+struct timezone {
+ int tz_minuteswest; /* minutes W of Greenwich */
+ int tz_dsttime; /* type of dst correction */
};
-int thrift_gettimeofday(struct timeval * tv, struct timezone * tz)
-{
- FILETIME ft;
- unsigned __int64 tmpres(0);
- static int tzflag;
-
- if (NULL != tv)
- {
- GetSystemTimeAsFileTime(&ft);
-
- tmpres |= ft.dwHighDateTime;
- tmpres <<= 32;
- tmpres |= ft.dwLowDateTime;
-
- /*converting file time to unix epoch*/
- tmpres -= DELTA_EPOCH_IN_MICROSECS;
- tmpres /= 10; /*convert into microseconds*/
- tv->tv_sec = (long)(tmpres / 1000000UL);
- tv->tv_usec = (long)(tmpres % 1000000UL);
+int thrift_gettimeofday(struct timeval* tv, struct timezone* tz) {
+ FILETIME ft;
+ unsigned __int64 tmpres(0);
+ static int tzflag;
+
+ if (NULL != tv) {
+ GetSystemTimeAsFileTime(&ft);
+
+ tmpres |= ft.dwHighDateTime;
+ tmpres <<= 32;
+ tmpres |= ft.dwLowDateTime;
+
+ /*converting file time to unix epoch*/
+ tmpres -= DELTA_EPOCH_IN_MICROSECS;
+ tmpres /= 10; /*convert into microseconds*/
+ tv->tv_sec = (long)(tmpres / 1000000UL);
+ tv->tv_usec = (long)(tmpres % 1000000UL);
+ }
+
+ if (NULL != tz) {
+ if (!tzflag) {
+ _tzset();
+ tzflag++;
}
- if (NULL != tz)
- {
- if (!tzflag)
- {
- _tzset();
- tzflag++;
- }
-
- long time_zone(0);
- errno_t err(_get_timezone(&time_zone));
- if (err == NO_ERROR)
- {
- tz->tz_minuteswest = time_zone / 60;
- }
- else
- {
- return -1;
- }
+ long time_zone(0);
+ errno_t err(_get_timezone(&time_zone));
+ if (err == NO_ERROR) {
+ tz->tz_minuteswest = time_zone / 60;
+ } else {
+ return -1;
+ }
- int day_light(0);
- err = (_get_daylight(&day_light));
- if (err == NO_ERROR)
- {
- tz->tz_dsttime = day_light;
- return 0;
- }
- else
- {
- return -1;
- }
+ int day_light(0);
+ err = (_get_daylight(&day_light));
+ if (err == NO_ERROR) {
+ tz->tz_dsttime = day_light;
+ return 0;
+ } else {
+ return -1;
}
+ }
- return 0;
+ return 0;
}
-int thrift_sleep(unsigned int seconds)
-{
+int thrift_sleep(unsigned int seconds) {
::Sleep(seconds * 1000);
return 0;
}
-int thrift_usleep(unsigned int microseconds)
-{
- unsigned int milliseconds = (microseconds + 999)/ 1000;
+int thrift_usleep(unsigned int microseconds) {
+ unsigned int milliseconds = (microseconds + 999) / 1000;
::Sleep(milliseconds);
return 0;
}
-char *thrift_ctime_r(const time_t *_clock, char *_buf)
-{
- strcpy(_buf, ctime(_clock));
- return _buf;
+char* thrift_ctime_r(const time_t* _clock, char* _buf) {
+ strcpy(_buf, ctime(_clock));
+ return _buf;
}
-
-
diff --git a/lib/cpp/src/thrift/windows/GetTimeOfDay.h b/lib/cpp/src/thrift/windows/GetTimeOfDay.h
index 27b8a841d..6e90ba183 100644
--- a/lib/cpp/src/thrift/windows/GetTimeOfDay.h
+++ b/lib/cpp/src/thrift/windows/GetTimeOfDay.h
@@ -35,9 +35,9 @@ struct thrift_timespec {
int64_t tv_nsec;
};
-int thrift_gettimeofday(struct timeval * tv, struct timezone * tz);
+int thrift_gettimeofday(struct timeval* tv, struct timezone* tz);
int thrift_sleep(unsigned int seconds);
int thrift_usleep(unsigned int micro_seconds);
-char *thrift_ctime_r(const time_t *_clock, char *_buf);
+char* thrift_ctime_r(const time_t* _clock, char* _buf);
#endif // _THRIFT_WINDOWS_GETTIMEOFDAY_H_
diff --git a/lib/cpp/src/thrift/windows/Operators.h b/lib/cpp/src/thrift/windows/Operators.h
index 95d8e3e8f..9b8609680 100644
--- a/lib/cpp/src/thrift/windows/Operators.h
+++ b/lib/cpp/src/thrift/windows/Operators.h
@@ -24,17 +24,17 @@
#pragma once
#endif // _MSC_VER
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
class TEnumIterator;
-inline bool operator == (const TEnumIterator&, const TEnumIterator&)
-{
- // Not entirely sure what the test should be here. It is only to enable
- // iterator debugging and is not used in release mode.
- return true;
+inline bool operator==(const TEnumIterator&, const TEnumIterator&) {
+ // Not entirely sure what the test should be here. It is only to enable
+ // iterator debugging and is not used in release mode.
+ return true;
}
-
-}} // apache::thrift
+}
+} // apache::thrift
#endif // _THRIFT_WINDOWS_OPERATORS_H_
diff --git a/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.cpp b/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.cpp
index 5dec390f0..5ac6fe00b 100644
--- a/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.cpp
+++ b/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.cpp
@@ -23,21 +23,23 @@
#include <boost/scope_exit.hpp>
#include <process.h>
-namespace apache { namespace thrift { namespace transport {
-
-TOverlappedWorkItem::TOverlappedWorkItem() :
- SLIST_ENTRY(),
- action(UNKNOWN),
- h(INVALID_HANDLE_VALUE),
- buffer(NULL),
- buffer_len(0),
- overlap(),
- last_error(0),
- success(TRUE)
-{}
+namespace apache {
+namespace thrift {
+namespace transport {
+
+TOverlappedWorkItem::TOverlappedWorkItem()
+ : SLIST_ENTRY(),
+ action(UNKNOWN),
+ h(INVALID_HANDLE_VALUE),
+ buffer(NULL),
+ buffer_len(0),
+ overlap(),
+ last_error(0),
+ success(TRUE) {
+}
-void TOverlappedWorkItem::reset(uint8_t *buf, uint32_t len, HANDLE event) {
- memset( &overlap, 0, sizeof(overlap));
+void TOverlappedWorkItem::reset(uint8_t* buf, uint32_t len, HANDLE event) {
+ memset(&overlap, 0, sizeof(overlap));
overlap.hEvent = event;
buffer = buf;
buffer_len = len;
@@ -48,7 +50,7 @@ void TOverlappedWorkItem::reset(uint8_t *buf, uint32_t len, HANDLE event) {
uint32_t TOverlappedWorkItem::overlappedResults(bool signal_failure) {
DWORD bytes = 0;
BOOL result = ::GetOverlappedResult(h, &overlap, &bytes, TRUE);
- if(signal_failure && !result) //get overlapped error case
+ if (signal_failure && !result) // get overlapped error case
{
GlobalOutput.perror("TPipe ::GetOverlappedResult errored GLE=", ::GetLastError());
throw TTransportException(TTransportException::UNKNOWN, "TPipe: GetOverlappedResult failed");
@@ -57,42 +59,40 @@ uint32_t TOverlappedWorkItem::overlappedResults(bool signal_failure) {
}
bool TOverlappedWorkItem::process() {
- BOOST_SCOPE_EXIT( (&doneSubmittingEvent) ) {
- SetEvent(doneSubmittingEvent.h);
- } BOOST_SCOPE_EXIT_END
+ BOOST_SCOPE_EXIT((&doneSubmittingEvent)) { SetEvent(doneSubmittingEvent.h); }
+ BOOST_SCOPE_EXIT_END
- switch(action) {
- case(CONNECT):
+ switch (action) {
+ case (CONNECT):
success = ::ConnectNamedPipe(h, &overlap);
- if(success == FALSE)
+ if (success == FALSE)
last_error = ::GetLastError();
return true;
- case(READ):
+ case (READ):
success = ::ReadFile(h, buffer, buffer_len, NULL, &overlap);
- if(success == FALSE)
+ if (success == FALSE)
last_error = ::GetLastError();
return true;
- case(CANCELIO):
+ case (CANCELIO):
success = ::CancelIo(h);
- if(success == FALSE)
+ if (success == FALSE)
last_error = ::GetLastError();
return true;
- case(STOP):
+ case (STOP):
default:
return false;
}
}
-void TOverlappedSubmissionThread::addWorkItem(TOverlappedWorkItem *item) {
+void TOverlappedSubmissionThread::addWorkItem(TOverlappedWorkItem* item) {
InterlockedPushEntrySList(&workList_, item);
SetEvent(workAvailableEvent_.h);
WaitForSingleObject(item->doneSubmittingEvent.h, INFINITE);
}
-TOverlappedSubmissionThread *TOverlappedSubmissionThread::acquire_instance() {
+TOverlappedSubmissionThread* TOverlappedSubmissionThread::acquire_instance() {
TAutoCrit lock(instanceGuard_);
- if(instance_ == NULL)
- {
+ if (instance_ == NULL) {
assert(instanceRefCount_ == 0);
instance_ = new TOverlappedSubmissionThread;
}
@@ -101,8 +101,7 @@ TOverlappedSubmissionThread *TOverlappedSubmissionThread::acquire_instance() {
}
void TOverlappedSubmissionThread::release_instance() {
TAutoCrit lock(instanceGuard_);
- if(--instanceRefCount_ == 0)
- {
+ if (--instanceRefCount_ == 0) {
delete instance_;
instance_ = NULL;
}
@@ -112,16 +111,11 @@ TOverlappedSubmissionThread::TOverlappedSubmissionThread() {
stopItem_.action = TOverlappedWorkItem::STOP;
InitializeSListHead(&workList_);
- thread_ = (HANDLE)_beginthreadex(
- NULL,
- 0,
- thread_proc,
- this,
- 0,
- NULL);
- if(thread_ == 0) {
+ thread_ = (HANDLE)_beginthreadex(NULL, 0, thread_proc, this, 0, NULL);
+ if (thread_ == 0) {
GlobalOutput.perror("TOverlappedSubmissionThread unable to create thread, errno=", errno);
- throw TTransportException(TTransportException::NOT_OPEN, " TOverlappedSubmissionThread unable to create thread");
+ throw TTransportException(TTransportException::NOT_OPEN,
+ " TOverlappedSubmissionThread unable to create thread");
}
}
@@ -132,25 +126,26 @@ TOverlappedSubmissionThread::~TOverlappedSubmissionThread() {
}
void TOverlappedSubmissionThread::run() {
- for(;;) {
+ for (;;) {
WaitForSingleObject(workAvailableEvent_.h, INFINITE);
- //todo check result
- SLIST_ENTRY *entry = NULL;
- while( (entry = InterlockedPopEntrySList(&workList_)) != NULL) {
- TOverlappedWorkItem &item = *static_cast<TOverlappedWorkItem *>(entry);
- if(!item.process())
+ // todo check result
+ SLIST_ENTRY* entry = NULL;
+ while ((entry = InterlockedPopEntrySList(&workList_)) != NULL) {
+ TOverlappedWorkItem& item = *static_cast<TOverlappedWorkItem*>(entry);
+ if (!item.process())
return;
}
}
}
-unsigned __stdcall TOverlappedSubmissionThread::thread_proc(void *addr) {
- static_cast<TOverlappedSubmissionThread *>(addr)->run();
+unsigned __stdcall TOverlappedSubmissionThread::thread_proc(void* addr) {
+ static_cast<TOverlappedSubmissionThread*>(addr)->run();
return 0;
}
TCriticalSection TOverlappedSubmissionThread::instanceGuard_;
TOverlappedSubmissionThread* TOverlappedSubmissionThread::instance_;
-uint32_t TOverlappedSubmissionThread::instanceRefCount_=0;
-
-}}} //apach::thrift::transport
+uint32_t TOverlappedSubmissionThread::instanceRefCount_ = 0;
+}
+}
+} // apach::thrift::transport
diff --git a/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.h b/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.h
index 16b7e24b6..56684bb9b 100644
--- a/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.h
+++ b/lib/cpp/src/thrift/windows/OverlappedSubmissionThread.h
@@ -59,13 +59,15 @@
until the operation has completed.
*/
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) struct TOverlappedWorkItem : public SLIST_ENTRY {
TOverlappedWorkItem();
enum action_t {
- UNKNOWN = 3000,
+ UNKNOWN = 3000,
CONNECT,
READ,
CANCELIO,
@@ -75,38 +77,38 @@ DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) struct TOverlappedWorkItem : public
TAutoResetEvent doneSubmittingEvent;
action_t action;
HANDLE h;
- uint8_t *buffer;
+ uint8_t* buffer;
uint32_t buffer_len;
OVERLAPPED overlap;
DWORD last_error;
BOOL success;
- void reset(uint8_t *buf, uint32_t len, HANDLE event);
+ void reset(uint8_t* buf, uint32_t len, HANDLE event);
uint32_t overlappedResults(bool signal_failure = true);
bool process();
};
-class TOverlappedSubmissionThread : boost::noncopyable
-{
+class TOverlappedSubmissionThread : boost::noncopyable {
public:
- void addWorkItem(TOverlappedWorkItem *item);
+ void addWorkItem(TOverlappedWorkItem* item);
-//singleton stuff
+ // singleton stuff
public:
- static TOverlappedSubmissionThread *acquire_instance();
+ static TOverlappedSubmissionThread* acquire_instance();
static void release_instance();
+
private:
static TCriticalSection instanceGuard_;
- static TOverlappedSubmissionThread *instance_;
+ static TOverlappedSubmissionThread* instance_;
static uint32_t instanceRefCount_;
-//thread details
+ // thread details
private:
TOverlappedSubmissionThread();
~TOverlappedSubmissionThread();
void run();
- static unsigned __stdcall thread_proc(void *addr);
+ static unsigned __stdcall thread_proc(void* addr);
private:
DECLSPEC_ALIGN(MEMORY_ALLOCATION_ALIGNMENT) SLIST_HEADER workList_;
@@ -117,13 +119,15 @@ private:
class TAutoOverlapThread : boost::noncopyable {
private:
- TOverlappedSubmissionThread *p;
+ TOverlappedSubmissionThread* p;
+
public:
TAutoOverlapThread() : p(TOverlappedSubmissionThread::acquire_instance()) {}
- ~TAutoOverlapThread() {TOverlappedSubmissionThread::release_instance();}
- TOverlappedSubmissionThread *operator->() {return p;}
+ ~TAutoOverlapThread() { TOverlappedSubmissionThread::release_instance(); }
+ TOverlappedSubmissionThread* operator->() { return p; }
};
-
-}}} //apache::thrift::transport
+}
+}
+} // apache::thrift::transport
#endif
diff --git a/lib/cpp/src/thrift/windows/SocketPair.cpp b/lib/cpp/src/thrift/windows/SocketPair.cpp
index 4b65e6baa..7228832ee 100644
--- a/lib/cpp/src/thrift/windows/SocketPair.cpp
+++ b/lib/cpp/src/thrift/windows/SocketPair.cpp
@@ -36,67 +36,65 @@
// Win32
#include <WS2tcpip.h>
-int thrift_socketpair(int d, int type, int protocol, THRIFT_SOCKET sv[2])
-{
- THRIFT_UNUSED_VARIABLE(protocol);
- THRIFT_UNUSED_VARIABLE(type);
- THRIFT_UNUSED_VARIABLE(d);
+int thrift_socketpair(int d, int type, int protocol, THRIFT_SOCKET sv[2]) {
+ THRIFT_UNUSED_VARIABLE(protocol);
+ THRIFT_UNUSED_VARIABLE(type);
+ THRIFT_UNUSED_VARIABLE(d);
- union {
- struct sockaddr_in inaddr;
- struct sockaddr addr;
- } a;
- THRIFT_SOCKET listener;
- int e;
- socklen_t addrlen = sizeof(a.inaddr);
- DWORD flags = 0;
- int reuse = 1;
+ union {
+ struct sockaddr_in inaddr;
+ struct sockaddr addr;
+ } a;
+ THRIFT_SOCKET listener;
+ int e;
+ socklen_t addrlen = sizeof(a.inaddr);
+ DWORD flags = 0;
+ int reuse = 1;
- if (sv == 0) {
- WSASetLastError(WSAEINVAL);
- return SOCKET_ERROR;
- }
+ if (sv == 0) {
+ WSASetLastError(WSAEINVAL);
+ return SOCKET_ERROR;
+ }
- listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (listener == INVALID_SOCKET)
- return SOCKET_ERROR;
+ listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
+ if (listener == INVALID_SOCKET)
+ return SOCKET_ERROR;
- memset(&a, 0, sizeof(a));
- a.inaddr.sin_family = AF_INET;
- a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
- a.inaddr.sin_port = 0;
+ memset(&a, 0, sizeof(a));
+ a.inaddr.sin_family = AF_INET;
+ a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+ a.inaddr.sin_port = 0;
- sv[0] = sv[1] = INVALID_SOCKET;
- do {
- //ignore errors coming out of this setsockopt. This is because
- //SO_EXCLUSIVEADDRUSE requires admin privileges on WinXP, but we don't
- //want to force socket pairs to be an admin.
- setsockopt(listener, SOL_SOCKET, SO_EXCLUSIVEADDRUSE,
- (char*) &reuse, (socklen_t) sizeof(reuse));
- if (bind(listener, &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
- break;
- if (getsockname(listener, &a.addr, &addrlen) == SOCKET_ERROR)
- break;
- if (listen(listener, 1) == SOCKET_ERROR)
- break;
- sv[0] = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, flags);
- if (sv[0] == INVALID_SOCKET)
- break;
- if (connect(sv[0], &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
- break;
- sv[1] = accept(listener, NULL, NULL);
- if (sv[1] == INVALID_SOCKET)
- break;
+ sv[0] = sv[1] = INVALID_SOCKET;
+ do {
+ // ignore errors coming out of this setsockopt. This is because
+ // SO_EXCLUSIVEADDRUSE requires admin privileges on WinXP, but we don't
+ // want to force socket pairs to be an admin.
+ setsockopt(listener, SOL_SOCKET, SO_EXCLUSIVEADDRUSE, (char*)&reuse, (socklen_t)sizeof(reuse));
+ if (bind(listener, &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
+ break;
+ if (getsockname(listener, &a.addr, &addrlen) == SOCKET_ERROR)
+ break;
+ if (listen(listener, 1) == SOCKET_ERROR)
+ break;
+ sv[0] = WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, flags);
+ if (sv[0] == INVALID_SOCKET)
+ break;
+ if (connect(sv[0], &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
+ break;
+ sv[1] = accept(listener, NULL, NULL);
+ if (sv[1] == INVALID_SOCKET)
+ break;
- closesocket(listener);
- return 0;
+ closesocket(listener);
+ return 0;
- } while (0);
+ } while (0);
- e = WSAGetLastError();
- closesocket(listener);
- closesocket(sv[0]);
- closesocket(sv[1]);
- WSASetLastError(e);
- return SOCKET_ERROR;
+ e = WSAGetLastError();
+ closesocket(listener);
+ closesocket(sv[0]);
+ closesocket(sv[1]);
+ WSASetLastError(e);
+ return SOCKET_ERROR;
}
diff --git a/lib/cpp/src/thrift/windows/Sync.h b/lib/cpp/src/thrift/windows/Sync.h
index ded6ea343..5d321996b 100644
--- a/lib/cpp/src/thrift/windows/Sync.h
+++ b/lib/cpp/src/thrift/windows/Sync.h
@@ -33,53 +33,55 @@
code, use the classes found in the concurrency namespace
*/
-namespace apache { namespace thrift {
+namespace apache {
+namespace thrift {
struct TCriticalSection : boost::noncopyable {
CRITICAL_SECTION cs;
- TCriticalSection() {InitializeCriticalSection(&cs);}
- ~TCriticalSection() {DeleteCriticalSection(&cs);}
+ TCriticalSection() { InitializeCriticalSection(&cs); }
+ ~TCriticalSection() { DeleteCriticalSection(&cs); }
};
class TAutoCrit : boost::noncopyable {
private:
- CRITICAL_SECTION *cs_;
+ CRITICAL_SECTION* cs_;
+
public:
- explicit TAutoCrit(TCriticalSection &cs) : cs_(&cs.cs) {EnterCriticalSection(cs_);}
- ~TAutoCrit() {LeaveCriticalSection(cs_);}
+ explicit TAutoCrit(TCriticalSection& cs) : cs_(&cs.cs) { EnterCriticalSection(cs_); }
+ ~TAutoCrit() { LeaveCriticalSection(cs_); }
};
struct TAutoResetEvent : boost::noncopyable {
HANDLE h;
TAutoResetEvent() {
- h = CreateEvent( NULL, FALSE, FALSE, NULL);
- if(h == NULL) {
+ h = CreateEvent(NULL, FALSE, FALSE, NULL);
+ if (h == NULL) {
GlobalOutput.perror("TAutoResetEvent unable to create event, GLE=", GetLastError());
throw apache::thrift::concurrency::SystemResourceException("CreateEvent failed");
}
}
- ~TAutoResetEvent() {CloseHandle(h);}
+ ~TAutoResetEvent() { CloseHandle(h); }
};
struct TManualResetEvent : boost::noncopyable {
HANDLE h;
TManualResetEvent() {
- h = CreateEvent( NULL, TRUE, FALSE, NULL);
- if(h == NULL) {
+ h = CreateEvent(NULL, TRUE, FALSE, NULL);
+ if (h == NULL) {
GlobalOutput.perror("TManualResetEvent unable to create event, GLE=", GetLastError());
throw apache::thrift::concurrency::SystemResourceException("CreateEvent failed");
}
}
- ~TManualResetEvent() {CloseHandle(h);}
+ ~TManualResetEvent() { CloseHandle(h); }
};
struct TAutoHandle : boost::noncopyable {
HANDLE h;
explicit TAutoHandle(HANDLE h_ = INVALID_HANDLE_VALUE) : h(h_) {}
~TAutoHandle() {
- if(h != INVALID_HANDLE_VALUE)
+ if (h != INVALID_HANDLE_VALUE)
CloseHandle(h);
}
@@ -89,14 +91,14 @@ struct TAutoHandle : boost::noncopyable {
return retval;
}
void reset(HANDLE h_ = INVALID_HANDLE_VALUE) {
- if(h_ == h)
+ if (h_ == h)
return;
- if(h != INVALID_HANDLE_VALUE)
+ if (h != INVALID_HANDLE_VALUE)
CloseHandle(h);
h = h_;
}
};
-
-}} //apache::thrift
+}
+} // apache::thrift
#endif
diff --git a/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp b/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp
index 2e306c627..2e0ccf53a 100644
--- a/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp
+++ b/lib/cpp/src/thrift/windows/TWinsockSingleton.cpp
@@ -23,51 +23,49 @@
#include <boost/assert.hpp>
#include <stdexcept>
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
TWinsockSingleton::instance_ptr TWinsockSingleton::instance_ptr_(NULL);
#if USE_BOOST_THREAD
-boost::once_flag TWinsockSingleton::flags_ = BOOST_ONCE_INIT;
+boost::once_flag TWinsockSingleton::flags_ = BOOST_ONCE_INIT;
#elif USE_STD_THREAD
-std::once_flag TWinsockSingleton::flags_;
+std::once_flag TWinsockSingleton::flags_;
#else
#error For windows you must choose USE_BOOST_THREAD or USE_STD_THREAD
#endif
//------------------------------------------------------------------------------
-TWinsockSingleton::TWinsockSingleton(void)
-{
- WORD version(MAKEWORD(2, 2));
- WSAData data = {0};
+TWinsockSingleton::TWinsockSingleton(void) {
+ WORD version(MAKEWORD(2, 2));
+ WSAData data = {0};
- int error(WSAStartup(version, &data));
- if (error != 0)
- {
- BOOST_ASSERT(false);
- throw std::runtime_error("Failed to initialise Winsock.");
- }
+ int error(WSAStartup(version, &data));
+ if (error != 0) {
+ BOOST_ASSERT(false);
+ throw std::runtime_error("Failed to initialise Winsock.");
+ }
}
//------------------------------------------------------------------------------
-TWinsockSingleton::~TWinsockSingleton(void)
-{
- WSACleanup();
+TWinsockSingleton::~TWinsockSingleton(void) {
+ WSACleanup();
}
//------------------------------------------------------------------------------
-void TWinsockSingleton::create(void)
-{
+void TWinsockSingleton::create(void) {
#if USE_BOOST_THREAD
- boost::call_once(init, flags_);
+ boost::call_once(init, flags_);
#elif USE_STD_THREAD
- std::call_once(flags_, init);
+ std::call_once(flags_, init);
#endif
}
//------------------------------------------------------------------------------
-void TWinsockSingleton::init(void)
-{
- instance_ptr_.reset(new TWinsockSingleton);
+void TWinsockSingleton::init(void) {
+ instance_ptr_.reset(new TWinsockSingleton);
}
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
diff --git a/lib/cpp/src/thrift/windows/TWinsockSingleton.h b/lib/cpp/src/thrift/windows/TWinsockSingleton.h
index ab12c222b..dc1b52f88 100644
--- a/lib/cpp/src/thrift/windows/TWinsockSingleton.h
+++ b/lib/cpp/src/thrift/windows/TWinsockSingleton.h
@@ -42,47 +42,43 @@
#error For windows you must choose USE_BOOST_THREAD or USE_STD_THREAD
#endif
-namespace apache { namespace thrift { namespace transport {
+namespace apache {
+namespace thrift {
+namespace transport {
/**
* Winsock2 must be intialised once only in order to create sockets. This class
* performs a one time initialisation when create is called.
*/
-class TWinsockSingleton : private boost::noncopyable
-{
+class TWinsockSingleton : private boost::noncopyable {
public:
-
- typedef boost::scoped_ptr<TWinsockSingleton> instance_ptr;
+ typedef boost::scoped_ptr<TWinsockSingleton> instance_ptr;
private:
-
- TWinsockSingleton(void);
+ TWinsockSingleton(void);
public:
-
- ~TWinsockSingleton(void);
+ ~TWinsockSingleton(void);
public:
-
- static void create(void);
+ static void create(void);
private:
-
- static void init(void);
+ static void init(void);
private:
-
- static instance_ptr instance_ptr_;
+ static instance_ptr instance_ptr_;
#if USE_BOOST_THREAD
- static boost::once_flag flags_;
+ static boost::once_flag flags_;
#elif USE_STD_THREAD
- static std::once_flag flags_;
+ static std::once_flag flags_;
#else
#error Need a non-Boost non-C++11 way to track single initialization here.
#endif
};
-
-}}} // apache::thrift::transport
+}
+}
+} // apache::thrift::transport
#endif // _THRIFT_TRANSPORT_WINDOWS_TWINSOCKSINGLETON_H_
diff --git a/lib/cpp/src/thrift/windows/WinFcntl.cpp b/lib/cpp/src/thrift/windows/WinFcntl.cpp
index 3dd4e3da7..c8b85f32d 100644
--- a/lib/cpp/src/thrift/windows/WinFcntl.cpp
+++ b/lib/cpp/src/thrift/windows/WinFcntl.cpp
@@ -19,54 +19,46 @@
#include <thrift/windows/WinFcntl.h>
-int thrift_fcntl(THRIFT_SOCKET fd, int cmd, int flags)
-{
- if(cmd != THRIFT_F_GETFL && cmd != THRIFT_F_SETFL)
- {
- return -1;
- }
+int thrift_fcntl(THRIFT_SOCKET fd, int cmd, int flags) {
+ if (cmd != THRIFT_F_GETFL && cmd != THRIFT_F_SETFL) {
+ return -1;
+ }
- if(flags != THRIFT_O_NONBLOCK && flags != 0)
- {
- return -1;
- }
+ if (flags != THRIFT_O_NONBLOCK && flags != 0) {
+ return -1;
+ }
- if(cmd == THRIFT_F_GETFL)
- {
- return 0;
- }
+ if (cmd == THRIFT_F_GETFL) {
+ return 0;
+ }
- int res;
- if(flags)
- {
- res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long *>(&(flags = 1)));
- }
- else
- {
- res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long *>(&(flags = 0)));
- }
+ int res;
+ if (flags) {
+ res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long*>(&(flags = 1)));
+ } else {
+ res = ioctlsocket(fd, FIONBIO, reinterpret_cast<u_long*>(&(flags = 0)));
+ }
- return res;
+ return res;
}
-#if WINVER <= 0x0502 //XP, Server2003
-int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout)
-{
+#if WINVER <= 0x0502 // XP, Server2003
+int thrift_poll(THRIFT_POLLFD* fdArray, ULONG nfds, INT timeout) {
fd_set read_fds, write_fds;
- fd_set* read_fds_ptr = NULL;
+ fd_set* read_fds_ptr = NULL;
fd_set* write_fds_ptr = NULL;
FD_ZERO(&read_fds);
FD_ZERO(&write_fds);
- for(ULONG i=0; i<nfds; i++) {
- //Read (in) socket
- if((fdArray[i].events & THRIFT_POLLIN) == THRIFT_POLLIN) {
+ for (ULONG i = 0; i < nfds; i++) {
+ // Read (in) socket
+ if ((fdArray[i].events & THRIFT_POLLIN) == THRIFT_POLLIN) {
read_fds_ptr = &read_fds;
FD_SET(fdArray[i].fd, &read_fds);
}
- //Write (out) socket
- else if((fdArray[i].events & THRIFT_POLLOUT) == THRIFT_POLLOUT) {
+ // Write (out) socket
+ else if ((fdArray[i].events & THRIFT_POLLOUT) == THRIFT_POLLOUT) {
write_fds_ptr = &write_fds;
FD_SET(fdArray[i].fd, &write_fds);
}
@@ -74,37 +66,35 @@ int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout)
timeval time_out;
timeval* time_out_ptr = NULL;
- if(timeout >= 0) {
+ if (timeout >= 0) {
timeval time_out = {timeout / 1000, (timeout % 1000) * 1000};
time_out_ptr = &time_out;
- }
- else { //to avoid compiler warnings
+ } else { // to avoid compiler warnings
(void)time_out;
(void)timeout;
}
int sktready = select(1, read_fds_ptr, write_fds_ptr, NULL, time_out_ptr);
- if(sktready > 0) {
- for(ULONG i=0; i<nfds; i++) {
+ if (sktready > 0) {
+ for (ULONG i = 0; i < nfds; i++) {
fdArray[i].revents = 0;
- if(FD_ISSET(fdArray[i].fd, &read_fds))
+ if (FD_ISSET(fdArray[i].fd, &read_fds))
fdArray[i].revents |= THRIFT_POLLIN;
- if(FD_ISSET(fdArray[i].fd, &write_fds))
+ if (FD_ISSET(fdArray[i].fd, &write_fds))
fdArray[i].revents |= THRIFT_POLLOUT;
}
}
return sktready;
}
-#else //Vista, Win7...
-int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout)
-{
+#else // Vista, Win7...
+int thrift_poll(THRIFT_POLLFD* fdArray, ULONG nfds, INT timeout) {
return WSAPoll(fdArray, nfds, timeout);
}
#endif // WINVER
#ifdef _WIN32_WCE
std::string thrift_wstr2str(std::wstring ws) {
- std::string s(ws.begin(), ws.end());
- return s;
+ std::string s(ws.begin(), ws.end());
+ return s;
}
#endif
diff --git a/lib/cpp/src/thrift/windows/WinFcntl.h b/lib/cpp/src/thrift/windows/WinFcntl.h
index 118c9a4da..6c6be97ef 100644
--- a/lib/cpp/src/thrift/windows/WinFcntl.h
+++ b/lib/cpp/src/thrift/windows/WinFcntl.h
@@ -36,17 +36,17 @@
#include <Winsock2.h>
#include <thrift/transport/PlatformSocket.h>
-#if WINVER <= 0x0502 //XP, Server2003
+#if WINVER <= 0x0502 // XP, Server2003
struct thrift_pollfd {
- THRIFT_SOCKET fd;
- SHORT events;
- SHORT revents;
+ THRIFT_SOCKET fd;
+ SHORT events;
+ SHORT revents;
};
#endif
extern "C" {
int thrift_fcntl(THRIFT_SOCKET fd, int cmd, int flags);
-int thrift_poll(THRIFT_POLLFD *fdArray, ULONG nfds, INT timeout);
+int thrift_poll(THRIFT_POLLFD* fdArray, ULONG nfds, INT timeout);
}
#ifdef _WIN32_WCE
diff --git a/lib/cpp/src/thrift/windows/config.h b/lib/cpp/src/thrift/windows/config.h
index 9261ca8de..dd0da3572 100644
--- a/lib/cpp/src/thrift/windows/config.h
+++ b/lib/cpp/src/thrift/windows/config.h
@@ -30,53 +30,53 @@
// use std::thread in MSVC11 (2012) or newer
#if _MSC_VER >= 1700
-# define USE_STD_THREAD 1
+#define USE_STD_THREAD 1
// otherwise use boost threads
#else
-# define USE_BOOST_THREAD 1
+#define USE_BOOST_THREAD 1
#endif
#ifndef TARGET_WIN_XP
-# define TARGET_WIN_XP 1
+#define TARGET_WIN_XP 1
#endif
#if TARGET_WIN_XP
-# ifndef WINVER
-# define WINVER 0x0501
-# endif
-# ifndef _WIN32_WINNT
-# define _WIN32_WINNT 0x0501
-# endif
+#ifndef WINVER
+#define WINVER 0x0501
+#endif
+#ifndef _WIN32_WINNT
+#define _WIN32_WINNT 0x0501
+#endif
#endif
#ifndef _WIN32_WINNT
-# define _WIN32_WINNT 0x0601
+#define _WIN32_WINNT 0x0601
#endif
#if defined(_M_IX86) || defined(_M_X64)
-# define ARITHMETIC_RIGHT_SHIFT 1
-# define SIGNED_RIGHT_SHIFT_IS 1
+#define ARITHMETIC_RIGHT_SHIFT 1
+#define SIGNED_RIGHT_SHIFT_IS 1
#endif
-#pragma warning(disable: 4996) // Deprecated posix name.
+#pragma warning(disable : 4996) // Deprecated posix name.
#define VERSION "1.0.0-dev"
#define HAVE_GETTIMEOFDAY 1
#define HAVE_SYS_STAT_H 1
#ifdef HAVE_STDINT_H
-# include <stdint.h>
+#include <stdint.h>
#else
-# include <boost/cstdint.hpp>
+#include <boost/cstdint.hpp>
-typedef boost::int64_t int64_t;
-typedef boost::uint64_t uint64_t;
-typedef boost::int32_t int32_t;
-typedef boost::uint32_t uint32_t;
-typedef boost::int16_t int16_t;
-typedef boost::uint16_t uint16_t;
-typedef boost::int8_t int8_t;
-typedef boost::uint8_t uint8_t;
+typedef boost::int64_t int64_t;
+typedef boost::uint64_t uint64_t;
+typedef boost::int32_t int32_t;
+typedef boost::uint32_t uint32_t;
+typedef boost::int16_t int16_t;
+typedef boost::uint16_t uint16_t;
+typedef boost::int8_t int8_t;
+typedef boost::uint8_t uint8_t;
#endif
#include <thrift/transport/PlatformSocket.h>
@@ -93,6 +93,6 @@ typedef boost::uint8_t uint8_t;
#pragma comment(lib, "Ws2.lib")
#else
#pragma comment(lib, "Ws2_32.lib")
-#pragma comment(lib, "advapi32.lib") //For security APIs in TPipeServer
+#pragma comment(lib, "advapi32.lib") // For security APIs in TPipeServer
#endif
#endif // _THRIFT_WINDOWS_CONFIG_H_