Add client threads to struct for client_details array

This commit is contained in:
flyingscorpio@clevo 2022-10-24 23:14:05 +02:00
parent d3d5dbb700
commit acbdd0ed18
2 changed files with 10 additions and 0 deletions

View file

@ -13,6 +13,8 @@
* id
* pipe
* sockid
* listener_thread
* sender_thread
* */
struct client_details clients[MAX_CLIENTS];
@ -40,6 +42,8 @@ int main(int argc, char *argv[]) {
clients[i].sockid = -1;
clients[i].pipe[0] = -1;
clients[i].pipe[1] = -1;
clients[i].listener_thread = -1;
clients[i].sender_thread = -1;
}
/* Initialize default values for the socket */
@ -118,6 +122,9 @@ int main(int argc, char *argv[]) {
exit(EXIT_FAILURE);
}
clients[client_id].listener_thread = clientlistener;
clients[client_id].sender_thread = clientsender;
// TODO: joining here prevents creating other clients, need to move the joins to some client_disconnect function
(void) pthread_join(clientsender, &retval);
(void) pthread_join(clientlistener, &retval);

View file

@ -1,6 +1,8 @@
#ifndef SERVER_H
#define SERVER_H
#include <pthread.h>
#define LISTEN_ALL // define to listen on 0.0.0.0, else loopback
#define MAX_CLIENTS 100 // how many clients the server can handle
@ -8,6 +10,7 @@
struct client_details {
int id, sockid;
int pipe[2];
pthread_t listener_thread, sender_thread;
};
/* Handle command line arguments */