+ wxDECLARE_NO_COPY_CLASS(wxSocketState);
+};
+
+// wxSocketWaitModeChanger: temporarily change the socket flags affecting its
+// wait mode
+class wxSocketWaitModeChanger
+{
+public:
+ // temporarily set the flags to include the flag value which may be either
+ // wxSOCKET_NOWAIT or wxSOCKET_WAITALL
+ wxSocketWaitModeChanger(wxSocketBase *socket, int flag)
+ : m_socket(socket),
+ m_oldflags(socket->GetFlags())
+
+ {
+ wxASSERT_MSG( flag == wxSOCKET_WAITALL || flag == wxSOCKET_NOWAIT,
+ "not a wait flag" );
+
+ // preserve wxSOCKET_BLOCK value when switching to wxSOCKET_WAITALL
+ // mode but not when switching to wxSOCKET_NOWAIT as the latter is
+ // incompatible with wxSOCKET_BLOCK
+ if ( flag != wxSOCKET_NOWAIT )
+ flag |= m_oldflags & wxSOCKET_BLOCK;
+
+ socket->SetFlags(flag);
+ }
+
+ ~wxSocketWaitModeChanger()
+ {
+ m_socket->SetFlags(m_oldflags);
+ }
+
+private:
+ wxSocketBase * const m_socket;
+ const int m_oldflags;
+
+ wxDECLARE_NO_COPY_CLASS(wxSocketWaitModeChanger);
+};
+
+// wxSocketRead/WriteGuard are instantiated before starting reading
+// from/writing to the socket
+class wxSocketReadGuard
+{
+public:
+ wxSocketReadGuard(wxSocketBase *socket)
+ : m_socket(socket)
+ {
+ wxASSERT_MSG( !m_socket->m_reading, "read reentrancy?" );
+
+ m_socket->m_reading = true;
+ }
+
+ ~wxSocketReadGuard()
+ {
+ m_socket->m_reading = false;
+
+ // connection could have been lost while reading, in this case calling
+ // ReenableEvents() would assert and is not necessary anyhow
+ wxSocketImpl * const impl = m_socket->m_impl;
+ if ( impl && impl->m_fd != INVALID_SOCKET )
+ impl->ReenableEvents(wxSOCKET_INPUT_FLAG);
+ }
+
+private:
+ wxSocketBase * const m_socket;
+
+ wxDECLARE_NO_COPY_CLASS(wxSocketReadGuard);
+};
+
+class wxSocketWriteGuard
+{
+public:
+ wxSocketWriteGuard(wxSocketBase *socket)
+ : m_socket(socket)
+ {
+ wxASSERT_MSG( !m_socket->m_writing, "write reentrancy?" );
+
+ m_socket->m_writing = true;
+ }
+
+ ~wxSocketWriteGuard()
+ {
+ m_socket->m_writing = false;
+
+ wxSocketImpl * const impl = m_socket->m_impl;
+ if ( impl && impl->m_fd != INVALID_SOCKET )
+ impl->ReenableEvents(wxSOCKET_OUTPUT_FLAG);
+ }
+
+private:
+ wxSocketBase * const m_socket;
+
+ wxDECLARE_NO_COPY_CLASS(wxSocketWriteGuard);