new: add pool server handler
This commit is contained in:
@ -8,4 +8,4 @@ lm_pool_t *lm_ctx_pools_add(lm_ctx_t *ctx, char *name, char *url);
|
||||
bool lm_ctx_pools_del(lm_ctx_t *ctx, char *name);
|
||||
void lm_ctx_pools_clear(lm_ctx_t *ctx);
|
||||
void lm_ctx_pools_test(lm_ctx_t *ctx);
|
||||
bool lm_ctx_pools_serve(lm_ctx_t *ctx, char *addr);
|
||||
bool lm_ctx_pools_serve(lm_ctx_t *ctx, char *addr, uint8_t threads);
|
||||
|
@ -54,7 +54,8 @@
|
||||
|
||||
[8 bits] HOST SIZE
|
||||
=========================================================
|
||||
| All bits used for specifying HOST size
|
||||
| All bits used for specifying HOST size, always zero
|
||||
| for responses
|
||||
---------------------------------------------------------
|
||||
|
||||
[8 bits] DATA SIZE
|
||||
@ -65,7 +66,7 @@
|
||||
[...] HOST
|
||||
---------------------------------------------------------
|
||||
| Plaintext server hostname, max size is 255 octets
|
||||
| see the SIZE section
|
||||
| see the SIZE section, always empty for responses
|
||||
---------------------------------------------------------
|
||||
|
||||
[...] DATA
|
||||
@ -125,8 +126,10 @@ bool lm_mptp_init(lm_mptp_t *packet, bool is_request, uint8_t code, bool is_last
|
||||
bool lm_mptp_set_data(lm_mptp_t *packet, char *data, size_t size);
|
||||
bool lm_mptp_set_host(lm_mptp_t *packet, char *host);
|
||||
bool lm_mptp_get_host(lm_mptp_t *packet, char *host);
|
||||
bool lm_mptp_get_data(lm_mptp_t *packet, char *data);
|
||||
|
||||
int lm_mptp_socket(char *addr, uint16_t port, struct sockaddr *saddr);
|
||||
void lm_mptp_copy(lm_mptp_t *dst, lm_mptp_t *src);
|
||||
bool lm_mptp_verify(lm_mptp_t *packet);
|
||||
void lm_mptp_close(int sock);
|
||||
|
||||
|
@ -1,9 +1,20 @@
|
||||
#pragma once
|
||||
#include "mptp.h"
|
||||
#include "types.h"
|
||||
#include <stdbool.h>
|
||||
#include <sys/socket.h>
|
||||
|
||||
typedef struct lm_pool_thread_arg {
|
||||
int sock;
|
||||
struct sockaddr addr;
|
||||
lm_mptp_t packet;
|
||||
lm_pool_t *pool;
|
||||
} lm_pool_thread_arg_t;
|
||||
|
||||
lm_pool_t *lm_pool_new(char *name, char *url);
|
||||
void lm_pool_test(lm_pool_t *pool);
|
||||
bool lm_pool_info_file(lm_pool_t *pool, char *file);
|
||||
bool lm_pool_info(lm_pool_t *pool, char *info);
|
||||
bool lm_pool_info_load(lm_pool_t *pool, char *file);
|
||||
void lm_pool_info_free(lm_pool_t *pool);
|
||||
void lm_pool_free(lm_pool_t *pool);
|
||||
void lm_pool_serve_thread(void *arg);
|
||||
void lm_pool_serve(lm_pool_t *pool, lm_mptp_t *packet, int sock, struct sockaddr *addr);
|
||||
|
28
include/thpool.h
Normal file
28
include/thpool.h
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
#include <pthread.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
typedef void (*lm_thfunc_t)(void *arg);
|
||||
typedef struct lm_thwork_t {
|
||||
lm_thfunc_t func;
|
||||
void *arg;
|
||||
struct lm_thwork_t *next;
|
||||
} lm_thwork_t;
|
||||
|
||||
typedef struct lm_thpool_t {
|
||||
pthread_mutex_t mutex;
|
||||
|
||||
pthread_cond_t work_lock;
|
||||
pthread_cond_t thread_lock;
|
||||
|
||||
size_t active;
|
||||
size_t all;
|
||||
|
||||
lm_thwork_t *first;
|
||||
lm_thwork_t *last;
|
||||
bool stop;
|
||||
} lm_thpool_t;
|
||||
|
||||
bool lm_thpool_init(lm_thpool_t *tp, int n);
|
||||
bool lm_thpool_add(lm_thpool_t *tp, lm_thfunc_t func, void *data);
|
||||
void lm_thpool_stop(lm_thpool_t *tp);
|
@ -7,6 +7,7 @@ typedef struct lm_pool_info {
|
||||
char *maintainer;
|
||||
char *pubkey;
|
||||
size_t size;
|
||||
char *file;
|
||||
} lm_pool_info_t;
|
||||
|
||||
typedef struct lm_pool {
|
||||
|
Reference in New Issue
Block a user