[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[certi-cvs] certi doc/.cvsignore libpdebug/.cvsignore libCE... [CERTI-SH
From: |
certi-cvs |
Subject: |
[certi-cvs] certi doc/.cvsignore libpdebug/.cvsignore libCE... [CERTI-SHM] |
Date: |
Wed, 08 Jul 2009 14:45:40 +0000 |
CVSROOT: /sources/certi
Module name: certi
Branch: CERTI-SHM
Changes by: Eric NOULARD <erk> 09/07/08 14:45:40
Added files:
doc : .cvsignore
libpdebug : .cvsignore
libCERTI : SocketSHM.cc_v1 .cvsignore CCom.hh SocketSHM.cc
SocketSHM.hh CCom.cc
include : .cvsignore
Log message:
store CERTI SHM (HP CERTI modification)
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/certi/doc/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.3.6.2
http://cvs.savannah.gnu.org/viewcvs/certi/libpdebug/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHM.cc_v1?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.2.6.2
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/CCom.hh?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHM.cc?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/SocketSHM.hh?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/libCERTI/CCom.cc?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.1.2.1
http://cvs.savannah.gnu.org/viewcvs/certi/include/.cvsignore?cvsroot=certi&only_with_tag=CERTI-SHM&rev=1.2.6.2
Patches:
Index: doc/.cvsignore
===================================================================
RCS file: doc/.cvsignore
diff -N doc/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ doc/.cvsignore 8 Jul 2009 14:45:39 -0000 1.3.6.2
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
Index: libpdebug/.cvsignore
===================================================================
RCS file: libpdebug/.cvsignore
diff -N libpdebug/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libpdebug/.cvsignore 8 Jul 2009 14:45:39 -0000 1.1.2.1
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
Index: libCERTI/SocketSHM.cc_v1
===================================================================
RCS file: libCERTI/SocketSHM.cc_v1
diff -N libCERTI/SocketSHM.cc_v1
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHM.cc_v1 8 Jul 2009 14:45:39 -0000 1.1.2.1
@@ -0,0 +1,403 @@
+// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002, 2003 ONERA
+//
+// This file is part of CERTI-libCERTI
+//
+// CERTI-libCERTI is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// CERTI-libCERTI is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+//
+// $Id: SocketSHM.cc_v1,v 1.1.2.1 2009/07/08 14:45:39 erk Exp $
+// ----------------------------------------------------------------------------
+
+#include "SocketSHM.hh"
+
+namespace certi {
+
+static pdCDebug D("SOCKSHM", "(SocketSHM) - ");
+
+
+// ----------------------------------------------------------------------------
+//! accept.
+int SocketSHM::accept(SocketTCP *serveur)
+{
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+ struct protoent *TCPent ;
+ int optval = 1 ;
+ socklen_t l ;
+
+ assert(serveur != NULL);
+
+ l = sizeof(_sockIn);
+
+ _socket_tcp = ::accept(serveur->returnSocket(), (sockaddr*)&_sockIn, &l);
+ //HPUX: _socket_tcp = accept(serveur->_socket_tcp, (sockaddr*)&_sockIn,
+ //(int*) &l);
+ if (_socket_tcp < 0) {
+ perror("SocketTCP: Accept");
+ exit(-1);
+ }
+
+ // Set the TCP_NODELAY option(Server Side)
+ TCPent = getprotobyname("tcp");
+ if (TCPent == NULL) {
+ cout << "Unable to retrieve TCP protocol number." << endl ;
+ return 0 ;
+ }
+
+ if (setsockopt(_socket_tcp,
+ TCPent->p_proto,
+ TCP_NODELAY,
+ (char *) &optval,
+ sizeof(optval))) {
+ cout << "Error while calling setsockopt." << endl ;
+ return 0 ;
+ }
+ D.Out(pdTrace, "Acceptation d'une connexion cote serveur") ;
+ isServer = true;
+ if ((shmId = shmget (IPC_PRIVATE, sizeof(SHM),IPC_CREAT|0666)) == -1)
+ { perror ("shmget"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Creating shared memory with id = %d", shmId) ;
+
+ /* attachement a une adresse non fixee */
+
+ if ((shm = (SHM *) shmat(shmId, 0 ,0)) == (SHM *) -1)
+ { perror ("shmat"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Shared memory attached") ;
+
+
+ shm -> S_C.qui = EMPTY ; // le segment est libre en écriture
+ shm -> C_S.qui = EMPTY ;
+
+ int ctrl;
+ write(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ read(_socket_tcp,&ctrl,(unsigned) sizeof(int));
+ if(ctrl != shmId) cout<< "erreur de transmission de l'identifiant shm";
+ ::close(_socket_tcp);
+
+ return shmId;
+}
+
+// ----------------------------------------------------------------------------
+//! createSHMClient
+void
+SocketSHM::createSHMClient(unsigned int port, char *nom_serveur){
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+
+
+ D.Out(pdTrace, "Creation socket cote client") ;
+
+ _socket_tcp=socket(AF_INET, SOCK_STREAM, 0);
+
+ D.Out(pdTrace, "Recuperation des infos sur le serveur") ;
+ // recuperer les infos sur le serveur a partir du nom
+ struct hostent *hptr = gethostbyname(nom_serveur);
+ if (hptr == 0) {
+ perror("SocketTCP: gethostbyname");
+ exit(-1);
+ }
+
+ unsigned long addr = 0 ;
+ memcpy((void *) &addr, (void *) hptr->h_addr, hptr->h_length);
+
+
+ int Result ;
+ struct protoent *TCPent ;
+ int optval = 1 ;
+
+ _sockIn.sin_family=AF_INET ;
+ _sockIn.sin_port=htons(port);
+ _sockIn.sin_addr.s_addr=addr ;
+
+ D.Out(pdTrace, "Tentative de connexion") ;
+ Result = ::connect(_socket_tcp, (sockaddr*)&_sockIn, sizeof(_sockIn));
+
+ if (Result < 0)
+ return ;
+
+ // Set the TCP_NODELAY option(Client Side)
+
+ TCPent = getprotobyname("tcp");
+ if (TCPent == NULL) {
+ cout << "Unable to retrieve TCP protocol number." << endl ;
+ return ;
+ }
+
+ if (setsockopt(_socket_tcp,
+ TCPent->p_proto,
+ TCP_NODELAY,
+ (char *) &optval,
+ sizeof(optval))) {
+ cout << "Error while calling setsockopt." << endl ;
+ return ;
+ }
+ D.Out(pdTrace, "Lecture des informations de connexion") ;
+ read(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ write(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ ::close(_socket_tcp);
+
+ D.Out(pdTrace, "Attachement de la memoire") ;
+ isServer = false;
+ //shmId = id_shm;
+ if ((shm = (SHM *) shmat(shmId, 0 ,0)) == (SHM *) -1)
+ { perror ("shmat"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Shared memory attached with id = %d", shmId) ;
+}
+
+
+// ----------------------------------------------------------------------------
+//! Constructor.
+SocketSHM::SocketSHM(void)
+{
+}
+// ----------------------------------------------------------------------------
+//! Destructor.
+SocketSHM::~SocketSHM(void)
+{
+ // Fermeture
+ //if (_est_init_tcp)
+ close();
+/*
+#ifdef RTI_PRINTS_STATISTICS
+ cout << endl ;
+ cout << "TCP Socket(" << _socket_tcp << "): Total Sent Bytes : "
+ << SentBytesCount << '.' << endl ;
+ cout << "TCP Socket(" << _socket_tcp << "): Total Received Bytes : "
+ << RcvdBytesCount << '.' << endl ;
+ cout << endl ;
+#endif
+*/
+}
+
+// ----------------------------------------------------------------------------
+//! send.
+void SocketSHM::send(void *Buffer, unsigned long Size)
+{
+ if(isServer){
+ D.Out(pdTrace, "Ecriture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en ecriture cote serveur") ;
+ while(shm->S_C.qui==FULL)D.Out(pdTrace, "S_C.qui : %c",shm->S_C.qui);
+ D.Out(pdTrace, "Ecriture debloque cote serveur : writing Header") ;
+ shm->S_C.Header = ((SharedMemory *)Buffer)->Header;
+ D.Out(pdTrace, "writing body") ;
+ shm->S_C.Body = ((SharedMemory *)Buffer)->Body;
+ shm->S_C.qui=FULL;
+ D.Out(pdTrace, "S_C.qui positionne a : %c",shm->S_C.qui) ;
+ }
+ else{
+ D.Out(pdTrace, "Ecriture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en Ecriture cote client") ;
+ int result=shm->C_S.qui;
+ while(result==FULL)result=shm->C_S.qui;
+ D.Out(pdTrace, "Ecriture debloque cote client : writing Header") ;
+ shm->C_S.Header = ((SharedMemory *)Buffer)->Header;
+ D.Out(pdTrace, "writing body") ;
+ shm->C_S.Body = ((SharedMemory *)Buffer)->Body;
+ shm->C_S.qui=FULL;
+ D.Out(pdTrace, "C_S.qui positionne a : %c",shm->C_S.qui) ;
+ }
+ /*long nSent = 0 ;
+ long total_sent = 0 ;
+ long expected_size = Size ;
+
+ assert(_est_init_tcp);
+
+ D.Out(pdDebug, "Beginning to send SHM message...");
+
+ while (total_sent < expected_size) {
+ nSent = ::send(_socket_tcp,
+ (char *) Buffer + total_sent,
+ expected_size - total_sent,
+ 0);
+
+ if (nSent < 0) {
+ D.Out(pdExcept, "Error while sending on TCP socket.");
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else {
+ perror("TCP Socket(EmettreTCP) ");
+ throw NetworkError("Error while sending TCP message.");
+ }
+ }
+
+ if (nSent == 0) {
+ D.Out(pdExcept, "No data could be sent, connection closed?.");
+ throw NetworkError("Could not send any data on TCP socket.");
+ }
+
+ total_sent += nSent ;
+ D.Out(pdTrace, "Sent %ld bytes out of %ld.", total_sent,
expected_size);
+ }
+
+ SentBytesCount += total_sent ;*/
+}
+
+// ----------------------------------------------------------------------------
+//! close.
+void SocketSHM::close(void)
+{
+ if(isServer){
+ /* detachement des segments memoire*/
+ if(shmdt(shm)){
+ perror("Echec du shmdt car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detachee cotee serveur") ;
+
+
+ /*Destruction des segments memoire */
+ if(shmctl(shmId, IPC_RMID,0)){
+ perror("Echec de shmctl(IPC_RMID) car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detruite") ;
+ }
+ else{
+ /* detachement des segments memoire*/
+ if(shmdt(shm)){
+ perror("Echec du shmdt car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detachee cotee client") ;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+/*! Return RTI_TRUE if any data as already been read from the system socket
+ and is waiting in the internal buffer, else RTI_FALSE.
+*/
+Boolean
+SocketSHM::isDataReady(void) const
+{
+ if(isServer){
+ if (shm->C_S.qui == FULL) return RTI_TRUE;
+ else return RTI_FALSE;
+ }
+ else{
+ if (shm->S_C.qui == FULL) return RTI_TRUE;
+ else return RTI_FALSE;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+//! receive.
+void SocketSHM::receive(void *Buffer, unsigned long Size)
+{
+ if(isServer){
+ D.Out(pdTrace, "Lecture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en lecture cote serveur") ;
+ while(shm->C_S.qui==EMPTY)D.Out(pdTrace, "C_S.qui : %c",shm->C_S.qui);
+ D.Out(pdTrace, "Lecture debloque cote serveur : reading Header") ;
+ ((SharedMemory *)Buffer)->Header = shm->C_S.Header;
+ D.Out(pdTrace, "reading body") ;
+ ((SharedMemory *)Buffer)->Body = shm->C_S.Body;
+ shm->C_S.qui=EMPTY;
+ D.Out(pdTrace, "C_S.qui positionne a : %c",shm->C_S.qui) ;
+ }
+ else{
+ D.Out(pdTrace, "Lecture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en lecture cote client") ;
+ int result=shm->S_C.qui;
+ while(result==EMPTY)result=shm->S_C.qui;
+ D.Out(pdTrace, "Lecture debloque cote client : reading Header") ;
+ ((SharedMemory *)Buffer)->Header = shm->S_C.Header;
+ D.Out(pdTrace, "reading body") ;
+ ((SharedMemory *)Buffer)->Body = shm->S_C.Body;
+ shm->S_C.qui=EMPTY;
+ D.Out(pdTrace, "S_C.qui positionne a : %c",shm->S_C.qui) ;
+ }
+
+ /*
+ assert(_est_init_tcp);
+
+ long nReceived = 0 ;
+#ifndef SOCKTCP_BUFFER_LENGTH
+ long RBLength = 0 ;
+#endif
+
+ D.Out(pdDebug, "Beginning to receive TCP message...");
+
+ while (RBLength < Size)
+ {
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ nReceived = recv(_socket_tcp,
+ ReadBuffer + RBLength,
+ SOCKTCP_BUFFER_LENGTH - RBLength,
+ 0);
+#else
+ nReceived = recv(_socket_tcp,
+ (char *) Buffer + RBLength,
+ Size - RBLength,
+ 0);
+#endif
+
+ if (nReceived < 0) {
+ D.Out(pdExcept, "Error while receiving on TCP socket.");
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else {
+ perror("TCP Socket(RecevoirTCP) ");
+ throw NetworkError("Error while receiving TCP message.");
+ }
+ }
+
+ if (nReceived == 0) {
+ D.Out(pdExcept, "TCP connection has been closed by peer.");
+ throw NetworkError("Connection closed by client.");
+ }
+
+ RBLength += nReceived ;
+ RcvdBytesCount += nReceived ;
+
+ D.Out(pdTrace, "Received %ld bytes out of %ld.", RBLength, Size);
+ }
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ memcpy(Buffer, (void *) ReadBuffer, Size);
+ memmove((void *) ReadBuffer,
+ (void *)(ReadBuffer + Size),
+ RBLength - Size);
+ RBLength -= Size ;
+#endif
+*/
+}
+
+// ----------------------------------------------------------------------------
+//! Returns the address.
+unsigned long
+SocketSHM::returnAdress(void) const
+{
+ return (unsigned long) shmId;
+}
+
+// ----------------------------------------------------------------------------
+//! Returns the socket.
+int
+SocketSHM::returnSocket(void) const
+{
+ return shmId;
+}
+
+}
+
+// $Id: SocketSHM.cc_v1,v 1.1.2.1 2009/07/08 14:45:39 erk Exp $
Index: libCERTI/.cvsignore
===================================================================
RCS file: libCERTI/.cvsignore
diff -N libCERTI/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/.cvsignore 8 Jul 2009 14:45:39 -0000 1.2.6.2
@@ -0,0 +1,2 @@
+Makefile.in
+Makefile
Index: libCERTI/CCom.hh
===================================================================
RCS file: libCERTI/CCom.hh
diff -N libCERTI/CCom.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/CCom.hh 8 Jul 2009 14:45:39 -0000 1.1.2.1
@@ -0,0 +1,89 @@
+// **** DEBUT ENTETE *********************************************************
+//
+// Copyright 1997 ONERA
+//
+//
+//_NOM : hla/test/test_msg/CSockServer.hh
+//
+//_VERSION : 1.1
+//
+//_HISTORIQUE :
+// 1.1 Creation par Thomas Hautesserres (address@hidden).
+//
+//_DESCRIPTION : Classe CSockServer, qui simule un serveur recevant des
+// CMessageReseau d'une autre classe CSockClient, a travers une connexion
+// TCP encapsulee dans la classe CSocketTCP (fichier ../util/sockTCP.hh).
+//
+//_CONTEXTE : Test de performance des differentes implementations des
+// CMessageReseau et des CSocket*.
+//
+//_CATEGORIE : Composant de l'implementation de HLA dans le cadre de SAIDA
+//
+//_SYNOPSIS :
+//
+//_ENTREE :
+//
+//_SORTIE :
+//
+//_MODIFIEE :
+//
+//_LOCALE :
+//
+//_DIAGNOSTIC :
+//
+//_BUGS CONNUS : ?
+//
+//_VOIR AUSSI : le fichier README.
+//
+// **** FIN ENTETE ***********************************************************
+
+#ifndef CCOM_HH
+#define CCOM_HH
+
+#include "setup.hh"
+#include "SocketTCP.hh"
+#include "NetworkMessage.hh"
+#include "SocketServer.hh"
+
+using namespace certi ;
+
+class CCom {
+
+public:
+
+ // --------------------------------
+ // -- Constructor and Destructor --
+ // --------------------------------
+
+ // The first parameter is the function called when NULL messages are
+ // received, and the second is called when UAV messages are received.
+ CCom (ProcessFunction *NullProcess = NULL,
+ ProcessFunction *UAVProcess = NULL) ;
+
+ virtual ~CCom () ;
+
+
+ // ------------------
+ // -- Main Methods --
+ // ------------------
+
+ // Return the number Messages received (of all types)
+ virtual long Main (unsigned int Time=0)=0;
+
+ // Should be called whenever a signal is caught (stop the main loop)
+ virtual void SignalHandler (int Sig)=0;
+
+private:
+
+ // ------------------------
+ // -- Private Attributes --
+ // ------------------------
+
+ char EndLoop;
+
+};
+
+ // } // end namespace
+
+#endif // CCOM_HH
+
Index: libCERTI/SocketSHM.cc
===================================================================
RCS file: libCERTI/SocketSHM.cc
diff -N libCERTI/SocketSHM.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHM.cc 8 Jul 2009 14:45:39 -0000 1.1.2.1
@@ -0,0 +1,415 @@
+// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002, 2003 ONERA
+//
+// This file is part of CERTI-libCERTI
+//
+// CERTI-libCERTI is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// CERTI-libCERTI is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+//
+// $Id: SocketSHM.cc,v 1.1.2.1 2009/07/08 14:45:39 erk Exp $
+// ----------------------------------------------------------------------------
+
+#include "SocketSHM.hh"
+
+namespace certi {
+
+static pdCDebug D("SOCKSHM", "(SocketSHM) - ");
+
+
+// ----------------------------------------------------------------------------
+//! accept.
+int SocketSHM::accept(SocketTCP *serveur)
+{
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+ struct protoent *TCPent ;
+ int optval = 1 ;
+ socklen_t l ;
+
+ assert(serveur != NULL);
+
+ l = sizeof(_sockIn);
+
+ _socket_tcp = ::accept(serveur->returnSocket(), (sockaddr*)&_sockIn, &l);
+ //HPUX: _socket_tcp = accept(serveur->_socket_tcp, (sockaddr*)&_sockIn,
+ //(int*) &l);
+ if (_socket_tcp < 0) {
+ perror("SocketTCP: Accept");
+ exit(-1);
+ }
+
+ // Set the TCP_NODELAY option(Server Side)
+ TCPent = getprotobyname("tcp");
+ if (TCPent == NULL) {
+ cout << "Unable to retrieve TCP protocol number." << endl ;
+ return 0 ;
+ }
+
+ if (setsockopt(_socket_tcp,
+ TCPent->p_proto,
+ TCP_NODELAY,
+ (char *) &optval,
+ sizeof(optval))) {
+ cout << "Error while calling setsockopt." << endl ;
+ return 0 ;
+ }
+ D.Out(pdTrace, "Acceptation d'une connexion cote serveur") ;
+ isServer = true;
+ if ((shmId = shmget (IPC_PRIVATE, sizeof(SHM),IPC_CREAT|0666)) == -1)
+ { perror ("shmget"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Creating shared memory with id = %d", shmId) ;
+
+ /* attachement a une adresse non fixee */
+
+ if ((shm = (SHM *) shmat(shmId, 0 ,0)) == (SHM *) -1)
+ { perror ("shmat"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Shared memory attached") ;
+
+
+ shm -> S_C.qui = EMPTY ; // le segment est libre en écriture
+ shm -> C_S.qui = EMPTY ;
+
+ int ctrl;
+ write(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ read(_socket_tcp,&ctrl,(unsigned) sizeof(int));
+ if(ctrl != shmId) cout<< "erreur de transmission de l'identifiant shm";
+ ::close(_socket_tcp);
+
+ return shmId;
+}
+
+// ----------------------------------------------------------------------------
+//! createSHMClient
+void
+SocketSHM::createSHMClient(unsigned int port, char *nom_serveur){
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+
+
+ D.Out(pdTrace, "Creation socket cote client") ;
+
+ _socket_tcp=socket(AF_INET, SOCK_STREAM, 0);
+
+ D.Out(pdTrace, "Recuperation des infos sur le serveur") ;
+ // recuperer les infos sur le serveur a partir du nom
+ struct hostent *hptr = gethostbyname(nom_serveur);
+ if (hptr == 0) {
+ perror("SocketTCP: gethostbyname");
+ exit(-1);
+ }
+
+ unsigned long addr = 0 ;
+ memcpy((void *) &addr, (void *) hptr->h_addr, hptr->h_length);
+
+
+ int Result ;
+ struct protoent *TCPent ;
+ int optval = 1 ;
+
+ _sockIn.sin_family=AF_INET ;
+ _sockIn.sin_port=htons(port);
+ _sockIn.sin_addr.s_addr=addr ;
+
+ D.Out(pdTrace, "Tentative de connexion") ;
+ Result = ::connect(_socket_tcp, (sockaddr*)&_sockIn, sizeof(_sockIn));
+
+ if (Result < 0)
+ return ;
+
+ // Set the TCP_NODELAY option(Client Side)
+
+ TCPent = getprotobyname("tcp");
+ if (TCPent == NULL) {
+ cout << "Unable to retrieve TCP protocol number." << endl ;
+ return ;
+ }
+
+ if (setsockopt(_socket_tcp,
+ TCPent->p_proto,
+ TCP_NODELAY,
+ (char *) &optval,
+ sizeof(optval))) {
+ cout << "Error while calling setsockopt." << endl ;
+ return ;
+ }
+ D.Out(pdTrace, "Lecture des informations de connexion") ;
+ read(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ write(_socket_tcp,&shmId,(unsigned) sizeof(int));
+ ::close(_socket_tcp);
+
+ D.Out(pdTrace, "Attachement de la memoire") ;
+ isServer = false;
+ //shmId = id_shm;
+ if ((shm = (SHM *) shmat(shmId, 0 ,0)) == (SHM *) -1)
+ { perror ("shmat"); exit (EXIT_FAILURE);}
+ D.Out(pdTrace, "Shared memory attached with id = %d", shmId) ;
+}
+
+
+// ----------------------------------------------------------------------------
+//! Constructor.
+SocketSHM::SocketSHM(void)
+{
+}
+// ----------------------------------------------------------------------------
+//! Destructor.
+SocketSHM::~SocketSHM(void)
+{
+ // Fermeture
+ //if (_est_init_tcp)
+ close();
+/*
+#ifdef RTI_PRINTS_STATISTICS
+ cout << endl ;
+ cout << "TCP Socket(" << _socket_tcp << "): Total Sent Bytes : "
+ << SentBytesCount << '.' << endl ;
+ cout << "TCP Socket(" << _socket_tcp << "): Total Received Bytes : "
+ << RcvdBytesCount << '.' << endl ;
+ cout << endl ;
+#endif
+*/
+}
+
+// ----------------------------------------------------------------------------
+//! send.
+void SocketSHM::send(void *Buffer, unsigned long Size)
+{
+ if(isServer){
+ D.Out(pdTrace, "Ecriture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en ecriture cote serveur") ;
+ while(shm->S_C.qui==FULL)D.Out(pdTrace, "S_C.qui : %c",shm->S_C.qui);
+ D.Out(pdTrace, "Ecriture debloque cote serveur : writing Header") ;
+ shm->S_C.Header = ((SharedMemory *)Buffer)->Header;
+ D.Out(pdTrace, "writing body") ;
+ shm->S_C.Body = ((SharedMemory *)Buffer)->Body;
+ shm->S_C.qui=FULL;
+ D.Out(pdTrace, "S_C.qui positionne a : %c",shm->S_C.qui) ;
+ }
+ else{
+ D.Out(pdTrace, "Ecriture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en Ecriture cote client") ;
+ int result=shm->C_S.qui;
+ while(result==FULL)result=shm->C_S.qui;
+ D.Out(pdTrace, "Ecriture debloque cote client : writing Header") ;
+ shm->C_S.Header = ((SharedMemory *)Buffer)->Header;
+ D.Out(pdTrace, "writing body") ;
+ shm->C_S.Body = ((SharedMemory *)Buffer)->Body;
+ shm->C_S.qui=FULL;
+ D.Out(pdTrace, "C_S.qui positionne a : %c",shm->C_S.qui) ;
+ }
+ /*long nSent = 0 ;
+ long total_sent = 0 ;
+ long expected_size = Size ;
+
+ assert(_est_init_tcp);
+
+ D.Out(pdDebug, "Beginning to send SHM message...");
+
+ while (total_sent < expected_size) {
+ nSent = ::send(_socket_tcp,
+ (char *) Buffer + total_sent,
+ expected_size - total_sent,
+ 0);
+
+ if (nSent < 0) {
+ D.Out(pdExcept, "Error while sending on TCP socket.");
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else {
+ perror("TCP Socket(EmettreTCP) ");
+ throw NetworkError("Error while sending TCP message.");
+ }
+ }
+
+ if (nSent == 0) {
+ D.Out(pdExcept, "No data could be sent, connection closed?.");
+ throw NetworkError("Could not send any data on TCP socket.");
+ }
+
+ total_sent += nSent ;
+ D.Out(pdTrace, "Sent %ld bytes out of %ld.", total_sent,
expected_size);
+ }
+
+ SentBytesCount += total_sent ;*/
+}
+
+// ----------------------------------------------------------------------------
+//! close.
+void SocketSHM::close(void)
+{
+ if(isServer){
+ /* detachement des segments memoire*/
+ if(shmdt(shm)){
+ perror("Echec du shmdt car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detachee cotee serveur") ;
+
+
+ /*Destruction des segments memoire */
+ if(shmctl(shmId, IPC_RMID,0)){
+ perror("Echec de shmctl(IPC_RMID) car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detruite") ;
+ }
+ else{
+ /* detachement des segments memoire*/
+ if(shmdt(shm)){
+ perror("Echec du shmdt car : ");
+ exit(1);
+ }
+ D.Out(pdTrace, "Memoire detachee cotee client") ;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+/*! Return RTI_TRUE if any data as already been read from the system socket
+ and is waiting in the internal buffer, else RTI_FALSE.
+*/
+Boolean
+SocketSHM::isDataReady(void) const
+{
+ if(isServer){
+ if (shm->C_S.qui == FULL) return RTI_TRUE;
+ else return RTI_FALSE;
+ }
+ else{
+ if (shm->S_C.qui == FULL) return RTI_TRUE;
+ else return RTI_FALSE;
+ }
+}
+
+
+// ----------------------------------------------------------------------------
+//! receive.
+void SocketSHM::receive(void *Buffer, unsigned long Size)
+{
+ if(isServer){
+ D.Out(pdTrace, "Lecture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en lecture cote serveur") ;
+ while(shm->C_S.qui==EMPTY) {
+ D.Out(pdTrace, "C_S.qui : %c",shm->C_S.qui);
+ if (sched_yield ()) {
+ D.Out(pdError, " SocketSHM::receive : sched_yield problem"); exit
(-1) ;
+ }
+
+ }
+ D.Out(pdTrace, "Lecture debloque cote serveur : reading Header") ;
+ ((SharedMemory *)Buffer)->Header = shm->C_S.Header;
+ D.Out(pdTrace, "reading body") ;
+ ((SharedMemory *)Buffer)->Body = shm->C_S.Body;
+ shm->C_S.qui=EMPTY;
+ D.Out(pdTrace, "C_S.qui positionne a : %c",shm->C_S.qui) ;
+ }
+ else{
+ D.Out(pdTrace, "Lecture sur SHM %d",shmId) ;
+ D.Out(pdTrace, "Socket bloque en lecture cote client") ;
+ int result=shm->S_C.qui;
+ while(result==EMPTY) {
+ if (sched_yield ()) {
+ D.Out(pdError, " SocketSHM::receive : sched_yield problem"); exit
(-1) ;
+ }
+
+ result=shm->S_C.qui;
+ }
+ D.Out(pdTrace, "Lecture debloque cote client : reading Header") ;
+ ((SharedMemory *)Buffer)->Header = shm->S_C.Header;
+ D.Out(pdTrace, "reading body") ;
+ ((SharedMemory *)Buffer)->Body = shm->S_C.Body;
+ shm->S_C.qui=EMPTY;
+ D.Out(pdTrace, "S_C.qui positionne a : %c",shm->S_C.qui) ;
+ }
+
+ /*
+ assert(_est_init_tcp);
+
+ long nReceived = 0 ;
+#ifndef SOCKTCP_BUFFER_LENGTH
+ long RBLength = 0 ;
+#endif
+
+ D.Out(pdDebug, "Beginning to receive TCP message...");
+
+ while (RBLength < Size)
+ {
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ nReceived = recv(_socket_tcp,
+ ReadBuffer + RBLength,
+ SOCKTCP_BUFFER_LENGTH - RBLength,
+ 0);
+#else
+ nReceived = recv(_socket_tcp,
+ (char *) Buffer + RBLength,
+ Size - RBLength,
+ 0);
+#endif
+
+ if (nReceived < 0) {
+ D.Out(pdExcept, "Error while receiving on TCP socket.");
+ if (errno == EINTR)
+ throw NetworkSignal();
+ else {
+ perror("TCP Socket(RecevoirTCP) ");
+ throw NetworkError("Error while receiving TCP message.");
+ }
+ }
+
+ if (nReceived == 0) {
+ D.Out(pdExcept, "TCP connection has been closed by peer.");
+ throw NetworkError("Connection closed by client.");
+ }
+
+ RBLength += nReceived ;
+ RcvdBytesCount += nReceived ;
+
+ D.Out(pdTrace, "Received %ld bytes out of %ld.", RBLength, Size);
+ }
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ memcpy(Buffer, (void *) ReadBuffer, Size);
+ memmove((void *) ReadBuffer,
+ (void *)(ReadBuffer + Size),
+ RBLength - Size);
+ RBLength -= Size ;
+#endif
+*/
+}
+
+// ----------------------------------------------------------------------------
+//! Returns the address.
+unsigned long
+SocketSHM::returnAdress(void) const
+{
+ return (unsigned long) shmId;
+}
+
+// ----------------------------------------------------------------------------
+//! Returns the socket.
+int
+SocketSHM::returnSocket(void) const
+{
+ return shmId;
+}
+
+}
+
+// $Id: SocketSHM.cc,v 1.1.2.1 2009/07/08 14:45:39 erk Exp $
Index: libCERTI/SocketSHM.hh
===================================================================
RCS file: libCERTI/SocketSHM.hh
diff -N libCERTI/SocketSHM.hh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/SocketSHM.hh 8 Jul 2009 14:45:39 -0000 1.1.2.1
@@ -0,0 +1,197 @@
+// -*- mode:C++ ; tab-width:4 ; c-basic-offset:4 ; indent-tabs-mode:nil -*-
+// ----------------------------------------------------------------------------
+// CERTI - HLA RunTime Infrastructure
+// Copyright (C) 2002, 2003 ONERA
+//
+// This file is part of CERTI-libCERTI
+//
+// CERTI-libCERTI is free software ; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public License
+// as published by the Free Software Foundation ; either version 2 of
+// the License, or (at your option) any later version.
+//
+// CERTI-libCERTI is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY ; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this program ; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+// USA
+//
+// $Id: SocketSHM.hh,v 1.1.2.1 2009/07/08 14:45:39 erk Exp $
+// ----------------------------------------------------------------------------
+
+#ifndef _CERTI_SOCKET_SHM_HH
+#define _CERTI_SOCKET_SHM_HH
+
+#include <config.h>
+
+#include <iostream>
+using std::cout ;
+using std::endl ;
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/time.h>
+#include <signal.h>
+#include <errno.h>
+#include <cstring>
+#include <ulimit.h>
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <netinet/tcp.h>
+
+#include "Socket.hh"
+#include "SocketTCP.hh"
+#include "RTItypes.hh"
+#include "PrettyDebug.hh"
+
+#include "MessageBody.hh"
+#include "NetworkMessage.hh"
+
+// This is the read buffer of TCP sockets. It must be at least as long
+// as the longest data ever received by a socket.
+// If the next line is commented out, no buffer will be used at all.
+#define SOCKSHM_BUFFER_LENGTH 4096
+
+// Taille de la chaine de caractères du message
+#define TAILLE_MESSAGE 256
+
+// Constantes full and empty
+
+#define FULL '1'
+#define EMPTY '0'
+
+// Nombre max de clients
+#define MAX_CLIENTS 100
+
+#define MAX_EXCEPTION_REASON_LENGTH 100
+
+#define SOCKET_TYPE_SHM 4
+
+namespace certi {
+/*
+// Shared Memory de communication entre client et serveur
+
+typedef struct {
+ char qui ; // char de synchronisation
+ HeaderStruct Header ;
+ MessageBody Body ;
+} SharedMemory ;
+
+typedef struct {
+ SharedMemory S_C ; // Zone serveur vers client
+ SharedMemory C_S ; // Zone client vers serveur
+} SHM ;
+*/
+
+/*! IMPORTANT NOTE: This TCP socket implementation uses a Read Buffer to
+ improve global read performances(by reducing Recv system calls). An
+ important drawback of this improvement is that a socket can be marked as
+ empty for the system, but in fact there is data waiting in the read
+ buffer. This is especially a problem for processes using the 'select'
+ system call: the socket won't be marked as ready for reading, because all
+ data has already been read, and is waiting in the internal buffer.
+ Therefore, before returning to a select loop, be sure to call the
+ IsDataReady method to check whether any data is waiting for processing.
+*/
+class SocketSHM : public Socket
+{
+public :
+ // ---------------------------------------------
+ // -- Fonctions heritee de la classe Socket --
+ // ---------------------------------------------
+
+ void send(void *Buffer, unsigned long Size);
+
+ void receive(void *Buffer, unsigned long Size);
+
+ Boolean isDataReady(void) const ;
+
+ int getClass(void) const { return SOCKET_TYPE_SHM ; };
+ int returnSocket(void) const ;
+
+ unsigned long returnAdress(void) const ;
+
+ void close(void);
+
+ // --------------------------
+ // -- SHM Specific Methods --
+ // --------------------------
+
+ SocketSHM(void);
+ ~SocketSHM(void);
+
+ int accept(SocketTCP *serveur);
+
+ void createSHMClient(unsigned int port, char *nom_serveur);
+ /*
+ int accept(SocketTCP *serveur);
+
+ void createTCPClient(unsigned int port, char *nom_serveur);
+ void createTCPClient(unsigned int port, unsigned long addr);
+ void createTCPServer(unsigned int port = 0, unsigned long addr =
INADDR_ANY);
+
+ SocketTCP & operator= (SocketTCP &theSocket);
+ */
+
+private:
+
+ // ------------------------
+ // -- Private Attributes --
+ // ------------------------
+
+ SHM * shm;
+ int shmId; //identifiant du segment
+
+ bool isServer;
+
+
+ /*
+ long _socket_tcp ;
+
+ struct sockaddr_in _sockIn ;
+ Boolean _est_init_tcp ;
+
+ unsigned long long SentBytesCount ;
+ unsigned long long RcvdBytesCount ;
+
+#ifdef SOCKTCP_BUFFER_LENGTH
+ // This class can use a buffer to reduce the number of systems calls
+ // when reading a lot of small amouts of data. Each time a Receive
+ // is made, it will try to read SOCKTCP_BUFFER_LENGTH
+
+ char ReadBuffer[SOCKTCP_BUFFER_LENGTH] ;
+ unsigned long RBLength ;
+#endif
+
+ // ---------------------
+ // -- Private Methods --
+ // ---------------------
+
+ unsigned int getPort(void) const ;
+ unsigned long getAddr(void) const ;
+ void setPort(unsigned int port);
+
+ int bind(unsigned int port=0, unsigned long addr=INADDR_ANY);
+ void changeReuseOption();
+ int connect(unsigned int port, unsigned long addr);
+ int listen(unsigned long howMuch=5);
+ int open(void);
+ int timeoutTCP(int, int);
+*/
+};
+}
+
+#endif // _CERTI_SOCKET_SHM_HH
+
+// $Id: SocketSHM.hh,v 1.1.2.1 2009/07/08 14:45:39 erk Exp $
Index: libCERTI/CCom.cc
===================================================================
RCS file: libCERTI/CCom.cc
diff -N libCERTI/CCom.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ libCERTI/CCom.cc 8 Jul 2009 14:45:39 -0000 1.1.2.1
@@ -0,0 +1,50 @@
+// **** DEBUT ENTETE *********************************************************
+//
+// Copyright 2003 ONERA
+//
+//
+//_NOM : hla/test/test_msg/CCom.cc
+//
+//_VERSION : 1.0
+//
+//_HISTORIQUE :
+//
+//
+//_DESCRIPTION : Classe abstraite pour la comunication entre de process
+//
+//
+//_CONTEXTE : Test de performance des differentes implementations des
+// CMessageReseau et des CSocket*.
+//
+//_CATEGORIE :
+//
+//_SYNOPSIS :
+//
+//_ENTREE :
+//
+//_SORTIE :
+//
+//_MODIFIEE :
+//
+//_LOCALE :
+//
+//_DIAGNOSTIC :
+//
+//_BUGS CONNUS : ?
+//
+//_VOIR AUSSI : le fichier README.
+//
+// **** FIN ENTETE ***********************************************************
+
+#include "CCom.hh"
+
+
+CCom::CCom (ProcessFunction *NullProcess ,
+ ProcessFunction *UAVProcess ) {
+
+}
+
+
+CCom::~CCom () {
+
+}
Index: include/.cvsignore
===================================================================
RCS file: include/.cvsignore
diff -N include/.cvsignore
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ include/.cvsignore 8 Jul 2009 14:45:39 -0000 1.2.6.2
@@ -0,0 +1,2 @@
+Makefile
+Makefile.in
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [certi-cvs] certi doc/.cvsignore libpdebug/.cvsignore libCE... [CERTI-SHM],
certi-cvs <=