#define CorbaIWithCopyReceiver CorbaWCWithCopyReceiver
#endif
+#ifdef HAVE_SOCKET
+#include <rpc/xdr.h>
+#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).
*/
else if(!CORBA::is_nil(sock_ptr))
{
CORBA::release(sender);
- SocketReceiver<double> rec(sock_ptr);
+ SocketReceiver<double,xdr_double> rec(sock_ptr);
return rec.getValue(size);
}
#endif
else if(!CORBA::is_nil(sock_ptr))
{
CORBA::release(sender);
- SocketReceiver<int> rec(sock_ptr);
+ SocketReceiver<int,xdr_int> rec(sock_ptr);
return rec.getValue(size);
}
#endif
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
+#include <rpc/xdr.h>
-template<class T>
-SocketReceiver<T>::SocketReceiver(SALOME::SocketSender_ptr mySender) : _mySender(mySender)
+template<class T,int (*myFunc)(XDR*,T*)>
+SocketReceiver<T,myFunc>::SocketReceiver(SALOME::SocketSender_ptr mySender) : _mySender(mySender)
{
_clientSockfd = -1;
_senderDestruc=true;
}
-template<class T>
-SocketReceiver<T>::~SocketReceiver()
+template<class T,int (*myFunc)(XDR*,T*)>
+SocketReceiver<T,myFunc>::~SocketReceiver()
{
if(_senderDestruc)
{
}
}
-template<class T>
-void *SocketReceiver<T>::getValue(long &size)
+template<class T,int (*myFunc)(XDR*,T*)>
+void *SocketReceiver<T,myFunc>::getValue(long &size)
{
return Receiver::getValue(size,_mySender);
}
-template<class T>
-void* SocketReceiver<T>::getDistValue(long &size)
+template<class T,int (*myFunc)(XDR*,T*)>
+void* SocketReceiver<T,myFunc>::getDistValue(long &size)
{
int n=0, m;
T *v;
+ XDR xp; /* pointeur sur le decodeur XDR */
try{
initCom();
_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 ){
}
n += m;
}
+ xdr_vector( &xp, (char*)v, size, sizeof(T), (xdrproc_t)myFunc);
+ xdr_destroy( &xp );
_mySender->endOfCom();
closeCom();
return v;
}
-template<class T>
-void SocketReceiver<T>::initCom()
+template<class T,int (*myFunc)(XDR*,T*)>
+void SocketReceiver<T,myFunc>::initCom()
{
try{
_mySender->initCom();
}
-template<class T>
-void SocketReceiver<T>::connectCom(const char *dest_address, int port)
+template<class T,int (*myFunc)(XDR*,T*)>
+void SocketReceiver<T,myFunc>::connectCom(const char *dest_address, int port)
{
struct sockaddr_in serv_addr;
struct hostent * server;
}
-template<class T>
-void SocketReceiver<T>::closeCom()
+template<class T,int (*myFunc)(XDR*,T*)>
+void SocketReceiver<T,myFunc>::closeCom()
{
_mySender->closeCom();
if( _clientSockfd >= 0 ){
+#include <rpc/xdr.h>
#include "SALOME_Comm_i.hxx"
#include "poa.h"
#include "omnithread.h"
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();
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)