odissey: add connection pooler object

This commit is contained in:
Dmitry Simonenko 2016-11-09 14:42:52 +03:00
parent 3535c35eda
commit 8198e87686
4 changed files with 45 additions and 7 deletions

View File

@ -28,12 +28,10 @@ void od_init(od_t *od)
od_loginit(&od->log);
od_schemeinit(&od->scheme);
od_configinit(&od->config, &od->log, &od->scheme);
od_poolinit(&od->pool);
}
void od_free(od_t *od)
{
od_poolfree(&od->pool);
od_schemefree(&od->scheme);
od_configclose(&od->config);
od_logclose(&od->log);
@ -48,6 +46,7 @@ od_usage(od_t *od, char *path)
int od_main(od_t *od, int argc, char **argv)
{
/* validate command line options */
if (argc != 2) {
od_usage(od, argv[0]);
return 1;
@ -65,6 +64,7 @@ int od_main(od_t *od, int argc, char **argv)
}
config_file = argv[1];
}
/* config file */
int rc;
rc = od_configopen(&od->config, config_file);
if (rc == -1)
@ -75,17 +75,24 @@ int od_main(od_t *od, int argc, char **argv)
od_log(&od->log, "odissey.");
od_log(&od->log, "");
od_schemeprint(&od->scheme, &od->log);
/* reopen log file after config parsing */
if (od->scheme.log_file) {
rc = od_logopen(&od->log, od->scheme.log_file);
if (rc == -1)
return 1;
}
od_log(&od->log, "");
/* validate configuration scheme */
rc = od_schemevalidate(&od->scheme, &od->log);
if (rc == -1)
return 1;
od_log(&od->log, "ready.");
rc = od_pooler(od);
/* run connection pooler */
odpooler_t pooler;
rc = od_pooler_init(&pooler, od);
if (rc == -1)
return 1;
rc = od_pooler_start(&pooler);
if (rc == -1)
return 1;
return 0;

View File

@ -13,7 +13,6 @@ struct od_t {
odlog_t log;
odconfig_t config;
odscheme_t scheme;
odpool_t pool;
};
void od_init(od_t*);

View File

@ -23,8 +23,30 @@
#include "od.h"
#include "od_pooler.h"
int od_pooler(od_t *od)
static inline void
od_pooler(void *arg)
{
(void)od;
(void)arg;
}
int od_pooler_init(odpooler_t *p, od_t *od)
{
p->env = ft_new();
if (p->env == NULL)
return -1;
p->server = ft_io_new(p->env);
if (p->server == NULL) {
ft_free(p->env);
return -1;
}
p->od = od;
od_poolinit(&p->pool);
return 0;
}
int od_pooler_start(odpooler_t *p)
{
ft_create(p->env, od_pooler, p);
ft_start(p->env);
return 0;
}

View File

@ -7,6 +7,16 @@
* PostgreSQL connection pooler and request router.
*/
int od_pooler(od_t*);
typedef struct odpooler_t odpooler_t;
struct odpooler_t {
ft_t env;
ftio_t server;
odpool_t pool;
od_t *od;
};
int od_pooler_init(odpooler_t*, od_t*);
int od_pooler_start(odpooler_t*);
#endif