SocketUN.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_UN_HH
00021 #define CERTI_SOCKET_UN_HH
00022 
00023 #if defined(RTIA_USE_TCP)
00024     #include "SocketTCP.hh"
00025 #else
00026     #include <netdb.h>
00027     #include <sys/socket.h>
00028 #endif
00029 
00030 #define NOM_FICHIER_SOCKET ".comFedRTI"
00031 #include "Socket.hh"
00032 #include "PrettyDebug.hh"
00033 
00034 namespace certi {
00035 // Signal Handler Types for a UNIX socket : - stSignalInterrupt :
00036 // return when read/write operation is interrupted by a signal. The
00037 // RW operation may not be complete. - stSignalIgnore : Ignore
00038 // signal interruption and continue to perform the RW operation till
00039 // its done. LibRTI will use the stSignalIgnore, RTIA will use
00040 // stSignalInterrupt.
00041 typedef enum { stSignalInterrupt, stIgnoreSignal } SignalHandlerType ;
00042 
00043 // This is the read buffer of UNIX sockets. It must be at least as
00044 // long as the longest data ever received by a socket. If the next
00045 // line is commented out, no buffer will be used at all.
00046 //#define SOCKUN_BUFFER_LENGTH 4096
00047 
00062 class CERTI_EXPORT SocketUN
00063 {
00064 public:
00065     SocketUN(SignalHandlerType theType = stSignalInterrupt);
00066     ~SocketUN();
00067 
00068     #ifdef _WIN32
00069         void connectUN(int Server_pid);         // Called by client to connect
00070     #else
00071         int connectUN(pid_t Server_pid);
00072     #endif
00073     void acceptUN(int RTIA_port);                                   //Called by server
00074 
00075     bool isDataReady();
00076 
00077     #ifdef _WIN32
00078         SOCKET returnSocket();
00079     #else
00080         int returnSocket();
00081     #endif
00082 
00083     void send(const unsigned char *, size_t)        throw (NetworkError, NetworkSignal);
00084     void receive(const unsigned char *, size_t) throw (NetworkError, NetworkSignal);
00085 
00086 protected:
00087     void error(const char *) throw (NetworkError);
00088 
00089     #ifdef _WIN32
00090         SOCKET _socket_un;
00091     #else
00092         int _socket_un;
00093     #endif
00094 
00095     bool _est_serveur ;
00096     bool _est_init_un ;
00097 
00098     SignalHandlerType HandlerType ;
00099 
00100     std::string name ;
00101 
00102 private:
00103 
00104     Socket::ByteCount_t SentBytesCount ;
00105     Socket::ByteCount_t RcvdBytesCount ;
00106 
00107     // la socket du serveur RTIA qui a ete cree par le federe-client
00108     int sock_connect ;
00109 
00110     pdCDebug *pD ;
00111 
00112     #ifdef SOCKUN_BUFFER_LENGTH
00113         // This class can use a buffer to reduce the number of systems
00114         // calls when reading a lot of small amouts of data. Each time a
00115         // Receive is made, it will try to read SOCKUN_BUFFER_LENGTH
00116 
00117         char ReadBuffer[SOCKUN_BUFFER_LENGTH] ;
00118         unsigned long RBLength ;
00119     #endif
00120 };
00121 
00122 } // namespace certi
00123 
00124 #endif // CERTI_SOCKET_UN_HH

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