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

MNUDPServerSocket.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_OS_NET_UDPSERVERSOCKET_H 00025 #define MN_OS_NET_UDPSERVERSOCKET_H 00026 00027 /************************************************************* 00028 * Classes defined in this header file: 00029 * MNUDPServerSocket 00030 */ 00031 00032 /************************************************************* 00033 * UDPSocket 00034 */ 00035 00036 #include <strings.h> 00037 #include <sys/uio.h> 00038 #include "MNSocket.h" 00039 #include "MNSelector.h" 00040 #include "MNThread.h" 00041 #include "MNMutex.h" 00042 #include "MNUDPSocket.h" 00043 #include "MNValid.h" 00044 00045 /* The Linux netinet header files are a shame, because they're completely 00046 * inconsitant compared to what the standards define. 00047 * Better check if this is defined in the 2.2.2 Kernel 00048 */ 00049 00050 #define IP_RECVDSTADDR 7 /* bool; receive IP dst addr w/datagram */ 00051 00052 /**********************************************************************/ 00053 /* MNUDPServerSocket */ 00054 /**********************************************************************/ 00055 00065 class MNUDPServerSocket : public MNUDPSocket 00066 { 00067 DECLARE_VALID 00068 00069 public: 00070 class Interfaces 00071 { 00072 struct ifi_info* interf; 00073 00074 void delete_interf() 00075 { 00076 // free ifi_info in iface 00077 00078 struct ifi_info* ifi; 00079 struct ifi_info* ifinext; 00080 00081 for (ifi = interf; ifi != NULL; ifi = ifinext) 00082 { 00083 if (ifi->ifi_addr != NULL) free(ifi->ifi_addr); 00084 if (ifi->ifi_brdaddr != NULL) free(ifi->ifi_brdaddr); 00085 if (ifi->ifi_dstaddr != NULL) free(ifi->ifi_dstaddr); 00086 00087 // can't fetch ifi_next after free() 00088 ifinext = ifi->ifi_next; 00089 00090 // free the ifi_info{} itself 00091 free(ifi); 00092 } 00093 interf = NULL; 00094 } 00095 00096 public: 00097 Interfaces ( ) 00098 { 00099 interf = NULL; 00100 } 00101 00102 ~Interfaces ( ) 00103 { 00104 delete_interf(); 00105 } 00106 00107 struct ifi_info* get_interf() { 00108 return interf; 00109 }; 00110 00111 void set_interf( struct ifi_info* ifi ) { 00112 delete_interf(); 00113 interf = ifi; 00114 }; 00115 }; 00116 00117 private: 00118 class Dest 00119 { 00120 const char* destname; 00121 public: 00122 int destport; 00123 00124 Dest& operator=( const Dest& orig ) 00125 { 00126 destname = strdup(orig.destname); 00127 destport = orig.destport; 00128 return *this; 00129 } 00130 00131 Dest( const Dest& orig ) 00132 { 00133 destname = strdup(orig.destname); 00134 destport = orig.destport; 00135 } 00136 00137 Dest() 00138 { 00139 destname = NULL; 00140 destport = 0; 00141 } 00142 00143 Dest( const char* name, int port ) 00144 : destport(port) 00145 { 00146 destname = strdup(name); 00147 } 00148 }; 00149 struct Dest* _dest; 00150 00151 MNSelector& _selector; 00152 00153 /* 00154 * Protect the stop function from reentry. 00155 */ 00156 MNMutex _stopEntryLock; 00157 00158 typedef MNUDPSocket::CallbackSetting CBSetting; 00159 public: 00160 00161 00162 MNUDPServerSocket ( MNUDPServerSocket& orig ); 00163 00164 MNUDPServerSocket ( MNSelector& sel, 00165 CBSetting cs ); 00166 00167 MNUDPServerSocket ( MNSelector& sel, 00168 int fd, 00169 int zero, 00170 CBSetting cs ); 00171 00172 MNUDPServerSocket ( MNSelector& sel, 00173 int port, 00174 CBSetting cs ); 00175 00176 MNUDPServerSocket ( MNSelector& sel, 00177 int port, 00178 char* hostname, 00179 CBSetting cs ); 00180 00181 MNUDPServerSocket ( MNSelector& sel, 00182 int port, 00183 char* hostname, 00184 Interfaces* intf ); 00185 00186 MNUDPServerSocket ( MNSelector& sel, 00187 MNSocket& orig, 00188 CBSetting cs = MNUDPSocket::IovecMode, 00189 int copyflags = MNSocket::TakeoverFlag ); 00190 virtual ~MNUDPServerSocket ( ); 00191 00192 virtual void activate(); 00193 00194 void stopUdpServer(); 00195 00199 MNSelector& getSelector( ); 00200 00201 int mc_join_all(int port, const char* hostname, Interfaces* intf); 00202 int mc_leave_all(int sockfd, struct sockaddr *sock_addr, Interfaces* intf); 00203 }; 00204 00205 #endif /* MN_OS_NET_UDPSERVERSOCKET_H */ 00206 00207

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