X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3c7789014106c9269b0f4ecc1a3071b14f351d3f..77dd7daad2df0faac2b4e846ac9bb6aff588278c:/include/wx/socket.h?ds=sidebyside diff --git a/include/wx/socket.h b/include/wx/socket.h index c3d655173d..5181d3b475 100644 --- a/include/wx/socket.h +++ b/include/wx/socket.h @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: socket.h +// Name: wx/socket.h // Purpose: Socket handling classes // Authors: Guilhem Lavaux, Guillermo Rodriguez Garcia // Modified by: @@ -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; @@ -95,7 +99,7 @@ enum wxSocketType // event class WXDLLIMPEXP_FWD_NET wxSocketEvent; -wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_NET, wxEVT_SOCKET, wxSocketEvent) +wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_NET, wxEVT_SOCKET, wxSocketEvent); // -------------------------------------------------------------------------- // wxSocketBase @@ -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(); @@ -165,12 +171,14 @@ public: wxSocketFlags GetFlags() const { return m_flags; } void SetFlags(wxSocketFlags flags); - void SetTimeout(long seconds); + virtual void SetTimeout(long seconds); long GetTimeout() const { return m_timeout; } 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; } @@ -179,11 +187,21 @@ public: void SetNotify(wxSocketEventFlags flags); void Notify(bool notify); - // initialize/shutdown the sockets (usually called automatically) - static bool IsInitialized(); + // initialize/shutdown the sockets (done automatically so there is no need + // to call these functions usually) + // + // should always be called from the main thread only so one of the cases + // where they should indeed be called explicitly is when the first wxSocket + // object in the application is created in a different thread static bool Initialize(); static void Shutdown(); + // check if wxSocket had been already initialized + // + // notice that this function should be only called from the main thread as + // otherwise it is inherently unsafe because Initialize/Shutdown() may be + // called concurrently with it in the main thread + static bool IsInitialized(); // Implementation from now on // -------------------------- @@ -244,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!) @@ -264,14 +284,11 @@ private: wxSocketEventFlags m_eventmask; // which events to notify? wxSocketEventFlags m_eventsgot; // collects events received in OnRequest() - // the initialization count, wxSocket is initialized if > 0 - static size_t m_countInit; - friend class wxSocketReadGuard; friend class wxSocketWriteGuard; - DECLARE_NO_COPY_CLASS(wxSocketBase) + wxDECLARE_NO_COPY_CLASS(wxSocketBase); DECLARE_CLASS(wxSocketBase) }; @@ -291,7 +308,7 @@ public: bool WaitForAccept(long seconds = -1, long milliseconds = 0); - DECLARE_NO_COPY_CLASS(wxSocketServer) + wxDECLARE_NO_COPY_CLASS(wxSocketServer); DECLARE_CLASS(wxSocketServer) }; @@ -330,7 +347,7 @@ private: int m_initialRecvBufferSize; int m_initialSendBufferSize; - DECLARE_NO_COPY_CLASS(wxSocketClient) + wxDECLARE_NO_COPY_CLASS(wxSocketClient); DECLARE_CLASS(wxSocketClient) }; @@ -359,7 +376,7 @@ public: */ private: - DECLARE_NO_COPY_CLASS(wxDatagramSocket) + wxDECLARE_NO_COPY_CLASS(wxDatagramSocket); DECLARE_CLASS(wxDatagramSocket) }; @@ -382,6 +399,7 @@ public: void *GetClientData() const { return m_clientData; } virtual wxEvent *Clone() const { return new wxSocketEvent(*this); } + virtual wxEventCategory GetEventCategory() const { return wxEVT_CATEGORY_SOCKET; } public: wxSocketNotify m_event;