00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _tcpsocket_h
00018 #define _tcpsocket_h
00019
00020 #include <spl/Debug.h>
00021 #include <spl/RefCountPtr.h>
00022 #include <spl/net/Socket.h>
00023
00030 class TcpSocket;
00031 typedef RefCountPtr<TcpSocket> TcpSocketPtr;
00032 typedef WeakReference<TcpSocket, TcpSocketPtr> TcpSocketRef;
00033
00034 REGISTER_TYPEOF(68, TcpSocketPtr);
00035 REGISTER_TYPEOF( 476, TcpSocketRef );
00036
00040 class TcpSocket : public IMemoryValidate
00041 {
00042 private:
00043
00044 inline TcpSocket(const TcpSocket& sock) {}
00045 inline TcpSocket& operator =(const TcpSocket& pmp) {}
00046
00047 protected:
00048 String m_address;
00049 SocketPtr m_sock;
00050 spl::IStreamPtr m_strm;
00051
00052 TcpSocket( SOCKET fd );
00053
00054 public:
00055 TcpSocket( const String& address, int port );
00056 virtual ~TcpSocket();
00057
00058 void Connect ();
00059
00061 spl::IStreamPtr GetStream();
00062
00063 inline bool IsClosed() { return m_sock->IsClosed(); }
00064 inline void Close() { m_sock->Close(); }
00065 inline void Shutdown( int i=SD_BOTH ) { m_sock->Shutdown(i); }
00066
00067 inline void SetNonBlocking() { m_sock->SetNonBlocking(); }
00068 inline void SetBlocking() { m_sock->SetBlocking(); }
00069 inline void SetLingerOn() { m_sock->SetLingerOn(); }
00070 inline void SetLingerOff() { m_sock->SetLingerOff(); }
00071 inline void SetNoDelay() { m_sock->SetNoDelay(); }
00072
00073 inline void SetSendTimeout(int toMS) { m_sock->SetSendTimeout(toMS); }
00074 inline void SetRecvTimeout(int toMS) { m_sock->SetRecvTimeout(toMS); }
00075 inline int GetSendTimeout() { return m_sock->GetSendTimeout(); }
00076 inline int GetRecvTimeout() { return m_sock->GetRecvTimeout(); }
00077
00078 inline int GetErrorCode() { return m_sock->m_errorStatus; }
00079 inline int GetBytesAvail() { return m_sock->GetBytesAvail(); }
00080
00081 inline String GetRemoteIp( ) { return m_sock->GetRemoteIp(); }
00082
00083 inline bool operator ==(const TcpSocket& s) const
00084 {
00085 return m_sock->GetFD() == s.m_sock->GetFD();
00086 }
00087
00088 friend class ServerSocket;
00089 friend class SocketSet;
00090
00091 #if defined(DEBUG) || defined(_DEBUG)
00092 virtual void CheckMem() const;
00093 virtual void ValidateMem() const;
00094 #endif
00095 };
00096
00097 REGISTER_TYPEOF(70, TcpSocket);
00098
00101 #endif