Skip to content
Snippets Groups Projects
Commit 4961ef50 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

pp

parent b25548db
No related branches found
No related tags found
No related merge requests found
...@@ -350,10 +350,9 @@ class GmshServer : public GmshSocket{ ...@@ -350,10 +350,9 @@ class GmshServer : public GmshSocket{
#endif #endif
} }
else{ else{
// TCP/IP socket // TCP/IP socket: valid names are either explicit ("hostname:12345")
// valid TCP/IP socket descriptors are either explicit: "hostname:12345" // or implicit ("hostname:", "hostname: ", "hostname:0") in which case
// or implicit: "hostname:" "hostname: " "hostname:0" // the system attributes at random an available port
// in which case the system attributes at random an available port.
const char *port = strstr(_sockname.c_str(), ":"); const char *port = strstr(_sockname.c_str(), ":");
_portno = atoi(port + 1); _portno = atoi(port + 1);
// create a socket // create a socket
...@@ -369,7 +368,7 @@ class GmshServer : public GmshSocket{ ...@@ -369,7 +368,7 @@ class GmshServer : public GmshSocket{
memset((char *) &addr_in, 0, sizeof(addr_in)); memset((char *) &addr_in, 0, sizeof(addr_in));
addr_in.sin_family = AF_INET; addr_in.sin_family = AF_INET;
addr_in.sin_addr.s_addr = INADDR_ANY; addr_in.sin_addr.s_addr = INADDR_ANY;
addr_in.sin_port = htons(_portno); // random assign if _portno=0 addr_in.sin_port = htons(_portno); // random assign if _portno == 0
if(bind(tmpsock, (struct sockaddr *)&addr_in, sizeof(addr_in)) < 0){ if(bind(tmpsock, (struct sockaddr *)&addr_in, sizeof(addr_in)) < 0){
CloseSocket(tmpsock); CloseSocket(tmpsock);
throw "Couldn't bind socket to name"; throw "Couldn't bind socket to name";
...@@ -378,22 +377,21 @@ class GmshServer : public GmshSocket{ ...@@ -378,22 +377,21 @@ class GmshServer : public GmshSocket{
socklen_t addrlen = sizeof(addr_in); socklen_t addrlen = sizeof(addr_in);
int rc = getsockname(tmpsock, (struct sockaddr *)&addr_in, &addrlen); int rc = getsockname(tmpsock, (struct sockaddr *)&addr_in, &addrlen);
_portno = ntohs(addr_in.sin_port); _portno = ntohs(addr_in.sin_port);
char tmp[256];
int pos = _sockname.find(':'); // remove trailing ' ' or '0' int pos = _sockname.find(':'); // remove trailing ' ' or '0'
char tmp[256];
sprintf(tmp, "%s:%d", _sockname.substr(0, pos).c_str(), _portno); sprintf(tmp, "%s:%d", _sockname.substr(0, pos).c_str(), _portno);
_sockname.assign(tmp); _sockname.assign(tmp);
} }
} }
if(command && strlen(command)){ if(command && strlen(command)){
// FIXME: this is ugly - we assume that the command line always // we assume that the command line always ends with the socket name
// ends with the socket name
std::string cmd(command); std::string cmd(command);
cmd += " " + _sockname; cmd += " " + _sockname;
#if !defined(WIN32) #if !defined(WIN32)
cmd += " &"; cmd += " &";
#endif #endif
SystemCall(cmd.c_str()); // starts the solver SystemCall(cmd.c_str()); // start the solver
} }
else{ else{
timeout = 0.; // no command launched: don't set a timeout timeout = 0.; // no command launched: don't set a timeout
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment