made ports reusable and added cannot connect to these ports in error class

git-svn-id: file:///afs/psi.ch/project/sls_det_software/svn/slsDetectorSoftware@453 951219d9-93cf-4727-9268-0efd64621fa3
This commit is contained in:
l_maliakal_d 2013-02-06 17:36:03 +00:00
parent 1d03be832f
commit 9fe499e20c
4 changed files with 77 additions and 4 deletions

View File

@ -189,6 +189,15 @@ protocol(p), is_a_server(0), socketDescriptor(-1),file_des(-1), packet_size(ps),
}
// reuse port
int yes=1;
if (setsockopt(socketDescriptor,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) {
cerr << "setsockopt" << endl;
socketDescriptor=-1;
return;
}
if(bind(socketDescriptor,(struct sockaddr *) &serverAddress,sizeof(serverAddress))<0){
cerr << "Can not bind socket "<< endl;
socketDescriptor=-1;

View File

@ -23,6 +23,11 @@ using namespace std;
#define CANNOT_CONNECT_TO_DETECTOR 0x8000000000000000ULL
#define CANNOT_CONNECT_TO_RECEIVER 0x4000000000000000ULL
#define COULDNOT_SET_CONTROL_PORT 0x2000000000000000ULL
#define COULDNOT_SET_STOP_PORT 0x1000000000000000ULL
#define COULDNOT_SET_DATA_PORT 0x0800000000000000ULL
#define COULD_NOT_CONFIGURE_MAC 0x0000000000000001ULL
@ -50,9 +55,21 @@ public:
if(slsErrorMask&CANNOT_CONNECT_TO_RECEIVER)
retval.append("Cannot connect to Receiver\n");
if(slsErrorMask&COULDNOT_SET_CONTROL_PORT)
retval.append("Could not set control port\n");
if(slsErrorMask&COULDNOT_SET_STOP_PORT)
retval.append("Could not set stop port\n");
if(slsErrorMask&COULDNOT_SET_DATA_PORT)
retval.append("Could not set receiver port\n");
if(slsErrorMask&COULD_NOT_CONFIGURE_MAC)
retval.append("Could not configure mac\n");
return retval;
}

View File

@ -2563,6 +2563,8 @@ int multiSlsDetector::setPort(portType t, int p) {
for (int idet=0; idet<thisMultiDetector->numberOfDetectors; idet++) {
if (detectors[idet]) {
ret1=detectors[idet]->setPort(t,p);
if(detectors[idet]->getErrorMask())
setErrorMask(getErrorMask()|(1<<idet));
if (ret==-100)
ret=ret1;
else if (ret!=ret1)

View File

@ -3488,7 +3488,6 @@ int slsDetector::setPort(portType index, int num){
MySocketTCP *s;
if (num>1024) {
switch(index) {
case CONTROL_PORT:
s=controlSocket;
@ -3516,17 +3515,40 @@ int slsDetector::setPort(portType index, int num){
setTCPSocket("",retval);
}
online = (thisDetector->onlineFlag==ONLINE_FLAG);
//not an error.could be from config file
if(num==thisDetector->controlPort)
return thisDetector->controlPort;
//reusable port, so print error
else if((num==thisDetector->stopPort)||(num==thisDetector->receiverTCPPort)){
std::cout<< "Can not connect to port in use " << std::endl;
setErrorMask((getErrorMask())|(COULDNOT_SET_CONTROL_PORT));
return thisDetector->controlPort;
}
break;
case DATA_PORT:
s=dataSocket;
retval=thisDetector->receiverTCPPort;
if(strcmp(thisDetector->receiver_hostname,"none")){
if (s==NULL) setReceiverTCPSocket("",retval);
if (dataSocket)s=dataSocket;
//else {cout<<"datasocket has no value"<<endl; setReceiverTCPSocket("",retval);}
}
online = (thisDetector->receiverOnlineFlag==ONLINE_FLAG);
//not an error. could be from config file
if(num==thisDetector->receiverTCPPort)
return thisDetector->receiverTCPPort;
//reusable port, so print error
else if((num==thisDetector->stopPort)||(num==thisDetector->controlPort)){
std::cout<< "Can not connect to port in use " << std::endl;
setErrorMask((getErrorMask())|(COULDNOT_SET_DATA_PORT));
return thisDetector->receiverTCPPort;
}
break;
case STOP_PORT:
s=stopSocket;
retval=thisDetector->stopPort;
@ -3534,12 +3556,26 @@ int slsDetector::setPort(portType index, int num){
if (stopSocket) s=stopSocket;
else setTCPSocket("",-1,retval);
online = (thisDetector->onlineFlag==ONLINE_FLAG);
//not an error. could be from config file
if(num==thisDetector->stopPort)
return thisDetector->stopPort;
//reusable port, so print error
else if((num==thisDetector->receiverTCPPort)||(num==thisDetector->controlPort)){
std::cout<< "Can not connect to port in use " << std::endl;
setErrorMask((getErrorMask())|(COULDNOT_SET_STOP_PORT));
return thisDetector->stopPort;
}
break;
default:
s=NULL;
break;
}
//send to current port to change port
if (online) {
if (s) {
@ -3559,6 +3595,8 @@ int slsDetector::setPort(portType index, int num){
}
}
if (ret!=FAIL) {
switch(index) {
case CONTROL_PORT:
@ -3585,11 +3623,13 @@ int slsDetector::setPort(portType index, int num){
switch(index) {
case CONTROL_PORT:
thisDetector->controlPort=num;
setErrorMask((getErrorMask())|(COULDNOT_SET_CONTROL_PORT));
break;
case DATA_PORT:
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG)
if(thisDetector->receiverOnlineFlag==ONLINE_FLAG){
thisDetector->receiverTCPPort=retval;
else{
setErrorMask((getErrorMask())|(COULDNOT_SET_DATA_PORT));
}else{
thisDetector->receiverTCPPort=num;
if(strcmp(thisDetector->receiver_hostname,"none"))
setReceiver(thisDetector->receiver_hostname);
@ -3597,12 +3637,17 @@ int slsDetector::setPort(portType index, int num){
break;
case STOP_PORT:
thisDetector->stopPort=num;
setErrorMask((getErrorMask())|(COULDNOT_SET_STOP_PORT));
break;
default:
break;
}
}
}
switch(index) {
case CONTROL_PORT:
retval=thisDetector->controlPort;