From bf7da5f4939d5fd265e37f408b11c3a7ab22c79f Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Tue, 13 Nov 2012 08:38:18 +0000 Subject: [PATCH] closeDataFile is only for gotthard and included lock for socket while using receiver git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@338 951219d9-93cf-4727-9268-0efd64621fa3 --- .../MySocketTCP/genericSocket.h | 197 +++++++++--------- .../slsDetector/slsDetector.cpp | 2 +- .../slsDetector/slsDetectorUtils.cpp | 49 +++-- .../slsDetectorAnalysis/fileIO.cpp | 4 +- .../slsDetectorAnalysis/postProcessing.cpp | 19 +- .../slsReceiver/slsReceiverFunctionList.c | 2 +- .../slsReceiver/slsReceiver_funcs.c | 3 +- 7 files changed, 153 insertions(+), 123 deletions(-) diff --git a/slsDetectorSoftware/MySocketTCP/genericSocket.h b/slsDetectorSoftware/MySocketTCP/genericSocket.h index b380cd181..829d3a606 100644 --- a/slsDetectorSoftware/MySocketTCP/genericSocket.h +++ b/slsDetectorSoftware/MySocketTCP/genericSocket.h @@ -89,6 +89,10 @@ enum communicationProtocol{ genericSocket(const char* const host_ip_or_name, unsigned short int const port_number, communicationProtocol p) : portno(port_number), protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFAULT_PACKET_SIZE)// sender (client): where to? ip { + pthread_mutex_t mp1 = PTHREAD_MUTEX_INITIALIZER; + mp=mp1; + pthread_mutex_init(&mp, NULL); + strcpy(hostname,host_ip_or_name); struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ @@ -237,92 +241,96 @@ enum communicationProtocol{ /** @short etablishes connection; disconnect should always follow \returns 1 if error */ - int Connect(){ + int Connect(){//cout<<"connect"<0) return file_des; + if(file_des>0) return file_des; - if(is_a_server && protocol==TCP){ //server tcp; the server will wait for the clients connection - if (socketDescriptor>0) { - if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) { - cerr << "Error: with server accept, connection refused"<0) { + if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) { + cerr << "Error: with server accept, connection refused"<=0){ //then was open - if(is_a_server){ - close(file_des); - } - else { - close(socketDescriptor); - socketDescriptor=-1; - } - file_des=-1; - } + + if(file_des>=0){ //then was open + if(is_a_server){ + close(file_des); + } + else { + close(socketDescriptor); + socketDescriptor=-1; + } + file_des=-1; + /*cout<<"unlocking"<dataBytes+HEADERLENGTH) { - std::cout<dataBytes+HEADERLENGTH << std::endl; + std::cout<dataBytes+HEADERLENGTH << std::endl; ret=FAIL; delete [] origVal; delete [] retval; diff --git a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp index 2b31ce330..50243daca 100644 --- a/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetectorUtils.cpp @@ -240,21 +240,26 @@ void slsDetectorUtils::acquire(int delflag){ } if(receiver){ - //send receiver file name - pthread_mutex_lock(&mp); - createFileName(); - pthread_mutex_unlock(&mp); - setFileName(fileIO::getFileName()); - if(setReceiverOnline()==OFFLINE_FLAG){ - stopReceiver(); - break; - } - //start receiver - startReceiver(); - if(setReceiverOnline()==OFFLINE_FLAG){ - stopReceiver(); - break; - } + //send receiver file name + pthread_mutex_lock(&mp); + createFileName(); + pthread_mutex_unlock(&mp); + + pthread_mutex_lock(&mg); + setFileName(fileIO::getFileName()); + if(setReceiverOnline()==OFFLINE_FLAG){ + stopReceiver(); + pthread_mutex_unlock(&mg); + break; + } + //start receiver + startReceiver(); + if(setReceiverOnline()==OFFLINE_FLAG){ + stopReceiver(); + pthread_mutex_unlock(&mg); + break; + } + pthread_mutex_unlock(&mg); } startAndReadAll(); @@ -290,6 +295,8 @@ void slsDetectorUtils::acquire(int delflag){ } else break; + + pthread_mutex_lock(&mg); if(setReceiverOnline()==OFFLINE_FLAG){ // wait until data processing thread has finished the data @@ -303,12 +310,16 @@ void slsDetectorUtils::acquire(int delflag){ usleep(100000); } - if((*correctionMask)&(1<