SocketMC.hh

Go to the documentation of this file.
00001 // ----------------------------------------------------------------------------
00002 // CERTI - HLA RunTime Infrastructure
00003 // Copyright (C) 2002-2005  ONERA
00004 //
00005 // This program is free software ; you can redistribute it and/or
00006 // modify it under the terms of the GNU Lesser General Public License
00007 // as published by the Free Software Foundation ; either version 2 of
00008 // the License, or (at your option) any later version.
00009 //
00010 // This program is distributed in the hope that it will be useful, but
00011 // WITHOUT ANY WARRANTY ; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00013 // Lesser General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU Lesser General Public
00016 // License along with this program ; if not, write to the Free Software
00017 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00018 // ----------------------------------------------------------------------------
00019 
00020 #ifndef CERTI_SOCKET_MC_HH
00021 #define CERTI_SOCKET_MC_HH
00022 
00023 #include "Socket.hh"
00024 #include "NetworkMessage.hh"
00025 
00026 #ifdef _WIN32
00027     #ifndef _WINSOCK2API_
00028     #ifndef _WINSOCKAPI_
00029     #include <winsock.h>
00030     #endif
00031     #endif
00032 #if __MINGW32__
00033     #define IP_ADD_MEMBERSHIP   5
00034     struct ip_mreq {
00035         struct in_addr imr_multiaddr;
00036         struct in_addr imr_interface;
00037     };
00038 #endif
00039 #else
00040     #include <sys/socket.h>
00041     #include <netinet/in.h>
00042 #endif
00043 namespace certi {
00044 
00045 class SocketMC : public Socket
00046 {
00047 public:
00048     int _socket_mc ;
00049     bool _est_init_mc ;
00050 
00051     SocketMC();
00052     virtual ~SocketMC();
00053 
00054     void CreerSocketMC(char *addr, unsigned long port);
00055     void CreerSocketMC(unsigned long addr, unsigned long port);
00056 
00057     virtual void send(const unsigned char *, size_t)
00058       throw (NetworkError, NetworkSignal);
00059     virtual void receive(void *Buffer, unsigned long Size)
00060       throw (NetworkError, NetworkSignal);
00061 
00062     #ifdef _WIN32
00063                 SOCKET returnSocket();
00064     #else
00065         virtual int returnSocket();
00066     #endif
00067 
00068     virtual unsigned long returnAdress() const ;
00069     virtual void close();
00070 
00071     void sendMC(NetworkMessage *msg);
00072     char *receiveMC(NetworkMessage *msg);
00073     
00074 private:
00075     struct sockaddr_in _sin ;
00076     struct sockaddr_in _sin_e ;
00077     #ifdef _WIN32
00078         int _sinlen;
00079         SOCKET _socket_emetteur;
00080     #else
00081         socklen_t _sinlen;
00082         int _socket_emetteur;
00083     #endif    
00084     int _sinlen_e ;
00085 
00086     int timeoutMC(int, int);
00087 
00088     int _num_msg ;
00089 };
00090 
00091 } // namespace certi
00092 
00093 #endif // CERTI_SOCKET_MC_HH

Generated on Thu Apr 30 15:53:50 2009 for CERTIDeveloperDocumentation by doxygen 1.5.5