2016-11-09 11:52:09 +00:00
|
|
|
#ifndef OD_CLIENT_H_
|
|
|
|
#define OD_CLIENT_H_
|
|
|
|
|
|
|
|
/*
|
|
|
|
* odissey.
|
|
|
|
*
|
|
|
|
* PostgreSQL connection pooler and request router.
|
|
|
|
*/
|
|
|
|
|
2016-11-29 13:14:50 +00:00
|
|
|
typedef struct od_client_t od_client_t;
|
2016-11-09 11:52:09 +00:00
|
|
|
|
2017-02-02 09:37:51 +00:00
|
|
|
typedef enum {
|
|
|
|
OD_CUNDEF,
|
|
|
|
OD_CACTIVE,
|
2017-02-20 13:04:16 +00:00
|
|
|
OD_CQUEUE,
|
|
|
|
OD_CPENDING
|
2017-02-02 09:37:51 +00:00
|
|
|
} od_clientstate_t;
|
|
|
|
|
2016-11-29 13:14:50 +00:00
|
|
|
struct od_client_t {
|
2017-02-02 09:37:51 +00:00
|
|
|
od_clientstate_t state;
|
2017-01-24 11:01:36 +00:00
|
|
|
mm_io_t io;
|
2017-01-24 13:38:59 +00:00
|
|
|
od_schemeuser_t *scheme;
|
2017-01-24 11:01:36 +00:00
|
|
|
so_bestartup_t startup;
|
|
|
|
so_key_t key;
|
|
|
|
so_stream_t stream;
|
|
|
|
od_server_t *server;
|
2017-02-02 09:27:31 +00:00
|
|
|
void *route;
|
2017-01-24 11:01:36 +00:00
|
|
|
void *pooler;
|
|
|
|
uint64_t id;
|
2017-02-20 12:00:33 +00:00
|
|
|
uint64_t id_fiber;
|
2017-02-02 09:54:26 +00:00
|
|
|
od_list_t link_pool;
|
2017-01-24 11:01:36 +00:00
|
|
|
od_list_t link;
|
2016-11-09 11:52:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static inline void
|
2016-11-29 13:14:50 +00:00
|
|
|
od_clientinit(od_client_t *c)
|
2016-11-09 11:52:09 +00:00
|
|
|
{
|
2017-02-02 09:37:51 +00:00
|
|
|
c->state = OD_CUNDEF;
|
2016-11-09 11:52:09 +00:00
|
|
|
c->io = NULL;
|
2017-01-24 13:38:59 +00:00
|
|
|
c->scheme = NULL;
|
2017-01-24 11:01:36 +00:00
|
|
|
c->id = 0;
|
2017-02-20 12:00:33 +00:00
|
|
|
c->id_fiber = 0;
|
2016-11-09 11:52:09 +00:00
|
|
|
c->server = NULL;
|
2017-01-20 14:22:06 +00:00
|
|
|
c->route = NULL;
|
2016-11-09 12:19:26 +00:00
|
|
|
c->pooler = NULL;
|
2016-11-10 12:15:46 +00:00
|
|
|
so_bestartup_init(&c->startup);
|
2016-11-16 13:15:14 +00:00
|
|
|
so_keyinit(&c->key);
|
2016-11-10 11:53:05 +00:00
|
|
|
so_stream_init(&c->stream);
|
2017-02-02 09:54:26 +00:00
|
|
|
od_listinit(&c->link_pool);
|
2016-11-09 11:52:09 +00:00
|
|
|
od_listinit(&c->link);
|
|
|
|
}
|
|
|
|
|
2016-11-29 13:14:50 +00:00
|
|
|
static inline od_client_t*
|
2016-11-09 11:52:09 +00:00
|
|
|
od_clientalloc(void)
|
|
|
|
{
|
2016-11-29 13:14:50 +00:00
|
|
|
od_client_t *c = malloc(sizeof(*c));
|
2016-11-09 11:52:09 +00:00
|
|
|
if (c == NULL)
|
|
|
|
return NULL;
|
|
|
|
od_clientinit(c);
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2016-11-29 13:14:50 +00:00
|
|
|
od_clientfree(od_client_t *c)
|
2016-11-09 11:52:09 +00:00
|
|
|
{
|
2016-11-10 12:15:46 +00:00
|
|
|
so_bestartup_free(&c->startup);
|
2016-11-10 11:53:05 +00:00
|
|
|
so_stream_free(&c->stream);
|
2016-11-09 11:52:09 +00:00
|
|
|
free(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|