Add per-direction wxSocket wait flags and byte counters.

Allow to specify whether the socket should block until all the data is read or
written or, on the contrary, avoid blocking only when reading or writing
instead of always using the same behaviour in both directions.

Also add separate counters for the bytes read/written instead of using the
same one for both.

These changes make it possible to use the same socket for reading/writing in
different threads.

Closes #14506.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72591 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2012-09-30 22:21:44 +00:00
parent be4162218d
commit 294a09aa8c
5 changed files with 150 additions and 26 deletions

View File

@@ -77,7 +77,11 @@ enum
wxSOCKET_BLOCK = 4,
wxSOCKET_REUSEADDR = 8,
wxSOCKET_BROADCAST = 16,
wxSOCKET_NOBIND = 32
wxSOCKET_NOBIND = 32,
wxSOCKET_NOWAIT_READ = 64,
wxSOCKET_WAITALL_READ = 128,
wxSOCKET_NOWAIT_WRITE = 256,
wxSOCKET_WAITALL_WRITE = 512
};
typedef int wxSocketFlags;
@@ -123,6 +127,8 @@ public:
bool IsData() { return WaitForRead(0, 0); }
bool IsDisconnected() const { return !IsConnected(); }
wxUint32 LastCount() const { return m_lcount; }
wxUint32 LastReadCount() const { return m_lcount_read; }
wxUint32 LastWriteCount() const { return m_lcount_write; }
wxSocketError LastError() const;
void SaveState();
void RestoreState();
@@ -171,6 +177,8 @@ public:
bool GetOption(int level, int optname, void *optval, int *optlen);
bool SetOption(int level, int optname, const void *optval, int optlen);
wxUint32 GetLastIOSize() const { return m_lcount; }
wxUint32 GetLastIOReadSize() const { return m_lcount_read; }
wxUint32 GetLastIOWriteSize() const { return m_lcount_write; }
// event handling
void *GetClientData() const { return m_clientData; }
@@ -254,6 +262,8 @@ private:
bool m_writing; // busy writing?
bool m_closed; // was the other end closed?
wxUint32 m_lcount; // last IO transaction size
wxUint32 m_lcount_read; // last IO transaction size of Read() direction.
wxUint32 m_lcount_write; // last IO transaction size of Write() direction.
unsigned long m_timeout; // IO timeout value in seconds
// (TODO: remove, wxSocketImpl has it too)
wxList m_states; // stack of states (TODO: remove!)