From ebb06fbeafa0d50581823e3a372a1232b0bc736d Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 13 Jan 2018 13:43:28 +0100 Subject: [PATCH] Use wxTimeVal_t instead of timeval to fix 64 bit Cygwin problems Due to the same problem with sizeof(long) mismatch as in the previous commit, we can't use struct timeval, with its long fields, in 64 bit Cygwin builds, and need to use __ms_timeval instead. Add wxTimeVal_t type to hide this difference and update all code compiled under MSW (there is no need to uglify Unix-only code using timeval, as in wxSelectDispatcher, for example) to use it instead of timeval. --- include/wx/private/socket.h | 13 +++++++++++-- src/common/socket.cpp | 8 ++++---- src/msw/sockmsw.cpp | 2 +- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/include/wx/private/socket.h b/include/wx/private/socket.h index 906c20c659..56a3cef528 100644 --- a/include/wx/private/socket.h +++ b/include/wx/private/socket.h @@ -62,6 +62,15 @@ #include // for timeval #endif +// 64 bit Cygwin can't use the standard struct timeval because it has long +// fields, which are supposed to be 32 bits in Win64 API, but long is 64 bits +// in 64 bit Cygwin, so we need to use its special __ms_timeval instead. +#if defined(__CYGWIN__) && defined(__LP64__) + typedef __ms_timeval wxTimeVal_t; +#else + typedef timeval wxTimeVal_t; +#endif + // these definitions are for MSW when we don't use configure, otherwise these // symbols are defined by configure #ifndef WX_SOCKLEN_T @@ -254,7 +263,7 @@ public: // flags defines what kind of conditions we're interested in, the return // value is composed of a (possibly empty) subset of the bits set in flags wxSocketEventFlags Select(wxSocketEventFlags flags, - const timeval *timeout = NULL); + wxTimeVal_t *timeout = NULL); // convenient wrapper calling Select() with our default timeout wxSocketEventFlags SelectWithTimeout(wxSocketEventFlags flags) @@ -299,7 +308,7 @@ public: bool m_broadcast; bool m_dobind; - struct timeval m_timeout; + wxTimeVal_t m_timeout; protected: wxSocketImpl(wxSocketBase& wxsocket); diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 5fb8c291ae..207b3c9751 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -135,7 +135,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxSocketEvent, wxEvent); namespace { -void SetTimeValFromMS(timeval& tv, unsigned long ms) +void SetTimeValFromMS(wxTimeVal_t& tv, unsigned long ms) { tv.tv_sec = (ms / 1000); tv.tv_usec = (ms % 1000) * 1000; @@ -1304,12 +1304,12 @@ wxSocketBase& wxSocketBase::Discard() and it will return a mask indicating which operations can be performed. */ wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags, - const timeval *timeout) + wxTimeVal_t *timeout) { if ( m_fd == INVALID_SOCKET ) return (wxSOCKET_LOST_FLAG & flags); - struct timeval tv; + wxTimeVal_t tv; if ( timeout ) tv = *timeout; else @@ -1502,7 +1502,7 @@ wxSocketBase::DoWait(long timeout, wxSocketEventFlags flags) else // no event loop or waiting in another thread { // as explained below, we should always check for wxSOCKET_LOST_FLAG - timeval tv; + wxTimeVal_t tv; SetTimeValFromMS(tv, timeLeft); events = m_impl->Select(flags | wxSOCKET_LOST_FLAG, &tv); } diff --git a/src/msw/sockmsw.cpp b/src/msw/sockmsw.cpp index 791f18a49b..2a66c8eda4 100644 --- a/src/msw/sockmsw.cpp +++ b/src/msw/sockmsw.cpp @@ -217,7 +217,7 @@ LRESULT CALLBACK wxSocket_Internal_WinProc(HWND hWnd, // only then). Ignore such dummy notifications. { fd_set fds; - timeval tv = { 0, 0 }; + wxTimeVal_t tv = { 0, 0 }; wxFD_ZERO(&fds); wxFD_SET(socket->m_fd, &fds);