moved deallocation into communicate_thread
This commit is contained in:
parent
7e77f6ffda
commit
2fb4c739b2
@ -27,7 +27,6 @@ int main(void)
|
|||||||
{
|
{
|
||||||
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
|
int listen_socket = socket(AF_INET, SOCK_STREAM, 0); //CREATE SERVER SOCKET
|
||||||
int accepted;
|
int accepted;
|
||||||
char *received = NULL;
|
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
|
||||||
if (listen_socket < 0) why2_die("Failed creating socket.");
|
if (listen_socket < 0) why2_die("Failed creating socket.");
|
||||||
@ -54,9 +53,6 @@ int main(void)
|
|||||||
pthread_create(&thread, NULL, communicate_thread, &accepted);
|
pthread_create(&thread, NULL, communicate_thread, &accepted);
|
||||||
}
|
}
|
||||||
|
|
||||||
//DEALLOCATION
|
|
||||||
why2_deallocate(received);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,10 +61,11 @@ void *communicate_thread(void *arg)
|
|||||||
printf("User connected.\t%d\n", *((int*) arg));
|
printf("User connected.\t%d\n", *((int*) arg));
|
||||||
|
|
||||||
const time_t startTime = time(NULL);
|
const time_t startTime = time(NULL);
|
||||||
|
char *received = NULL;
|
||||||
|
|
||||||
while (time(NULL) - startTime < 86400) //KEEP COMMUNICATION ALIVE FOR 24 HOURS
|
while (time(NULL) - startTime < 86400) //KEEP COMMUNICATION ALIVE FOR 24 HOURS
|
||||||
{
|
{
|
||||||
char *received = read_socket(*((int*) arg)); //READ
|
received = read_socket(*((int*) arg)); //READ
|
||||||
|
|
||||||
if (received == NULL) return NULL; //FAILED; EXIT THREAD
|
if (received == NULL) return NULL; //FAILED; EXIT THREAD
|
||||||
|
|
||||||
@ -81,7 +78,10 @@ void *communicate_thread(void *arg)
|
|||||||
|
|
||||||
printf("User exited.\t%d\n", *((int*) arg));
|
printf("User exited.\t%d\n", *((int*) arg));
|
||||||
|
|
||||||
|
//DEALLOCATION
|
||||||
close(*((int*) arg));
|
close(*((int*) arg));
|
||||||
|
why2_deallocate(received);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user