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;