-
- // Public interface
- // ----------------
-
- // ctors and dtors
- wxSocketBase();
- wxSocketBase(wxSocketFlags flags, wxSocketType type);
- virtual ~wxSocketBase();
- void Init();
- bool Destroy();
-
- // state
- inline bool Ok() const { return (m_socket != NULL); };
- inline bool Error() const { return m_error; };
- inline bool IsConnected() const { return m_connected; };
- inline bool IsData() { return WaitForRead(0, 0); };
- inline bool IsDisconnected() const { return !IsConnected(); };
- inline wxUint32 LastCount() const { return m_lcount; }
- inline wxSocketError LastError() const { return (wxSocketError)GSocket_GetError(m_socket); }
- void SaveState();
- void RestoreState();
-
- // addresses
- virtual bool GetLocal(wxSockAddress& addr_man) const;
- virtual bool GetPeer(wxSockAddress& addr_man) const;
-
- // base IO
- virtual bool Close();
- wxSocketBase& Discard();
- wxSocketBase& Peek(void* buffer, wxUint32 nbytes);
- wxSocketBase& Read(void* buffer, wxUint32 nbytes);
- wxSocketBase& ReadMsg(void *buffer, wxUint32 nbytes);
- wxSocketBase& Unread(const void *buffer, wxUint32 nbytes);
- wxSocketBase& Write(const void *buffer, wxUint32 nbytes);
- wxSocketBase& WriteMsg(const void *buffer, wxUint32 nbytes);
-
- void InterruptWait() { m_interrupt = TRUE; };
- bool Wait(long seconds = -1, long milliseconds = 0);
- bool WaitForRead(long seconds = -1, long milliseconds = 0);
- bool WaitForWrite(long seconds = -1, long milliseconds = 0);
- bool WaitForLost(long seconds = -1, long milliseconds = 0);
-
- inline wxSocketFlags GetFlags() const { return m_flags; }
- void SetFlags(wxSocketFlags flags);
- void SetTimeout(long seconds);
-
- // event handling
- void *GetClientData() const { return m_clientData; }
- void SetClientData(void *data) { m_clientData = data; }
- void SetEventHandler(wxEvtHandler& handler, int id = -1);
- void SetNotify(wxSocketEventFlags flags);
- void Notify(bool notify);
-
- // initialize/shutdown the sockets (usually called automatically)
- static bool IsInitialized();
- static bool Initialize();
- static void Shutdown();
-
-
- // Implementation from now on
- // --------------------------
-
- // do not use, should be private (called from GSocket)
- void OnRequest(wxSocketNotify notify);
-
- // do not use, not documented nor supported
- inline bool IsNoWait() const { return ((m_flags & wxSOCKET_NOWAIT) != 0); }
- inline wxSocketType GetType() const { return m_type; }
+ // Public interface
+ // ----------------
+
+ // ctors and dtors
+ wxSocketBase();
+ wxSocketBase(wxSocketFlags flags, wxSocketType type);
+ virtual ~wxSocketBase();
+ void Init();
+ bool Destroy();
+
+ // state
+ bool Ok() const { return IsOk(); }
+ bool IsOk() const { return m_impl != NULL; }
+ bool Error() const { return LastError() != wxSOCKET_NOERROR; }
+ bool IsClosed() const { return m_closed; }
+ bool IsConnected() const { return m_connected; }
+ 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();
+
+ // addresses
+ virtual bool GetLocal(wxSockAddress& addr_man) const;
+ virtual bool GetPeer(wxSockAddress& addr_man) const;
+ virtual bool SetLocal(const wxIPV4address& local);
+
+ // base IO
+ virtual bool Close();
+ void ShutdownOutput();
+ wxSocketBase& Discard();
+ wxSocketBase& Peek(void* buffer, wxUint32 nbytes);
+ wxSocketBase& Read(void* buffer, wxUint32 nbytes);
+ wxSocketBase& ReadMsg(void *buffer, wxUint32 nbytes);
+ wxSocketBase& Unread(const void *buffer, wxUint32 nbytes);
+ wxSocketBase& Write(const void *buffer, wxUint32 nbytes);
+ wxSocketBase& WriteMsg(const void *buffer, wxUint32 nbytes);
+
+ // all Wait() functions wait until their condition is satisfied or the
+ // timeout expires; if seconds == -1 (default) then m_timeout value is used
+ //
+ // it is also possible to call InterruptWait() to cancel any current Wait()
+
+ // wait for anything at all to happen with this socket
+ bool Wait(long seconds = -1, long milliseconds = 0);
+
+ // wait until we can read from or write to the socket without blocking
+ // (notice that this does not mean that the operation will succeed but only
+ // that it will return immediately)
+ bool WaitForRead(long seconds = -1, long milliseconds = 0);
+ bool WaitForWrite(long seconds = -1, long milliseconds = 0);
+
+ // wait until the connection is terminated
+ bool WaitForLost(long seconds = -1, long milliseconds = 0);
+
+ void InterruptWait() { m_interrupt = true; }
+
+
+ wxSocketFlags GetFlags() const { return m_flags; }
+ void SetFlags(wxSocketFlags flags);
+ 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; }
+ void SetClientData(void *data) { m_clientData = data; }
+ void SetEventHandler(wxEvtHandler& handler, int id = wxID_ANY);
+ void SetNotify(wxSocketEventFlags flags);
+ void Notify(bool notify);
+
+ // 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
+ // --------------------------
+
+ // do not use, should be private (called from wxSocketImpl only)
+ void OnRequest(wxSocketNotify notify);
+
+ // do not use, not documented nor supported
+ bool IsNoWait() const { return ((m_flags & wxSOCKET_NOWAIT) != 0); }
+ wxSocketType GetType() const { return m_type; }