update myclib
This commit is contained in:
@@ -44,11 +44,19 @@ typedef enum cws_server_ret_t {
|
||||
CWS_SERVER_REQUEST_TOO_LARGE,
|
||||
} cws_server_ret;
|
||||
|
||||
/* TODO: use last_activity as keep-alive */
|
||||
typedef struct cws_client_t {
|
||||
struct sockaddr_storage addr;
|
||||
time_t last_activity;
|
||||
} cws_client;
|
||||
|
||||
typedef struct cws_pthread_data_t {
|
||||
int client_fd;
|
||||
int epfd;
|
||||
cws_config *config;
|
||||
mcl_hashmap *clients;
|
||||
} cws_pthread_data;
|
||||
|
||||
/**
|
||||
* @brief Setups hints object
|
||||
*
|
||||
@@ -114,6 +122,6 @@ int cws_server_accept_client(int sockfd, struct sockaddr_storage *their_sa, sock
|
||||
void cws_server_close_client(int epfd, int client_fd, mcl_hashmap *hashmap);
|
||||
|
||||
cws_server_ret cws_server_handle_new_client(int sockfd, int epfd, mcl_hashmap *clients);
|
||||
cws_server_ret cws_server_handle_client_data(int client_fd, int epfd, mcl_hashmap *clients, cws_config *config);
|
||||
void *cws_server_handle_client_data(void *arg);
|
||||
|
||||
#endif
|
||||
|
||||
34
include/server/threadpool.h
Normal file
34
include/server/threadpool.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef CWS_THREADPOOL_H
|
||||
#define CWS_THREADPOOL_H
|
||||
|
||||
#include "myclib/hashmap/myhashmap.h"
|
||||
#include "server.h"
|
||||
#include "utils/config.h"
|
||||
|
||||
#define CWS_MAX_QUEUE_TASKS 16
|
||||
#define CWS_MAX_THREADS 16
|
||||
|
||||
typedef struct cws_task_t {
|
||||
int client_fd;
|
||||
int epfd;
|
||||
mcl_hashmap *clients;
|
||||
cws_config *config;
|
||||
} cws_task;
|
||||
|
||||
typedef struct cws_threadpool_t {
|
||||
cws_task queue[CWS_MAX_QUEUE_TASKS];
|
||||
int front, rear;
|
||||
|
||||
pthread_mutex_t lock;
|
||||
pthread_cond_t cond;
|
||||
pthread_t threads[CWS_MAX_THREADS];
|
||||
|
||||
int shutdown;
|
||||
} cws_threadpool;
|
||||
|
||||
cws_threadpool *cws_threadpool_init();
|
||||
cws_server_ret cws_threadpool_add_task(cws_threadpool *pool, cws_task *task);
|
||||
cws_server_ret cws_threadpool_worker(cws_threadpool *pool);
|
||||
cws_server_ret cws_threadpool_destroy(cws_threadpool *pool);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user