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.
This commit is contained in:
Vadim Zeitlin
2018-01-13 13:43:28 +01:00
parent 1261139bcb
commit ebb06fbeaf
3 changed files with 16 additions and 7 deletions

View File

@@ -62,6 +62,15 @@
#include <sys/time.h> // for timeval #include <sys/time.h> // for timeval
#endif #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 // these definitions are for MSW when we don't use configure, otherwise these
// symbols are defined by configure // symbols are defined by configure
#ifndef WX_SOCKLEN_T #ifndef WX_SOCKLEN_T
@@ -254,7 +263,7 @@ public:
// flags defines what kind of conditions we're interested in, the return // 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 // value is composed of a (possibly empty) subset of the bits set in flags
wxSocketEventFlags Select(wxSocketEventFlags flags, wxSocketEventFlags Select(wxSocketEventFlags flags,
const timeval *timeout = NULL); wxTimeVal_t *timeout = NULL);
// convenient wrapper calling Select() with our default timeout // convenient wrapper calling Select() with our default timeout
wxSocketEventFlags SelectWithTimeout(wxSocketEventFlags flags) wxSocketEventFlags SelectWithTimeout(wxSocketEventFlags flags)
@@ -299,7 +308,7 @@ public:
bool m_broadcast; bool m_broadcast;
bool m_dobind; bool m_dobind;
struct timeval m_timeout; wxTimeVal_t m_timeout;
protected: protected:
wxSocketImpl(wxSocketBase& wxsocket); wxSocketImpl(wxSocketBase& wxsocket);

View File

@@ -135,7 +135,7 @@ wxIMPLEMENT_DYNAMIC_CLASS(wxSocketEvent, wxEvent);
namespace namespace
{ {
void SetTimeValFromMS(timeval& tv, unsigned long ms) void SetTimeValFromMS(wxTimeVal_t& tv, unsigned long ms)
{ {
tv.tv_sec = (ms / 1000); tv.tv_sec = (ms / 1000);
tv.tv_usec = (ms % 1000) * 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. and it will return a mask indicating which operations can be performed.
*/ */
wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags, wxSocketEventFlags wxSocketImpl::Select(wxSocketEventFlags flags,
const timeval *timeout) wxTimeVal_t *timeout)
{ {
if ( m_fd == INVALID_SOCKET ) if ( m_fd == INVALID_SOCKET )
return (wxSOCKET_LOST_FLAG & flags); return (wxSOCKET_LOST_FLAG & flags);
struct timeval tv; wxTimeVal_t tv;
if ( timeout ) if ( timeout )
tv = *timeout; tv = *timeout;
else else
@@ -1502,7 +1502,7 @@ wxSocketBase::DoWait(long timeout, wxSocketEventFlags flags)
else // no event loop or waiting in another thread else // no event loop or waiting in another thread
{ {
// as explained below, we should always check for wxSOCKET_LOST_FLAG // as explained below, we should always check for wxSOCKET_LOST_FLAG
timeval tv; wxTimeVal_t tv;
SetTimeValFromMS(tv, timeLeft); SetTimeValFromMS(tv, timeLeft);
events = m_impl->Select(flags | wxSOCKET_LOST_FLAG, &tv); events = m_impl->Select(flags | wxSOCKET_LOST_FLAG, &tv);
} }

View File

@@ -217,7 +217,7 @@ LRESULT CALLBACK wxSocket_Internal_WinProc(HWND hWnd,
// only then). Ignore such dummy notifications. // only then). Ignore such dummy notifications.
{ {
fd_set fds; fd_set fds;
timeval tv = { 0, 0 }; wxTimeVal_t tv = { 0, 0 };
wxFD_ZERO(&fds); wxFD_ZERO(&fds);
wxFD_SET(socket->m_fd, &fds); wxFD_SET(socket->m_fd, &fds);