From af3abff8dd33f123fdea575832878e12b173f1cb Mon Sep 17 00:00:00 2001 From: l_maliakal_d Date: Mon, 19 Nov 2012 12:44:17 +0000 Subject: [PATCH] converted receiver to c++, edited generic socket to include differentclients git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@348 951219d9-93cf-4727-9268-0efd64621fa3 --- .../MySocketTCP/genericSocket.h | 26 +++++++++++++++++-- .../commonFiles/sls_detector_funcs.h | 2 -- .../slsDetector/slsDetector.cpp | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/slsDetectorSoftware/MySocketTCP/genericSocket.h b/slsDetectorSoftware/MySocketTCP/genericSocket.h index bfcc75166..eb142a991 100644 --- a/slsDetectorSoftware/MySocketTCP/genericSocket.h +++ b/slsDetectorSoftware/MySocketTCP/genericSocket.h @@ -149,6 +149,11 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA /* myaddr.sin_addr.s_addr = INADDR_ANY; */ + if(serverAddress.sin_port == htons(port_number)){ + socketDescriptor = -10; + return; + } + char ip[20]; strcpy(ip,"0.0.0.0"); @@ -251,7 +256,7 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA /** @short returns error status \returns 1 if error */ - int getErrorStatus(){if (socketDescriptor<0) return 1; else return 0;}; + int getErrorStatus(){if (socketDescriptor==-10) return -10; else if (socketDescriptor<0) return 1; else return 0;}; /** @short etablishes connection; disconnect should always follow @@ -314,10 +319,12 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA } socketDescriptor=-1; } + else{ + inet_ntop(AF_INET, &(clientAddress.sin_addr), dummyClientIP, INET_ADDRSTRLEN); #ifdef VERY_VERBOSE - else cout << "client connected "<< file_des << endl; #endif + } } // file_des = socketDescriptor; @@ -519,6 +526,14 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA #ifdef VERY_VERBOSE cout << "sent "<< total_sent << " Bytes" << endl; #endif + if (total_sent>0) + strcpy(thisClientIP,dummyClientIP); + + if (strcmp(lastClientIP,thisClientIP)) + differentClients=1; + else + differentClients=0; + return total_sent; @@ -568,6 +583,9 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA } + char lastClientIP[INET_ADDRSTRLEN]; + char thisClientIP[INET_ADDRSTRLEN]; + int differentClients; protected: @@ -587,6 +605,10 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(DEFA struct sockaddr_in clientAddress, serverAddress; socklen_t clientAddress_length; + + char dummyClientIP[INET_ADDRSTRLEN]; + + private: int nsending; diff --git a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h index cbd7018e6..7358b22d9 100644 --- a/slsDetectorSoftware/commonFiles/sls_detector_funcs.h +++ b/slsDetectorSoftware/commonFiles/sls_detector_funcs.h @@ -122,8 +122,6 @@ enum { F_GET_FRAMES_CAUGHT, /**< gets the number of frames caught by receiver */ - F_LOCK_RECEIVER, /**< locks receiver */ - F_GET_FRAME_INDEX, /**< gets the frame index */ F_RESET_FRAMES_CAUGHT /**< resets the frames caught */ diff --git a/slsDetectorSoftware/slsDetector/slsDetector.cpp b/slsDetectorSoftware/slsDetector/slsDetector.cpp index a20d5a71d..243e330f9 100644 --- a/slsDetectorSoftware/slsDetector/slsDetector.cpp +++ b/slsDetectorSoftware/slsDetector/slsDetector.cpp @@ -5743,7 +5743,7 @@ int* slsDetector::readFrameFromReceiver(char* fName, int &fIndex){ int slsDetector::lockReceiver(int lock){ - int fnum=F_LOCK_RECEIVER; + int fnum=F_LOCK_SERVER; int ret = FAIL; int retval=-1; int arg=lock;