2018-08-28 14:43:46 +00:00
|
|
|
#ifndef ODYSSEY_CLIENT_H
|
|
|
|
#define ODYSSEY_CLIENT_H
|
2017-05-25 12:00:58 +00:00
|
|
|
|
|
|
|
/*
|
2018-03-12 14:03:15 +00:00
|
|
|
* Odyssey.
|
2017-05-25 12:00:58 +00:00
|
|
|
*
|
2018-04-04 13:19:58 +00:00
|
|
|
* Scalable PostgreSQL connection pooler.
|
2017-05-25 12:00:58 +00:00
|
|
|
*/
|
|
|
|
|
2018-08-28 14:43:46 +00:00
|
|
|
typedef struct od_client_ctl od_client_ctl_t;
|
|
|
|
typedef struct od_client od_client_t;
|
2017-05-25 12:00:58 +00:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
2018-08-28 14:43:46 +00:00
|
|
|
OD_CLIENT_UNDEF,
|
|
|
|
OD_CLIENT_PENDING,
|
|
|
|
OD_CLIENT_ACTIVE,
|
|
|
|
OD_CLIENT_QUEUE
|
|
|
|
} od_client_state_t;
|
2017-05-25 12:00:58 +00:00
|
|
|
|
2018-07-19 14:33:44 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2018-08-28 14:43:46 +00:00
|
|
|
OD_CLIENT_OP_NONE,
|
|
|
|
OD_CLIENT_OP_KILL
|
2018-07-19 14:33:44 +00:00
|
|
|
} od_clientop_t;
|
|
|
|
|
2018-08-28 14:43:46 +00:00
|
|
|
struct od_client_ctl
|
2018-07-19 14:33:44 +00:00
|
|
|
{
|
2018-12-06 14:23:15 +00:00
|
|
|
volatile od_clientop_t op;
|
2018-07-19 14:33:44 +00:00
|
|
|
};
|
|
|
|
|
2017-05-25 12:00:58 +00:00
|
|
|
struct od_client
|
|
|
|
{
|
2018-08-28 14:43:46 +00:00
|
|
|
od_client_state_t state;
|
|
|
|
od_id_t id;
|
|
|
|
od_client_ctl_t ctl;
|
|
|
|
uint64_t coroutine_id;
|
|
|
|
machine_io_t *io;
|
|
|
|
machine_io_t *io_notify;
|
|
|
|
machine_tls_t *tls;
|
2018-10-23 13:51:30 +00:00
|
|
|
od_packet_t packet_reader;
|
2018-12-06 14:23:15 +00:00
|
|
|
od_rule_t *rule;
|
2018-08-28 14:43:46 +00:00
|
|
|
od_config_listen_t *config_listen;
|
|
|
|
uint64_t time_accept;
|
|
|
|
uint64_t time_setup;
|
|
|
|
kiwi_be_startup_t startup;
|
|
|
|
kiwi_params_t params;
|
|
|
|
kiwi_key_t key;
|
|
|
|
od_server_t *server;
|
|
|
|
void *route;
|
|
|
|
od_global_t *global;
|
|
|
|
od_list_t link_pool;
|
|
|
|
od_list_t link;
|
2017-05-25 12:00:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
od_client_init(od_client_t *client)
|
|
|
|
{
|
2018-12-06 14:23:15 +00:00
|
|
|
client->state = OD_CLIENT_UNDEF;
|
|
|
|
client->coroutine_id = 0;
|
|
|
|
client->io = NULL;
|
|
|
|
client->tls = NULL;
|
|
|
|
client->rule = NULL;
|
2018-03-06 15:23:52 +00:00
|
|
|
client->config_listen = NULL;
|
2018-12-06 14:23:15 +00:00
|
|
|
client->server = NULL;
|
|
|
|
client->route = NULL;
|
|
|
|
client->global = NULL;
|
|
|
|
client->time_accept = 0;
|
|
|
|
client->time_setup = 0;
|
|
|
|
client->ctl.op = OD_CLIENT_OP_NONE;
|
2018-08-28 14:43:46 +00:00
|
|
|
kiwi_be_startup_init(&client->startup);
|
|
|
|
kiwi_params_init(&client->params);
|
|
|
|
kiwi_key_init(&client->key);
|
2018-10-23 13:51:30 +00:00
|
|
|
od_packet_init(&client->packet_reader);
|
2017-05-25 12:00:58 +00:00
|
|
|
od_list_init(&client->link_pool);
|
|
|
|
od_list_init(&client->link);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline od_client_t*
|
|
|
|
od_client_allocate(void)
|
|
|
|
{
|
|
|
|
od_client_t *client = malloc(sizeof(*client));
|
|
|
|
if (client == NULL)
|
|
|
|
return NULL;
|
|
|
|
od_client_init(client);
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
od_client_free(od_client_t *client)
|
|
|
|
{
|
2018-08-28 14:43:46 +00:00
|
|
|
kiwi_be_startup_free(&client->startup);
|
|
|
|
kiwi_params_free(&client->params);
|
2017-05-25 12:00:58 +00:00
|
|
|
free(client);
|
|
|
|
}
|
|
|
|
|
2018-07-19 14:33:44 +00:00
|
|
|
static inline void
|
|
|
|
od_client_notify(od_client_t *client)
|
|
|
|
{
|
2018-08-28 14:43:46 +00:00
|
|
|
machine_msg_t *msg;
|
|
|
|
msg = machine_msg_create(sizeof(uint64_t));
|
|
|
|
*(uint64_t*)machine_msg_get_data(msg) = 1;
|
|
|
|
machine_write(client->io_notify, msg);
|
2018-07-19 14:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
od_client_notify_read(od_client_t *client)
|
|
|
|
{
|
2018-08-28 14:43:46 +00:00
|
|
|
machine_msg_t *msg;
|
|
|
|
msg = machine_read(client->io_notify, sizeof(uint64_t), UINT32_MAX);
|
|
|
|
if (msg)
|
|
|
|
machine_msg_free(msg);
|
2018-07-19 14:33:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 14:23:15 +00:00
|
|
|
static inline void
|
|
|
|
od_client_kill(od_client_t *client)
|
|
|
|
{
|
|
|
|
/* TODO */
|
|
|
|
client->ctl.op = OD_CLIENT_OP_KILL;
|
|
|
|
od_client_notify(client);
|
|
|
|
}
|
|
|
|
|
2018-08-28 14:43:46 +00:00
|
|
|
#endif /* ODYSSEY_CLIENT_H */
|