00001 /* **************************************************************** 00002 **************************************************************** 00003 * Com++ Professional (c) 2009 C++ World 00004 * http://www.cplusplusworld.com/ mailto:compp@cplusplusworld.com 00005 **************************************************************** 00006 **************************************************************** 00007 */ 00008 00009 00010 #ifndef SOCKETTCP_H 00011 #define SOCKETTCP_H 00012 00013 #include <iostream> 00014 #include <cstring> 00015 #include <string> 00016 #include <unistd.h> 00017 #include <fcntl.h> 00018 00019 #include "ComPlusPlus/Socket.h" 00020 00021 00022 namespace compp { 00023 00028 class SocketTcp : public Socket { 00029 00030 private: 00031 void NewTcpSocket(); 00032 00033 protected: 00034 00035 bool Async ; 00036 bool AsyncConnect ; 00037 bool OptTcpNoDelay ; 00038 int Backlog ; 00039 00040 public: 00041 00042 void SetOptTcpNoDelay( bool val) ; 00043 bool GetOptTcpNoDelay() const ; 00044 void SetOptAsyncConnect( bool val) ; 00045 bool GetOptAsyncConnect() const ; 00046 void SetOptAsync(bool val) ; 00047 bool GetOptSync() const; 00048 void SetBacklog(int val) ; 00049 bool GetBacklog() const ; 00050 virtual ~SocketTcp(); 00051 00052 SocketTcp( unsigned int bufsize = SocketTcpStandardBufferSize ); 00053 SocketTcp(const std::string & Addr, int port); 00054 SocketTcp( int port); 00055 SocketTcp ( struct sockaddr_in *saddr, int len, int fd, unsigned int readaheadbufsz = SocketTcpStandardBufferSize ) ; 00056 void Close (); 00057 void Shutdown (int method = 0); 00058 00059 // Listen with backlog or stdbacklog 00060 void Listen ( const int backlog); 00061 void Listen (); 00062 00063 // Do an explicit bind 00064 void Bind ( const std::string & addr, int port); 00065 void Bind ( const int port ); 00066 00067 bool Connect( const std::string &addr, const int port ); 00068 SocketTcp* Accept ( void ); 00069 00070 // Nagle's algorithmn 00071 bool SetSockOptTcpNoDelay ( bool yesno ) ; 00072 // maximum segment size. cannot be more that MTU 00073 bool SetSockOptTCP_MAXSEG ( int val ) ; 00074 00075 static const unsigned int SocketTcpStandardBufferSize = (8*1024); 00076 const std::string GetPeerSockIPAddr() const ; 00077 const unsigned short GetPeerSockPort() const; 00078 00079 const std::string GetSockIPAddr() const ; 00080 const unsigned short GetSockPort() const; 00081 00082 00083 }; 00084 } 00085 #endif
1.6.3