From: Vadim Zeitlin Date: Sun, 23 Nov 2008 13:39:12 +0000 (+0000) Subject: use struct timeval and not a long to store socket timeout under Unix too X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/87c0312a66f57b1d167e1f9454a80fe4b7b28e0b?ds=inline use struct timeval and not a long to store socket timeout under Unix too git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56940 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gsocket.h b/include/wx/gsocket.h index e7d362e247..cb34121e17 100644 --- a/include/wx/gsocket.h +++ b/include/wx/gsocket.h @@ -37,6 +37,8 @@ class WXDLLIMPEXP_FWD_NET wxSocketBase; #include #endif +#include // for timeval + enum GAddressType { GSOCK_NOFAMILY = 0, @@ -215,11 +217,7 @@ public: bool m_broadcast; bool m_dobind; -#ifdef __WINDOWS__ struct timeval m_timeout; -#else - unsigned long m_timeout; -#endif GSocketEventFlags m_detected; diff --git a/src/common/socket.cpp b/src/common/socket.cpp index 6826063517..a1e3be8456 100644 --- a/src/common/socket.cpp +++ b/src/common/socket.cpp @@ -231,12 +231,8 @@ void GSocketBase::Shutdown() */ void GSocketBase::SetTimeout(unsigned long millis) { -#ifdef __WXMSW__ m_timeout.tv_sec = (millis / 1000); m_timeout.tv_usec = (millis % 1000) * 1000; -#else - m_timeout = millis; -#endif } void GSocketBase::NotifyOnStateChange(GSocketEvent event) diff --git a/src/unix/gsocket.cpp b/src/unix/gsocket.cpp index 77a818bf6d..95d59e581b 100644 --- a/src/unix/gsocket.cpp +++ b/src/unix/gsocket.cpp @@ -1161,13 +1161,11 @@ void GSocket::Disable(GSocketEvent event) */ GSocketError GSocket::Input_Timeout() { - struct timeval tv; fd_set readfds; int ret; - /* Linux select() will overwrite the struct on return */ - tv.tv_sec = (m_timeout / 1000); - tv.tv_usec = (m_timeout % 1000) * 1000; + // Linux select() will overwrite the struct on return so make a copy + struct timeval tv = m_timeout; if (!m_non_blocking) { @@ -1202,13 +1200,11 @@ GSocketError GSocket::Input_Timeout() */ GSocketError GSocket::Output_Timeout() { - struct timeval tv; fd_set writefds; int ret; - /* Linux select() will overwrite the struct on return */ - tv.tv_sec = (m_timeout / 1000); - tv.tv_usec = (m_timeout % 1000) * 1000; + // Linux select() will overwrite the struct on return so make a copy + struct timeval tv = m_timeout; GSocket_Debug( ("m_non_blocking has: %d\n", (int)m_non_blocking) );