Server return value
This commit is contained in:
parent
5ec6e86f6e
commit
8ae1f2f65f
|
@ -123,6 +123,7 @@ struct {
|
||||||
struct {
|
struct {
|
||||||
pthread_t id;
|
pthread_t id;
|
||||||
bool pleaseStop;
|
bool pleaseStop;
|
||||||
|
int returnValue;
|
||||||
int sockfd;
|
int sockfd;
|
||||||
} typedef Server_t;
|
} typedef Server_t;
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
time_t t;
|
time_t t;
|
||||||
Server_t *server0;
|
Server_t *server0;
|
||||||
|
int returnValue = 0;
|
||||||
|
|
||||||
// Go!
|
// Go!
|
||||||
printLog("Starting gem-graph-server...\n");
|
printLog("Starting gem-graph-server...\n");
|
||||||
|
@ -48,9 +49,10 @@ int main(int argc, char **argv)
|
||||||
ServerWait(server0);
|
ServerWait(server0);
|
||||||
|
|
||||||
// Exiting
|
// Exiting
|
||||||
|
returnValue |= server0->returnValue;
|
||||||
ServerDestroy(server0);
|
ServerDestroy(server0);
|
||||||
ModelSystemDestroy();
|
ModelSystemDestroy();
|
||||||
free(server0);
|
free(server0);
|
||||||
|
|
||||||
return 0;
|
return returnValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -130,12 +130,14 @@ static void *serverMain(void *server)
|
||||||
|
|
||||||
// Get args
|
// Get args
|
||||||
args = (Server_t*) server;
|
args = (Server_t*) server;
|
||||||
|
args->returnValue = 0;
|
||||||
printLog("Server #%lu online\n", args->id);
|
printLog("Server #%lu online\n", args->id);
|
||||||
|
|
||||||
// Create socket
|
// Create socket
|
||||||
args->sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
args->sockfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
if (args->sockfd == -1) {
|
if (args->sockfd == -1) {
|
||||||
printLog("Socket creation failed!\n");
|
printLog("Socket creation failed!\n");
|
||||||
|
args->returnValue = 1;
|
||||||
goto serverExiting;
|
goto serverExiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,12 +145,14 @@ static void *serverMain(void *server)
|
||||||
flags = fcntl(args->sockfd, F_GETFL);
|
flags = fcntl(args->sockfd, F_GETFL);
|
||||||
if (flags == -1) {
|
if (flags == -1) {
|
||||||
printLog("Socket parameters getting failed!\n");
|
printLog("Socket parameters getting failed!\n");
|
||||||
|
args->returnValue = 1;
|
||||||
goto serverExiting;
|
goto serverExiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Change socket flags to non-blocking
|
// Change socket flags to non-blocking
|
||||||
if (fcntl(args->sockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
if (fcntl(args->sockfd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||||
printLog("Socket non-blocking setting failed!\n");
|
printLog("Socket non-blocking setting failed!\n");
|
||||||
|
args->returnValue = 1;
|
||||||
goto serverExiting;
|
goto serverExiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,12 +167,14 @@ static void *serverMain(void *server)
|
||||||
// Binding newly created socket
|
// Binding newly created socket
|
||||||
if ((bind(args->sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr))) == -1) {
|
if ((bind(args->sockfd, (struct sockaddr*)&servaddr, sizeof(servaddr))) == -1) {
|
||||||
printLog("Socket bind failed!\n");
|
printLog("Socket bind failed!\n");
|
||||||
|
args->returnValue = 1;
|
||||||
goto serverExiting;
|
goto serverExiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now server is ready to listen and verification
|
// Now server is ready to listen and verification
|
||||||
if (listen(args->sockfd, MAX_CONNECTION) == -1) {
|
if (listen(args->sockfd, MAX_CONNECTION) == -1) {
|
||||||
printLog("Socket listening failed!\n");
|
printLog("Socket listening failed!\n");
|
||||||
|
args->returnValue = 1;
|
||||||
goto serverExiting;
|
goto serverExiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +183,7 @@ static void *serverMain(void *server)
|
||||||
if (getsockname(args->sockfd, (struct sockaddr *) &servaddr, &socklen)
|
if (getsockname(args->sockfd, (struct sockaddr *) &servaddr, &socklen)
|
||||||
== -1) {
|
== -1) {
|
||||||
printLog("Could not get sock name!\n");
|
printLog("Could not get sock name!\n");
|
||||||
|
args->returnValue = 1;
|
||||||
goto serverExiting;
|
goto serverExiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,6 +224,7 @@ static void *serverMain(void *server)
|
||||||
(void*)&serverSlots[serverSlotIndex]);
|
(void*)&serverSlots[serverSlotIndex]);
|
||||||
if(threadStatus != 0) {
|
if(threadStatus != 0) {
|
||||||
printLog("Error from pthread: %d\n", threadStatus);
|
printLog("Error from pthread: %d\n", threadStatus);
|
||||||
|
args->returnValue = 1;
|
||||||
goto serverExiting;
|
goto serverExiting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue