Add client threads to struct for client_details array
This commit is contained in:
parent
d3d5dbb700
commit
acbdd0ed18
2 changed files with 10 additions and 0 deletions
|
@ -13,6 +13,8 @@
|
||||||
* id
|
* id
|
||||||
* pipe
|
* pipe
|
||||||
* sockid
|
* sockid
|
||||||
|
* listener_thread
|
||||||
|
* sender_thread
|
||||||
* */
|
* */
|
||||||
struct client_details clients[MAX_CLIENTS];
|
struct client_details clients[MAX_CLIENTS];
|
||||||
|
|
||||||
|
@ -40,6 +42,8 @@ int main(int argc, char *argv[]) {
|
||||||
clients[i].sockid = -1;
|
clients[i].sockid = -1;
|
||||||
clients[i].pipe[0] = -1;
|
clients[i].pipe[0] = -1;
|
||||||
clients[i].pipe[1] = -1;
|
clients[i].pipe[1] = -1;
|
||||||
|
clients[i].listener_thread = -1;
|
||||||
|
clients[i].sender_thread = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize default values for the socket */
|
/* Initialize default values for the socket */
|
||||||
|
@ -118,6 +122,9 @@ int main(int argc, char *argv[]) {
|
||||||
exit(EXIT_FAILURE);
|
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
|
// 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(clientsender, &retval);
|
||||||
(void) pthread_join(clientlistener, &retval);
|
(void) pthread_join(clientlistener, &retval);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#ifndef SERVER_H
|
#ifndef SERVER_H
|
||||||
#define SERVER_H
|
#define SERVER_H
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#define LISTEN_ALL // define to listen on 0.0.0.0, else loopback
|
#define LISTEN_ALL // define to listen on 0.0.0.0, else loopback
|
||||||
#define MAX_CLIENTS 100 // how many clients the server can handle
|
#define MAX_CLIENTS 100 // how many clients the server can handle
|
||||||
|
|
||||||
|
@ -8,6 +10,7 @@
|
||||||
struct client_details {
|
struct client_details {
|
||||||
int id, sockid;
|
int id, sockid;
|
||||||
int pipe[2];
|
int pipe[2];
|
||||||
|
pthread_t listener_thread, sender_thread;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Handle command line arguments */
|
/* Handle command line arguments */
|
||||||
|
|
Loading…
Reference in a new issue