added way to stop server

This commit is contained in:
Václav Šmejkal 2023-02-22 09:56:23 +01:00
parent 5a9073f595
commit 1e7fbc03a8
Signed by: ENGO150
GPG Key ID: F6D6DF86242C5A59

View File

@ -18,12 +18,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <why2/chat/common.h> #include <why2/chat/common.h>
#include <unistd.h>
#include <why2/chat/misc.h> #include <why2/chat/misc.h>
int main(void) 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
pthread_t thread; pthread_t thread;
size_t line_length_buffer;
char *line_buffer;
if (listen_socket < 0) why2_die("Failed creating socket."); if (listen_socket < 0) why2_die("Failed creating socket.");
@ -43,9 +47,21 @@ int main(void)
pthread_create(&thread, NULL, why2_accept_thread, &listen_socket); pthread_create(&thread, NULL, why2_accept_thread, &listen_socket);
//TODO: Add getline() for (;;)
{
getline(&line_buffer, &line_length_buffer, stdin);
pthread_join(thread, NULL); if (strcmp(line_buffer, "!exit\n") == 0) //USER REQUESTED PROGRAM EXIT
{
printf("Exiting...\n");
break;
}
}
//TODO: Exit threads
free(line_buffer);
close(listen_socket);
return 0; return 0;
} }