This commit is contained in:
2020-04-06 17:28:05 +02:00
parent 47b0e46f15
commit 80e55cd4da
7 changed files with 230 additions and 84 deletions

View File

@ -7,11 +7,13 @@
#include "slsDetectorServer_funcs.h"
#include "slsDetectorServer_defs.h"
#include "versionAPI.h"
#ifdef VIRTUAL
#include "communication_virtual.h"
#endif
#include <signal.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
// Global variables from communication_funcs
extern int isControlServer;
@ -24,9 +26,6 @@ extern int checkModuleFlag;
// Global variables from slsDetectorFunctionList
#ifdef VIRTUAL
//extern int pipeFDs[2];
#endif
#ifdef GOTTHARDD
extern int phaseShift;
#endif
@ -55,8 +54,9 @@ int main(int argc, char *argv[]) {
}
int portno = DEFAULT_PORTNO;
int retval = OK;
int fd = 0;
isControlServer = 1;
debugflag = 0;
checkModuleFlag = 1;
// if socket crash, ignores SISPIPE, prevents global signal handler
// subsequent read/write to socket gives error - must handle locally
@ -66,7 +66,11 @@ int main(int argc, char *argv[]) {
{
int i;
for (i = 1; i < argc; ++i) {
if(!strcasecmp(argv[i],"-devel")){
if(!strcasecmp(argv[i],"-stopserver")) {
LOG(logINFO, ("Detected stop server\n"));
isControlServer = 0;
}
else if(!strcasecmp(argv[i],"-devel")){
LOG(logINFO, ("Detected developer mode\n"));
debugflag = 1;
}
@ -83,7 +87,7 @@ int main(int argc, char *argv[]) {
LOG(logERROR, ("cannot decode port value %s. Exiting.\n", argv[i + 1]));
return -1;
}
LOG(logINFO, ("Detected control port: %d\n", portno));
LOG(logINFO, ("Detected port: %d\n", portno));
}
#ifdef GOTTHARDD
else if(!strcasecmp(argv[i],"-phaseshift")){
@ -101,62 +105,51 @@ int main(int argc, char *argv[]) {
}
}
// stop server
// control server
if (isControlServer) {
#ifdef STOP_SERVER
// create pipes to communicate with stop server
// start stop server process
char cmd[MAX_STR_LENGTH];
memset(cmd, 0, MAX_STR_LENGTH);
{
int i;
for (i = 0; i < argc; ++i) {
if (i > 0) {
strcat(cmd, " ");
}
strcat(cmd, argv[i]);
}
char temp[50];
memset(temp, 0, sizeof(temp));
sprintf(temp, " -stopserver -port %d &", portno + 1);
strcat(cmd, temp);
LOG(logDEBUG1, ("Command to start stop server:%s\n", cmd));
system(cmd);
}
LOG(logINFOBLUE, ("Control Server [%d]\n", portno));
#ifdef VIRTUAL
/*if (pipe(pipeFDs) < 0) {
LOG(logERROR, ("Could not create pipes to communicate with stop server\n"));
return -1;
}*/
// creating files for virtual servers to communicate with each other
if (!ComVirtual_createFiles(portno)) {
return -1;
}
#endif
// fork stop server
pid_t cpid = fork();
if (cpid < 0) {
LOG(logERROR, ("Could not create fork a stop server\n"));
return -1;
}
//fcntl(pipeFDs[PIPE_READ], F_SETFL, O_NONBLOCK);
//fcntl(pipeFDs[PIPE_WRITE], F_SETFL, O_NONBLOCK);
// stop server (child process)
if (cpid == 0) {
isControlServer = 0;
++portno;
LOG(logINFOBLUE, ("Stop server [%d]\n", portno));
// change name of stop server to distinguish
char stopServerSuffix[30];
memset(stopServerSuffix, 0, sizeof(stopServerSuffix));
sprintf(stopServerSuffix, " Stop_Server %d", portno);
//strcat(argv[0], stopServerSuffix);
#ifdef VIRTUAL
//close(pipeFDs[PIPE_WRITE]);
//fcntl(pipeFDs[PIPE_READ], F_SETFL, O_NONBLOCK);
#endif
} else {
isControlServer = 1;
LOG(logINFOBLUE, ("Control server [%d]\n", portno));
}
// stop server
else {
LOG(logINFOBLUE, ("Stop Server [%d]\n", portno));
#ifdef VIRTUAL
//close(pipeFDs[PIPE_READ]);
ComVirtual_setFileNames(portno);
#endif
}
#endif
init_detector();
{ // bind socket
sockfd = bindSocket(portno);
if (ret == FAIL)
return -1;
}
// bind socket
sockfd = bindSocket(portno);
if (ret == FAIL)
return -1;
// assign function table
function_table();
@ -167,8 +160,9 @@ int main(int argc, char *argv[]) {
}
// waits for connection
int retval = OK;
while(retval != GOODBYE && retval != REBOOT) {
fd = acceptConnection(sockfd);
int fd = acceptConnection(sockfd);
if (fd > 0) {
retval = decode_function(fd);
closeConnection(fd);