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.
|
2020-04-02 11:00:56 +00:00
|
|
|
*/
|
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;
|
2020-04-02 11:00:56 +00:00
|
|
|
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-12-07 12:12:06 +00:00
|
|
|
OD_CLIENT_OP_NONE = 0,
|
|
|
|
OD_CLIENT_OP_KILL = 1
|
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-07 12:12:06 +00:00
|
|
|
od_atomic_u32_t op;
|
2018-07-19 14:33:44 +00:00
|
|
|
};
|
|
|
|
|
2017-05-25 12:00:58 +00:00
|
|
|
struct od_client
|
|
|
|
{
|
2020-04-02 11:00:56 +00:00
|
|
|
od_client_state_t state;
|
|
|
|
od_id_t id;
|
|
|
|
od_client_ctl_t ctl;
|
|
|
|
uint64_t coroutine_id;
|
|
|
|
machine_tls_t *tls;
|
|
|
|
od_io_t io;
|
|
|
|
machine_cond_t *cond;
|
|
|
|
od_relay_t relay;
|
|
|
|
machine_io_t *notify_io;
|
|
|
|
od_rule_t *rule;
|
2018-08-28 14:43:46 +00:00
|
|
|
od_config_listen_t *config_listen;
|
2020-04-02 11:00:56 +00:00
|
|
|
uint64_t time_accept;
|
|
|
|
uint64_t time_setup;
|
|
|
|
kiwi_be_startup_t startup;
|
|
|
|
kiwi_vars_t vars;
|
|
|
|
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->tls = NULL;
|
2019-01-23 15:43:52 +00:00
|
|
|
client->cond = NULL;
|
2018-12-06 14:23:15 +00:00
|
|
|
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;
|
2019-01-23 15:43:52 +00:00
|
|
|
client->notify_io = NULL;
|
2018-12-06 14:23:15 +00:00
|
|
|
client->ctl.op = OD_CLIENT_OP_NONE;
|
2018-08-28 14:43:46 +00:00
|
|
|
kiwi_be_startup_init(&client->startup);
|
2018-12-12 13:07:25 +00:00
|
|
|
kiwi_vars_init(&client->vars);
|
2018-08-28 14:43:46 +00:00
|
|
|
kiwi_key_init(&client->key);
|
2019-01-23 15:43:52 +00:00
|
|
|
od_io_init(&client->io);
|
|
|
|
od_relay_init(&client->relay, &client->io);
|
2017-05-25 12:00:58 +00:00
|
|
|
od_list_init(&client->link_pool);
|
|
|
|
od_list_init(&client->link);
|
|
|
|
}
|
|
|
|
|
2020-04-02 11:00:56 +00:00
|
|
|
static inline od_client_t *
|
2017-05-25 12:00:58 +00:00
|
|
|
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)
|
|
|
|
{
|
2019-01-23 15:43:52 +00:00
|
|
|
od_relay_free(&client->relay);
|
|
|
|
od_io_free(&client->io);
|
|
|
|
if (client->cond)
|
|
|
|
machine_cond_free(client->cond);
|
2017-05-25 12:00:58 +00:00
|
|
|
free(client);
|
|
|
|
}
|
|
|
|
|
2020-10-22 11:01:18 +00:00
|
|
|
static inline od_retcode_t
|
2019-01-23 15:43:52 +00:00
|
|
|
od_client_notify_read(od_client_t *client)
|
2018-07-19 14:33:44 +00:00
|
|
|
{
|
2019-01-23 15:43:52 +00:00
|
|
|
uint64_t value;
|
2020-10-22 11:01:18 +00:00
|
|
|
return machine_read_raw(client->notify_io, &value, sizeof(value));
|
2018-07-19 14:33:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2019-01-23 15:43:52 +00:00
|
|
|
od_client_notify(od_client_t *client)
|
2018-07-19 14:33:44 +00:00
|
|
|
{
|
2020-11-23 08:22:17 +00:00
|
|
|
uint64_t value = 1;
|
|
|
|
size_t processed = 0;
|
|
|
|
machine_write_raw(client->notify_io, &value, sizeof(value), &processed);
|
2018-07-19 14:33:44 +00:00
|
|
|
}
|
|
|
|
|
2018-12-07 12:12:06 +00:00
|
|
|
static inline uint32_t
|
|
|
|
od_client_ctl_of(od_client_t *client)
|
|
|
|
{
|
|
|
|
return od_atomic_u32_of(&client->ctl.op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
od_client_ctl_set(od_client_t *client, uint32_t op)
|
|
|
|
{
|
|
|
|
od_atomic_u32_or(&client->ctl.op, op);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
od_client_ctl_unset(od_client_t *client, uint32_t op)
|
|
|
|
{
|
|
|
|
od_atomic_u32_xor(&client->ctl.op, op);
|
|
|
|
}
|
|
|
|
|
2018-12-06 14:23:15 +00:00
|
|
|
static inline void
|
|
|
|
od_client_kill(od_client_t *client)
|
|
|
|
{
|
2018-12-07 12:12:06 +00:00
|
|
|
od_client_ctl_set(client, OD_CLIENT_OP_KILL);
|
2018-12-06 14:23:15 +00:00
|
|
|
od_client_notify(client);
|
|
|
|
}
|
|
|
|
|
2018-08-28 14:43:46 +00:00
|
|
|
#endif /* ODYSSEY_CLIENT_H */
|