89 lines
2.3 KiB
C
89 lines
2.3 KiB
C
#ifndef VESSEL_SERVER_H_
|
|
#define VESSEL_SERVER_H_
|
|
|
|
#include "conf.h"
|
|
|
|
#include "def.h"
|
|
#include "log.h"
|
|
#include "hook.h"
|
|
#include "stream.h"
|
|
#include "thread.h"
|
|
|
|
#include <pthread.h>
|
|
#include <sys/time.h>
|
|
#include <netinet/in.h>
|
|
|
|
#ifndef VS_MAX_SOCK_SERVERS
|
|
# define VS_MAX_SOCK_SERVERS 4096
|
|
#endif /* VS_MAX_SOCK_SERVERS */
|
|
|
|
#ifndef VS_MAX_SOCK_RETRIES
|
|
# define VS_MAX_SOCK_RETRIES 16
|
|
#endif /* VS_MAX_SOCK_RETRIES */
|
|
|
|
#ifndef VS_MAX_SOCK_UNLOCK_RETRIES
|
|
# define VS_MAX_SOCK_UNLOCK_RETRIES 24
|
|
#endif /* VS_MAX_SOCK_UNLOCK_RETRIES */
|
|
|
|
typedef struct {
|
|
volatile bool occupied;
|
|
volatile bool dirty;
|
|
vs_Stream stream;
|
|
struct sockaddr_in client_addr;
|
|
vs_Thread thread;
|
|
vs_Lock lock;
|
|
const vs_Logger *logger;
|
|
void *arg; /* Feel free to use this for any custom storage pass-through. */
|
|
} vs_SockWorker;
|
|
|
|
typedef struct {
|
|
/* Setup state */
|
|
|
|
const char *host;
|
|
uint16_t port;
|
|
|
|
const vs_Logger *logger;
|
|
uint16_t threads;
|
|
|
|
/* Server state */
|
|
|
|
vs_File file;
|
|
struct sockaddr_in addr;
|
|
|
|
vs_SockWorker *workers;
|
|
vs_Lock lock;
|
|
volatile bool run;
|
|
|
|
/* Developer state */
|
|
|
|
void *arg; /* Feel free to use this for any state pass-through. */
|
|
} vs_SockServer;
|
|
|
|
typedef enum {
|
|
vs_SockWorkerHookType_pre_open = 0,
|
|
vs_SockWorkerHookType_post_open,
|
|
vs_SockWorkerHookType_pre_close,
|
|
vs_SockWorkerHookType_post_close,
|
|
vs_SockWorkerHookType_timeout,
|
|
} vs_SockWorkerHookType;
|
|
|
|
VS_DECLARE_HOOKS(vs_SockWorker, vs_SockWorkerHookType, vs_SockWorker *);
|
|
|
|
typedef enum {
|
|
vs_SockServerHookType_no_worker = 0,
|
|
vs_SockServerHookType_pre_worker,
|
|
} vs_SockServerHookType;
|
|
|
|
VS_DECLARE_HOOKS(vs_SockServer, vs_SockServerHookType, vs_SockServer *);
|
|
|
|
#define VS_SOCK_SER_VV4 AF_INET, SOCK_STREAM, 0
|
|
|
|
bool vs_SockServer_create_generic(vs_SockServer *server);
|
|
bool vs_SockServer_init(vs_SockServer *server, suseconds_t timeout);
|
|
bool vs_SockServer_setup_signals(vs_SockServer *server);
|
|
bool vs_SockServer_start(vs_SockServer *server,
|
|
const vs_SockWorkerHook *worker_hooks,
|
|
const vs_SockServerHook *server_hooks);
|
|
bool vs_SockServer_destroy(vs_SockServer *server);
|
|
|
|
#endif /* VESSEL_SERVER_H_ */
|