Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

MNTCPSocket.h

Go to the documentation of this file.
00001 /* Copyright (C) 2000 KOM/Darmstadt University of Technology 00002 * 00003 * You are allowed to use all other parts of the code under the following terms: 00004 * 00005 * For non-commercial use, code may be used in unmodified form provided 00006 * that this copyright notice and this permission notice appear in 00007 * supporting documentation. 00008 * 00009 * This software is provided "as is" and without any express or implied 00010 * warranties, including, without limitation, the implied warranty of 00011 * fitness for a particular purpose. 00012 * 00013 * The code may be subjected to the GNU General Public License, Version 2, 00014 * and re-distributed under the terms of this license. 00015 * As a special exception, permission is granted to link this code 00016 * with the Qt library and distribute executables, as long as you 00017 * follow the requirements of the GNU GPL in regard to all of the 00018 * software in the executable aside from Qt. 00019 * 00020 * Commercial use other than under the terms of the GNU General Public 00021 * License is allowed only after express negotiation of conditions 00022 * with the authors. 00023 */ 00024 #ifndef MN_TCPSOCKET_H 00025 #define MN_TCPSOCKET_H 00026 00027 /*********************************************************************** 00028 * MNTCPSocket 00029 * 00030 * The base class for all TCP sockets. 00031 * It does not implement any data reception functionality. This must 00032 * be implemented by the base classes by overloading callback(). 00033 * 00034 * The functions reader() and set_buffers() are deprecated and will 00035 * be removed soon. 00036 * 00037 * The constructors are semantically inconsistent and need a major 00038 * revision. 00039 ***********************************************************************/ 00040 00041 00042 #include "MNSocket.h" 00043 #include <sys/uio.h> 00044 #include <sys/socket.h> 00045 #include <netdb.h> 00046 #include <netinet/in.h> 00047 00048 class MNSelector; 00049 00050 class MNTCPSocket : public MNSocket 00051 { 00052 public: 00053 enum CreationMode 00054 { 00055 MakeNow 00056 }; 00057 00058 enum Fail 00059 { 00060 Ok = 0, 00061 Errno = -1, 00062 Herrno = -2 00063 }; 00064 protected: 00065 void show_buffers (struct iovec *iov ); 00066 00067 private: 00069 MNTCPSocket& operator=( const MNTCPSocket& ); 00071 MNTCPSocket( const MNTCPSocket& ); 00072 public: 00073 MNTCPSocket ( ); 00074 MNTCPSocket ( int i ); 00075 MNTCPSocket ( int i, CreationMode mode ); 00076 00077 virtual ~MNTCPSocket ( ); 00078 00079 void warn_errors ( int errval ); 00080 00081 virtual void callback( MNSelector* select, int fd ) = 0; 00082 virtual void tcallback() { }; /* needed for thread exit */ 00083 00089 inline virtual bool isUdp() const {return false;} 00090 00096 virtual Fail connect( int port, const char *hostname ); 00097 00103 virtual Fail connect( const struct sockaddr_in& dest ); 00104 00109 int read( char* buffer, int len ); 00110 int write( const char* buf, int len ); 00111 00126 bool getLocalSockAddr( struct sockaddr_in& addr ); 00127 00137 bool getRemoteSockAddr( struct sockaddr_in& addr ); 00138 }; 00139 00140 /*********************************************************************** 00141 * MNTCPClientSocket 00142 * 00143 * MNTCPClientSocket is a helper class to open and manage TCP sockets 00144 * consistently although other mechanisms are used for the actual 00145 * interaction with the socket. It may be used to keep a socket open 00146 * until its management is taken over by another class. 00147 * 00148 * Note that a standard TCPServerSocket receiver will add an object of 00149 * this class to its MNSelector in a standard callback() function. If 00150 * the user of this class does not suppress this, it will crash the 00151 * program. 00152 * 00153 * Write functions of this class may be used but read() functions of 00154 * this class are not operational. 00155 ***********************************************************************/ 00156 00157 00158 class MNTCPClientSocket : public MNTCPSocket 00159 { 00160 public: 00161 MNTCPClientSocket( ) 00162 { } 00163 MNTCPClientSocket( int lsocket ) : MNTCPSocket( lsocket ) 00164 { } 00165 00166 virtual void callback ( MNSelector* /*select*/, int /*fd*/ ) 00167 { 00168 MN_FATAL("callback() not implemented for MNTCPClientSocket"); 00169 } 00170 00171 private: 00172 virtual int reader ( struct iovec* /*iov*/ ) 00173 { 00174 MN_FATAL("reader() not implemented for MNTCPClientSocket"); 00175 return 0; 00176 } 00177 00178 virtual void set_buffers ( struct iovec* /*iov*/, int /*iovlen*/ ) 00179 { 00180 MN_FATAL("set_buffers() not implemented for MNTCPClientSocket"); 00181 } 00182 }; 00183 00184 #endif /* MN_TCPSOCKET_H */ 00185

Generated on Sun Mar 6 13:35:49 2005 for Komssys by doxygen 1.3.8