2022-09-13 21:40:23 +02:00
|
|
|
#ifndef SERVER_H
|
|
|
|
#define SERVER_H
|
|
|
|
|
2022-10-24 23:14:05 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
|
2022-10-19 22:55:51 +02:00
|
|
|
#define LISTEN_ALL // define to listen on 0.0.0.0, else loopback
|
2022-10-21 13:39:01 +02:00
|
|
|
#define MAX_CLIENTS 100 // how many clients the server can handle
|
|
|
|
|
|
|
|
/* Details for each client, used by Dispatcher and passed to client threads */
|
|
|
|
struct client_details {
|
2022-10-21 14:20:32 +02:00
|
|
|
int id, sockid;
|
|
|
|
int pipe[2];
|
2022-10-24 23:14:05 +02:00
|
|
|
pthread_t listener_thread, sender_thread;
|
2022-10-21 13:39:01 +02:00
|
|
|
};
|
2022-10-19 22:55:51 +02:00
|
|
|
|
2022-10-24 22:29:23 +02:00
|
|
|
/* Handle command line arguments */
|
|
|
|
int handle_args(int, char**);
|
|
|
|
|
2022-10-21 14:50:10 +02:00
|
|
|
/* Compute the next free client_id in the client array */
|
|
|
|
int get_next_free_client_id(void);
|
|
|
|
|
2022-10-26 22:38:19 +02:00
|
|
|
/* Disconnect a client using its client id */
|
|
|
|
int disconnect_client(int);
|
|
|
|
|
2022-10-21 10:28:23 +02:00
|
|
|
/* Thread, parses and handles messages */
|
2022-10-21 11:05:39 +02:00
|
|
|
void *Dispatcher(void*);
|
2022-10-21 10:28:23 +02:00
|
|
|
|
2022-10-21 09:43:04 +02:00
|
|
|
/* Thread, listens for incoming messages */
|
2022-10-21 11:05:39 +02:00
|
|
|
void *ClientListener(void*);
|
2022-10-21 09:43:04 +02:00
|
|
|
|
|
|
|
/* Thread, sends messages to the client */
|
2022-10-21 11:05:39 +02:00
|
|
|
void *ClientSender(void*);
|
2022-10-21 09:43:04 +02:00
|
|
|
|
2022-10-19 22:35:06 +02:00
|
|
|
/* Handles a client after its connection */
|
2022-09-13 21:40:23 +02:00
|
|
|
void service(int);
|
|
|
|
|
2022-10-19 22:35:06 +02:00
|
|
|
/* Handler for signal() */
|
2022-09-13 21:40:23 +02:00
|
|
|
void interrupt(int);
|
|
|
|
|
|
|
|
#endif
|