2016-09-21 05:52:58 +08:00
|
|
|
#include <stdio.h>
|
2017-01-10 17:34:42 +08:00
|
|
|
#include <stdlib.h>
|
2017-01-11 03:21:30 +08:00
|
|
|
#include <getopt.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2017-01-11 17:48:25 +08:00
|
|
|
#include <pthread.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2017-01-12 23:24:59 +08:00
|
|
|
#include <poll.h>
|
2017-01-10 17:34:42 +08:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include "tsmpool.h"
|
2016-09-21 05:52:58 +08:00
|
|
|
|
|
|
|
#define MSG_START "nmux: "
|
2017-01-12 23:24:59 +08:00
|
|
|
#define NMUX_DEBUG 1
|
2016-09-21 05:52:58 +08:00
|
|
|
|
|
|
|
typedef enum client_status_e
|
|
|
|
{
|
|
|
|
CS_CREATED,
|
|
|
|
CS_THREAD_RUNNING,
|
|
|
|
CS_THREAD_FINISHED
|
|
|
|
} client_status_t;
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct client_s
|
|
|
|
{
|
|
|
|
struct sockaddr_in addr;
|
|
|
|
int socket;
|
|
|
|
int error; //set to non-zero on error (data transfer failed)
|
|
|
|
pthread_t thread;
|
2017-01-11 17:48:25 +08:00
|
|
|
tsmthread_t* tsmthread;
|
2016-09-21 05:52:58 +08:00
|
|
|
client_status_t status;
|
|
|
|
//the following members are there to give access to some global variables inside the thread:
|
2017-01-12 22:27:48 +08:00
|
|
|
tsmpool* lpool;
|
2016-09-21 05:52:58 +08:00
|
|
|
int sleeping;
|
|
|
|
} client_t;
|
2017-01-11 03:21:30 +08:00
|
|
|
|
|
|
|
void print_exit(const char* why);
|
|
|
|
void sig_handler(int signo);
|
|
|
|
void* client_thread (void* param);
|
|
|
|
void error_exit(const char* why);
|
|
|
|
void maxfd(int* maxfd, int fd);
|
|
|
|
int set_nonblocking(int fd);
|