diff --git a/slsReceiverSoftware/include/genericSocket.h b/slsReceiverSoftware/include/genericSocket.h index 20b5492f4..de49d7860 100644 --- a/slsReceiverSoftware/include/genericSocket.h +++ b/slsReceiverSoftware/include/genericSocket.h @@ -60,7 +60,6 @@ class sockaddr_in; #include #endif - #include /******exit */ #include @@ -71,6 +70,8 @@ class sockaddr_in; #include #include + + using namespace std; #define DEFAULT_PACKET_SIZE 1286 @@ -272,7 +273,11 @@ typedef struct if (socketDescriptor >= 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; \ }; @@ -376,6 +381,7 @@ typedef struct #ifdef VERY_VERBOSE cout << "client connected "<< file_des << endl; #endif + } } @@ -392,7 +398,6 @@ typedef struct cerr << "Can not create socket "<=0){ + close(socketDescriptor); + socketDescriptor = -1; + } + } + } + /** @short free connection */ void Disconnect(){ if (protocol==UDP){ @@ -435,9 +450,8 @@ typedef struct void ShutDownSocket(){ - while(!shutdown(socketDescriptor, SHUT_RDWR)); - close(socketDescriptor); - socketDescriptor = -1; + while(!shutdown(socketDescriptor, SHUT_RDWR)); + Disconnect(); }; @@ -513,6 +527,9 @@ typedef struct } mac[sizeof(mac)-1]='\0'; + if(sock!=1){ + close(sock); + } return string(mac); }; @@ -534,6 +551,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/UDPBaseImplementation.cpp b/slsReceiverSoftware/src/UDPBaseImplementation.cpp index e1a630103..40152f581 100644 --- a/slsReceiverSoftware/src/UDPBaseImplementation.cpp +++ b/slsReceiverSoftware/src/UDPBaseImplementation.cpp @@ -745,15 +745,17 @@ 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 @@ -1063,24 +1064,26 @@ 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{ + }else{ #ifdef VERBOSE cprintf(BG_RED,"Could not create UDP socket on port %d error: %d\n", port[i], iret); #endif @@ -1089,6 +1092,8 @@ int UDPStandardImplementation::createUDPSockets(){ } } + + return OK; } @@ -1286,7 +1291,7 @@ int UDPStandardImplementation::setupWriter(){ numMissingPackets = 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,""); @@ -1414,9 +1419,13 @@ int UDPStandardImplementation::createNewFile(){ if(enableFileWrite && cbAction > DO_NOTHING){ //close if(sfilefd){ - fclose(sfilefd); + if(fclose(sfilefd)){ + cprintf(RED, "file close problem %d\n",fileno(sfilefd)); + fclose(sfilefd); + } sfilefd = NULL; } + //open file if(!overwrite){ if (NULL == (sfilefd = fopen((const char *) (savefilename), "wx"))){ @@ -1430,6 +1439,7 @@ int UDPStandardImplementation::createNewFile(){ //setting buffer setvbuf(sfilefd,NULL,_IOFBF,BUF_SIZE); + //printing packet losses and file names if(!packetsCaught) cout << savefilename << endl; @@ -1473,9 +1483,10 @@ void UDPStandardImplementation::closeFile(int ithr){ if(!dataCompression){ if(sfilefd){ #ifdef VERBOSE - cout << "sfield:" << (int)sfilefd << endl; + cprintf(YELLOW, "gonna close file:%d\n",fileno(sfilefd)); #endif - fclose(sfilefd); + if(fclose(sfilefd)) + perror("file close ERROR"); sfilefd = NULL; } } @@ -1486,7 +1497,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 @@ -1625,7 +1637,6 @@ int UDPStandardImplementation::stopReceiver(){ }else cout <<" Not idle to stop receiver" << endl; - //sem_post(&smp); return OK; @@ -2483,18 +2494,8 @@ void UDPStandardImplementation::startFrameIndices(int ithread, int numbytes){ FILE_LOG(logDEBUG) << __AT__ << " called"; //add currframenum later in this method for scans - if (myDetectorType == EIGER){ - //check if its a header + if (myDetectorType == EIGER) startFrameIndex = 0; - /* - if(EIGER_HEADER_LENGTH == numbytes) - startFrameIndex = (htonl(*(unsigned int*)((eiger_image_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->fnum))-1; - //missed header packet, so default value - else - startFrameIndex = ((*(uint32_t*)(((eiger_packet_header *)((char*)(buffer[ithread] + HEADER_SIZE_NUM_TOT_PACKETS)))->num1))-1); - cout<<"startFrameIndex["<lastClientIP,"none"); strcpy(socket->thisClientIP,"none1"); strcpy(mess,"dummy message"); - function_table(); #ifdef VERBOSE cout << "Function table assigned." << endl; @@ -148,8 +147,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); }