odyssey/core/od_server.h

81 lines
1.4 KiB
C
Raw Normal View History

2016-11-09 11:01:08 +00:00
#ifndef OD_SERVER_H_
#define OD_SERVER_H_
/*
* odissey.
*
* PostgreSQL connection pooler and request router.
*/
typedef struct od_server_t od_server_t;
2016-11-09 11:01:08 +00:00
typedef enum {
OD_SUNDEF,
OD_SIDLE,
OD_SEXPIRE,
2016-12-13 14:46:41 +00:00
OD_SCLOSE,
2016-11-09 11:01:08 +00:00
OD_SCONNECT,
2016-11-14 13:53:26 +00:00
OD_SRESET,
2016-11-09 11:01:08 +00:00
OD_SACTIVE
} od_serverstate_t;
2016-11-09 11:01:08 +00:00
struct od_server_t {
od_serverstate_t state;
so_stream_t stream;
2017-03-23 12:55:36 +00:00
machine_io_t io;
2017-03-31 14:32:22 +00:00
machine_tls_t tls;
int is_transaction;
2017-02-17 09:06:28 +00:00
int is_copy;
2016-11-29 13:52:29 +00:00
int64_t count_request;
int64_t count_reply;
int idle_time;
so_key_t key;
so_key_t key_client;
void *route;
2016-11-11 09:17:53 +00:00
void *pooler;
2016-11-29 13:03:39 +00:00
od_list_t link;
2016-11-09 11:01:08 +00:00
};
2016-11-29 14:40:53 +00:00
static inline int
od_server_is_sync(od_server_t *s) {
return s->count_request == s->count_reply;
}
2016-11-09 11:01:08 +00:00
static inline void
od_serverinit(od_server_t *s)
2016-11-09 11:01:08 +00:00
{
s->state = OD_SUNDEF;
s->route = NULL;
s->io = NULL;
2017-03-31 14:32:22 +00:00
s->tls = NULL;
s->pooler = NULL;
s->idle_time = 0;
s->is_transaction = 0;
2017-02-17 09:06:28 +00:00
s->is_copy = 0;
2016-11-29 13:52:29 +00:00
s->count_request = 0;
s->count_reply = 0;
2016-11-16 12:24:55 +00:00
so_keyinit(&s->key);
so_keyinit(&s->key_client);
so_stream_init(&s->stream);
2016-11-09 11:01:08 +00:00
od_listinit(&s->link);
}
static inline od_server_t*
2016-11-09 11:01:08 +00:00
od_serveralloc(void)
{
od_server_t *s = malloc(sizeof(*s));
2016-11-09 11:01:08 +00:00
if (s == NULL)
return NULL;
od_serverinit(s);
return s;
}
static inline void
od_serverfree(od_server_t *s)
2016-11-09 11:01:08 +00:00
{
so_stream_free(&s->stream);
2016-11-09 11:01:08 +00:00
free(s);
}
#endif