From: ageay Date: Wed, 22 Sep 2004 13:04:37 +0000 (+0000) Subject: ajout du codage standard xdr avec les sockets. X-Git-Tag: BR_GEAY_20041105~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6d0a32f7857f40dddcb74e64e6e3adaf4dad81b3;p=modules%2Fkernel.git ajout du codage standard xdr avec les sockets. --- diff --git a/src/Communication/ReceiverFactory.cxx b/src/Communication/ReceiverFactory.cxx index 781a37417..31bcb6768 100644 --- a/src/Communication/ReceiverFactory.cxx +++ b/src/Communication/ReceiverFactory.cxx @@ -17,6 +17,10 @@ #define CorbaIWithCopyReceiver CorbaWCWithCopyReceiver #endif +#ifdef HAVE_SOCKET +#include +#endif + /*! This method performs the transfert with the remote sender given. If it fails with this sender it tries with an another protocol (CORBA by default). */ @@ -81,7 +85,7 @@ void *ReceiverFactory::getValueOneShot(SALOME::Sender_ptr sender,long &size)thro else if(!CORBA::is_nil(sock_ptr)) { CORBA::release(sender); - SocketReceiver rec(sock_ptr); + SocketReceiver rec(sock_ptr); return rec.getValue(size); } #endif @@ -117,7 +121,7 @@ void *ReceiverFactory::getValueOneShot(SALOME::Sender_ptr sender,long &size)thro else if(!CORBA::is_nil(sock_ptr)) { CORBA::release(sender); - SocketReceiver rec(sock_ptr); + SocketReceiver rec(sock_ptr); return rec.getValue(size); } #endif diff --git a/src/Communication/Receivers.cxx b/src/Communication/Receivers.cxx index 04851c461..e01125aa7 100644 --- a/src/Communication/Receivers.cxx +++ b/src/Communication/Receivers.cxx @@ -218,16 +218,17 @@ void *MPIReceiver::getValue(long &size) #include #include #include +#include -template -SocketReceiver::SocketReceiver(SALOME::SocketSender_ptr mySender) : _mySender(mySender) +template +SocketReceiver::SocketReceiver(SALOME::SocketSender_ptr mySender) : _mySender(mySender) { _clientSockfd = -1; _senderDestruc=true; } -template -SocketReceiver::~SocketReceiver() +template +SocketReceiver::~SocketReceiver() { if(_senderDestruc) { @@ -236,17 +237,18 @@ SocketReceiver::~SocketReceiver() } } -template -void *SocketReceiver::getValue(long &size) +template +void *SocketReceiver::getValue(long &size) { return Receiver::getValue(size,_mySender); } -template -void* SocketReceiver::getDistValue(long &size) +template +void* SocketReceiver::getDistValue(long &size) { int n=0, m; T *v; + XDR xp; /* pointeur sur le decodeur XDR */ try{ initCom(); @@ -260,6 +262,7 @@ void* SocketReceiver::getDistValue(long &size) _mySender->send(); + xdrmem_create(&xp,(char*)v,size*sizeof(T),XDR_DECODE ); while( n < size*sizeof(T) ){ m = read(_clientSockfd, (char*)v+n, size*sizeof(T)-n); if( m < 0 ){ @@ -272,6 +275,8 @@ void* SocketReceiver::getDistValue(long &size) } n += m; } + xdr_vector( &xp, (char*)v, size, sizeof(T), (xdrproc_t)myFunc); + xdr_destroy( &xp ); _mySender->endOfCom(); closeCom(); @@ -290,8 +295,8 @@ void* SocketReceiver::getDistValue(long &size) return v; } -template -void SocketReceiver::initCom() +template +void SocketReceiver::initCom() { try{ _mySender->initCom(); @@ -319,8 +324,8 @@ void SocketReceiver::initCom() } -template -void SocketReceiver::connectCom(const char *dest_address, int port) +template +void SocketReceiver::connectCom(const char *dest_address, int port) { struct sockaddr_in serv_addr; struct hostent * server; @@ -371,8 +376,8 @@ void SocketReceiver::connectCom(const char *dest_address, int port) } -template -void SocketReceiver::closeCom() +template +void SocketReceiver::closeCom() { _mySender->closeCom(); if( _clientSockfd >= 0 ){ diff --git a/src/Communication/Receivers.hxx b/src/Communication/Receivers.hxx index 917a32c1a..4fd2581ee 100644 --- a/src/Communication/Receivers.hxx +++ b/src/Communication/Receivers.hxx @@ -90,10 +90,13 @@ private: #endif #ifdef HAVE_SOCKET + +class XDR; + /*! Receiver for transfert with sockets. */ -template +template class SocketReceiver : public Receiver { private: diff --git a/src/Communication/SALOME_Comm_i.cxx b/src/Communication/SALOME_Comm_i.cxx index 74ca7b244..00fe36a11 100644 --- a/src/Communication/SALOME_Comm_i.cxx +++ b/src/Communication/SALOME_Comm_i.cxx @@ -1,3 +1,4 @@ +#include #include "SALOME_Comm_i.hxx" #include "poa.h" #include "omnithread.h" @@ -308,12 +309,13 @@ SALOME::SocketSender::param * SALOME_SocketSender_i::getParam() void SALOME_SocketSender_i::send() { - _argsForThr=new (void *)[5]; + _argsForThr=new void *[6]; _argsForThr[0]=&_serverSockfd; _argsForThr[1]=&_clientSockfd; _argsForThr[2]=&_lgrTabToSend; _argsForThr[3]=(void *)_tabToSend; _argsForThr[4]=&_errorFlag; + _argsForThr[5]=&_type; _newThr=new omni_thread(SALOME_SocketSender_i::myThread,_argsForThr); _newThr->start(); @@ -328,23 +330,64 @@ void* SALOME_SocketSender_i::myThread(void *args) long *lgrTabToSend=(long *)argsTab[2]; void *tabToSend=argsTab[3]; bool *errorFlag=(bool*)argsTab[4]; - - *errorFlag = false; - while( n < *lgrTabToSend*sizeof(double) ){ - m = write(*clientSockfd, (char*)tabToSend+n, *lgrTabToSend*sizeof(double)-n); - if( m < 0 ){ - if( *clientSockfd >= 0 ){ - ::close(*clientSockfd); - *clientSockfd = -1; + SALOME::TypeOfDataTransmitted *type=(SALOME::TypeOfDataTransmitted *)argsTab[5]; + + XDR xp; /* pointeur sur le decodeur XDR */ + + switch(*type) + { + case SALOME::DOUBLE_: + xdrmem_create(&xp,(char*)tabToSend,(*lgrTabToSend)*sizeof(double),XDR_ENCODE ); + xdr_vector( &xp, (char*)tabToSend, *lgrTabToSend, sizeof(double), (xdrproc_t)xdr_double ); + + *errorFlag = false; + while( n < *lgrTabToSend*sizeof(double) ){ + m = write(*clientSockfd, (char*)tabToSend+n, *lgrTabToSend*sizeof(double)-n); + if( m < 0 ){ + if( *clientSockfd >= 0 ){ + ::close(*clientSockfd); + *clientSockfd = -1; + } + if( *serverSockfd >= 0 ){ + ::close(*serverSockfd); + *serverSockfd = -1; + } + *errorFlag = true; + } + n += m; } - if( *serverSockfd >= 0 ){ - ::close(*serverSockfd); - *serverSockfd = -1; + xdr_destroy( &xp ); + + xdrmem_create(&xp,(char*)tabToSend,(*lgrTabToSend)*sizeof(double),XDR_DECODE ); + xdr_vector( &xp, (char*)tabToSend, *lgrTabToSend, sizeof(double), (xdrproc_t)xdr_double ); + xdr_destroy( &xp ); + break; + case SALOME::INT_: + xdrmem_create(&xp,(char*)tabToSend,(*lgrTabToSend)*sizeof(int),XDR_ENCODE ); + xdr_vector( &xp, (char*)tabToSend, *lgrTabToSend, sizeof(int), (xdrproc_t)xdr_int ); + + *errorFlag = false; + while( n < *lgrTabToSend*sizeof(int) ){ + m = write(*clientSockfd, (char*)tabToSend+n, *lgrTabToSend*sizeof(int)-n); + if( m < 0 ){ + if( *clientSockfd >= 0 ){ + ::close(*clientSockfd); + *clientSockfd = -1; + } + if( *serverSockfd >= 0 ){ + ::close(*serverSockfd); + *serverSockfd = -1; + } + *errorFlag = true; + } + n += m; } - *errorFlag = true; + xdr_destroy( &xp ); + + xdrmem_create(&xp,(char*)tabToSend,(*lgrTabToSend)*sizeof(int),XDR_DECODE ); + xdr_vector( &xp, (char*)tabToSend, *lgrTabToSend, sizeof(int), (xdrproc_t)xdr_int ); + xdr_destroy( &xp ); } - n += m; - } } void SALOME_SocketSender_i::initCom() throw(SALOME::SALOME_Exception)