From 52f83b9249bc9a32300053de62ba7adb46533725 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Mon, 10 Aug 2015 13:44:57 +0200 Subject: [PATCH 1/5] do not push, debug commands involved --- slsReceiverSoftware/include/genericSocket.h | 50 ++++++++++++++++--- .../src/UDPBaseImplementation.cpp | 8 ++- .../src/UDPStandardImplementation.cpp | 41 ++++++++++----- .../src/slsReceiverTCPIPInterface.cpp | 1 - 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 216a9fa11..3bb4adcff 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -60,7 +60,7 @@ class sockaddr_in; #include #endif - +#include "ansi.h" #include /******exit */ #include @@ -71,6 +71,8 @@ class sockaddr_in; #include #include +#include //SIGINT + using namespace std; #define DEFAULT_PACKET_SIZE 1286 @@ -125,6 +127,7 @@ typedef struct struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n"; + cprintf(RED,"Exiting: Problem interpreting host:%s\n",host_ip_or_name); } else { // Set some fields in the serverAddress structure. serverAddress.sin_family = hostInfo->h_addrtype; @@ -134,6 +137,7 @@ typedef struct socketDescriptor=0; //You can use send and recv, //would it work????? } clientAddress_length=sizeof(clientAddress); + cprintf(MAGENTA, "client socket created %d \n",socketDescriptor,protocol); } @@ -176,6 +180,7 @@ typedef struct nsent(0), total_sent(0) { + signal(SIGCHLD,SIG_IGN); //memset(&serverAddress, 0, sizeof(sockaddr_in)); // memset(&clientAddress, 0, sizeof(sockaddr_in)); // serverAddress = {0}; @@ -205,9 +210,12 @@ typedef struct socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp + cprintf(MAGENTA, "socket created %d protocol:%d\n",socketDescriptor,protocol); + if (socketDescriptor < 0) { cerr << "Can not create socket "<0) { if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) { cerr << "Error: with server accept, connection refused"<=0){ + close(file_des); + file_des=-1; + } + } +*/ + + if(file_des>=0){ //then was open if(is_a_server){ - close(file_des); + // cprintf(MAGENTA, "file_des disconnected %d \n",file_des); + if(close(file_des)) + cprintf(RED,"file_des not disconnected %d\n", file_des); + // cprintf(MAGENTA, "file_des disconnected %d \n",file_des); } else { - close(socketDescriptor); + //cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor); + if(close(socketDescriptor)) + cprintf(RED,"socketDescriptor not disconnected %d\n", file_des); + // cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor); socketDescriptor=-1; } file_des=-1; } + + + } }; void ShutDownSocket(){ - while(!shutdown(socketDescriptor, SHUT_RDWR)); - close(socketDescriptor); - socketDescriptor = -1; + while(!shutdown(socketDescriptor, SHUT_RDWR)); + Disconnect(); }; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index bbb8b331d..80ce6b2c7 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -745,15 +745,19 @@ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " if(!strlen(eth)){ cout<<"warning:eth is empty.listening to all"< /proc/sys/net/core/netdev_max_backlog")) cout << "\nWARNING: Could not change max length of input queue in file /proc/sys/net/core/netdev_max_backlog" << endl; + /** permanent setting heiner net.core.rmem_max = 104857600 # 100MiB net.core.netdev_max_backlog = 250000 @@ -1056,24 +1057,29 @@ int UDPStandardImplementation::createUDPSockets(){ if(!strlen(eth)){ cout<<"warning:eth is empty.listening to all"<getErrorStatus(); - if(!iret) + if(!iret){ cout << "UDP port opened at port " << port[i] << endl; - else{ + cprintf(YELLOW, "socket of port %d descriptor:%d\n",i,udpSocket[i]->getsocketDescriptor()); + }else{ #ifdef VERBOSE cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); #endif @@ -1082,6 +1088,8 @@ int UDPStandardImplementation::createUDPSockets(){ } } + + return OK; } @@ -1276,7 +1284,7 @@ int UDPStandardImplementation::setupWriter(){ packetsInFile=0; packetsCaught=0; frameIndex=0; - if(sfilefd) sfilefd=NULL; + if(sfilefd) {cprintf(RED,"**FILE not closed!\n");fclose(sfilefd);sfilefd=NULL;} guiData = NULL; guiDataReady=0; strcpy(guiFileName,""); @@ -1402,9 +1410,13 @@ int UDPStandardImplementation::createNewFile(){ if(enableFileWrite && cbAction > DO_NOTHING){ //close if(sfilefd){ - fclose(sfilefd); + if(fclose(sfilefd)){ + cprintf(YELLOW, "file clsoe problem %d\n",fileno(sfilefd)); + fclose(sfilefd); + } sfilefd = NULL; } + //open file if(!overwrite){ if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ @@ -1418,6 +1430,9 @@ int UDPStandardImplementation::createNewFile(){ //setting buffer setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + cprintf(YELLOW, "file value:%d\n",fileno(sfilefd)); + + //cprintf(YELLOW, "file valuex:%d",(int)sfilefd); //printing packet losses and file names if(!packetsCaught) cout << savefilename << endl; @@ -1459,10 +1474,12 @@ void UDPStandardImplementation::closeFile(int ithr){ if(!dataCompression){ if(sfilefd){ -#ifdef VERBOSE - cout << "sfield:" << (int)sfilefd << endl; -#endif - fclose(sfilefd); +//#ifdef VERBOSE + cprintf(YELLOW, "gonna close file:%d\n",fileno(sfilefd)); +//#endif + if(fclose(sfilefd)) + perror("close ERRROR"); + cprintf(YELLOW, "check close file:%d\n",fileno(sfilefd)); sfilefd = NULL; } } @@ -1473,7 +1490,8 @@ void UDPStandardImplementation::closeFile(int ithr){ #ifdef VERBOSE cout << "sfield:" << (int)sfilefd << endl; #endif - fclose(sfilefd); + if(fclose(sfilefd)) + perror("close ERRROR"); sfilefd = NULL; } #endif @@ -1612,7 +1630,6 @@ int UDPStandardImplementation::stopReceiver(){ }else cout <<" Not idle to stop receiver" << endl; - //sem_post(&smp); return OK; diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index 5cb2f0fb5..dfa01e6e3 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -65,7 +65,6 @@ slsReceiverTCPIPInterface::slsReceiverTCPIPInterface(int &success, UDPInterface* strcpy(socket->lastClientIP,"none"); strcpy(socket->thisClientIP,"none1"); strcpy(mess,"dummy message"); - function_table(); #ifdef VERBOSE cout << "Function table assigned." << endl; From 5dd5c250f3c30593706dd67f3ed8c80a6440443d Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 19 Aug 2015 14:55:15 +0200 Subject: [PATCH 2/5] removing unnecessary prints --- slsReceiverSoftware/include/genericSocket.h | 30 +++---------------- .../src/UDPBaseImplementation.cpp | 2 -- .../src/UDPStandardImplementation.cpp | 19 ++++++------ 3 files changed, 13 insertions(+), 38 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 3bb4adcff..aa79f3233 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -60,7 +60,6 @@ class sockaddr_in; #include #endif -#include "ansi.h" #include /******exit */ #include @@ -71,7 +70,6 @@ class sockaddr_in; #include #include -#include //SIGINT using namespace std; @@ -127,7 +125,6 @@ typedef struct struct hostent *hostInfo = gethostbyname(host_ip_or_name); if (hostInfo == NULL){ cerr << "Exiting: Problem interpreting host: " << host_ip_or_name << "\n"; - cprintf(RED,"Exiting: Problem interpreting host:%s\n",host_ip_or_name); } else { // Set some fields in the serverAddress structure. serverAddress.sin_family = hostInfo->h_addrtype; @@ -137,7 +134,6 @@ typedef struct socketDescriptor=0; //You can use send and recv, //would it work????? } clientAddress_length=sizeof(clientAddress); - cprintf(MAGENTA, "client socket created %d \n",socketDescriptor,protocol); } @@ -180,7 +176,6 @@ typedef struct nsent(0), total_sent(0) { - signal(SIGCHLD,SIG_IGN); //memset(&serverAddress, 0, sizeof(sockaddr_in)); // memset(&clientAddress, 0, sizeof(sockaddr_in)); // serverAddress = {0}; @@ -210,12 +205,10 @@ typedef struct socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp - cprintf(MAGENTA, "socket created %d protocol:%d\n",socketDescriptor,protocol); if (socketDescriptor < 0) { cerr << "Can not create socket "<0) { if ((file_des = accept(socketDescriptor,(struct sockaddr *) &clientAddress, &clientAddress_length)) < 0) { cerr << "Error: with server accept, connection refused"<=0){ @@ -459,16 +443,10 @@ typedef struct if(file_des>=0){ //then was open if(is_a_server){ - // cprintf(MAGENTA, "file_des disconnected %d \n",file_des); - if(close(file_des)) - cprintf(RED,"file_des not disconnected %d\n", file_des); - // cprintf(MAGENTA, "file_des disconnected %d \n",file_des); + close(file_des); } else { - //cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor); - if(close(socketDescriptor)) - cprintf(RED,"socketDescriptor not disconnected %d\n", file_des); - // cprintf(MAGENTA, "socketDescriptor disconnected %d \n",socketDescriptor); + close(socketDescriptor); socketDescriptor=-1; } file_des=-1; diff --git a/slsReceiverSoftware/src/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index 80ce6b2c7..670805a46 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -746,7 +746,6 @@ int UDPBaseImplementation::createUDPSockets(){ FILE_LOG(logDEBUG) << __AT__ << " cout<<"warning:eth is empty.listening to all"<getErrorStatus(); if(!iret){ cout << "UDP port opened at port " << port[i] << endl; - cprintf(YELLOW, "socket of port %d descriptor:%d\n",i,udpSocket[i]->getsocketDescriptor()); + //cprintf(YELLOW, "socket of port %d descriptor:%d\n",i,udpSocket[i]->getsocketDescriptor()); }else{ #ifdef VERBOSE cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); @@ -1411,7 +1411,7 @@ int UDPStandardImplementation::createNewFile(){ //close if(sfilefd){ if(fclose(sfilefd)){ - cprintf(YELLOW, "file clsoe problem %d\n",fileno(sfilefd)); + cprintf(RED, "file close problem %d\n",fileno(sfilefd)); fclose(sfilefd); } sfilefd = NULL; @@ -1430,9 +1430,8 @@ int UDPStandardImplementation::createNewFile(){ //setting buffer setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); - cprintf(YELLOW, "file value:%d\n",fileno(sfilefd)); + //cprintf(YELLOW, "file value:%d\n",fileno(sfilefd)); - //cprintf(YELLOW, "file valuex:%d",(int)sfilefd); //printing packet losses and file names if(!packetsCaught) cout << savefilename << endl; @@ -1474,12 +1473,12 @@ void UDPStandardImplementation::closeFile(int ithr){ if(!dataCompression){ if(sfilefd){ -//#ifdef VERBOSE +#ifdef VERBOSE cprintf(YELLOW, "gonna close file:%d\n",fileno(sfilefd)); -//#endif +#endif if(fclose(sfilefd)) - perror("close ERRROR"); - cprintf(YELLOW, "check close file:%d\n",fileno(sfilefd)); + perror("file close ERROR"); + //cprintf(YELLOW, "check close file:%d\n",fileno(sfilefd)); sfilefd = NULL; } } From 587d357f3ee94ae5c75c0577b8f6826b2805d286 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Wed, 19 Aug 2015 15:47:24 +0200 Subject: [PATCH 3/5] resetting frame index for scans for eiger --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index bb7241665..bebb7ad5e 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2187,11 +2187,8 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " called"; if (myDetectorType == EIGER){ - //add currframenum later in this method for scans - /*if(dynamicRange == 32) - startFrameIndex = htonl(*(unsigned int*)((eiger_image_header32 *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); - else*/ - startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum); + startFrameIndex = 0; + /*startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum);*/ } //gotthard has +1 for frame number and not a short frame else if ((myDetectorType == PROPIX) || ((myDetectorType == GOTTHARD) && (shortFrame == -1))) @@ -2209,6 +2206,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ acqStarted = true; cout << "startAcquisitionIndex:" << hex << startAcquisitionIndex< Date: Thu, 20 Aug 2015 10:17:36 +0200 Subject: [PATCH 4/5] changed startframeindex to 1 as thats whats written to file in eiger --- slsReceiverSoftware/src/UDPStandardImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slsReceiverSoftware/src/UDPStandardImplementation.cpp b/slsReceiverSoftware/src/UDPStandardImplementation.cpp index bebb7ad5e..683b6a9f9 100644 --- a/slsReceiverSoftware/src/UDPStandardImplementation.cpp +++ b/slsReceiverSoftware/src/UDPStandardImplementation.cpp @@ -2187,7 +2187,7 @@ void UDPStandardImplementation::startFrameIndices(int ithread){ FILE_LOG(logDEBUG) << __AT__ << " called"; if (myDetectorType == EIGER){ - startFrameIndex = 0; + startFrameIndex = 1; /*startFrameIndex = htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum);*/ } //gotthard has +1 for frame number and not a short frame From 0a0dfb2dc6765e0a8c3931ec92b47bfd78fc2939 Mon Sep 17 00:00:00 2001 From: Dhanya Maliakal Date: Fri, 21 Aug 2015 14:11:38 +0200 Subject: [PATCH 5/5] fixed problem with increasing file descriptor when connecting to receiver --- slsReceiverSoftware/include/genericSocket.h | 40 ++++++++++--------- .../src/slsReceiverTCPIPInterface.cpp | 11 +++++ 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index aa79f3233..fe49df0d2 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -71,6 +71,7 @@ class sockaddr_in; #include + using namespace std; #define DEFAULT_PACKET_SIZE 1286 @@ -206,7 +207,6 @@ typedef struct socketDescriptor = socket(AF_INET, getProtocol(),0); //tcp - if (socketDescriptor < 0) { cerr << "Can not create socket "<= 0){ \ close(socketDescriptor); \ } \ - file_des=-1; \ + if(is_a_server and getProtocol() == TCP){\ + if(file_des>0)\ + close(file_des);\ + } + file_des=-1; \ serverAddress.sin_port=-1; \ }; @@ -401,7 +405,6 @@ typedef struct cerr << "Can not create socket "<=0){ + close(socketDescriptor); + socketDescriptor = -1; + } + } + } + /** @short free connection */ void Disconnect(){ if (protocol==UDP){ @@ -429,18 +442,6 @@ typedef struct socketDescriptor=-1; } else{ - - /* close(socketDescriptor); - socketDescriptor=-1; - if(is_a_server){ - if(file_des>=0){ - close(file_des); - file_des=-1; - } - } -*/ - - if(file_des>=0){ //then was open if(is_a_server){ close(file_des); @@ -451,9 +452,6 @@ typedef struct } file_des=-1; } - - - } }; @@ -536,6 +534,9 @@ typedef struct } mac[sizeof(mac)-1]='\0'; + if(sock!=1){ + close(sock); + } return string(mac); }; @@ -557,6 +558,9 @@ typedef struct strncpy(addr,p,sizeof(addr)-1); addr[sizeof(addr)-1]='\0'; + if(sock!=1){ + close(sock); + } return string(addr); }; diff --git a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp index dfa01e6e3..65dbd890c 100644 --- a/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp +++ b/slsReceiverSoftware/src/slsReceiverTCPIPInterface.cpp @@ -145,8 +145,18 @@ void slsReceiverTCPIPInterface::stop(){ cout<<"Shutting down TCP Socket and TCP thread"<shutDownUDPSockets(); + + cout << "Closing Files... " << endl; + receiverBase->closeFile(); + } + + killTCPServerThread = 1; socket->ShutDownSocket(); + socket->exitServer(); cout<<"Socket closed"<closeFile(); } + socket->exitServer(); pthread_exit(NULL); }