2016-11-09 12:19:26 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* odissey.
|
|
|
|
*
|
|
|
|
* PostgreSQL connection pooler and request router.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include <flint.h>
|
2016-11-10 11:53:05 +00:00
|
|
|
#include <soprano.h>
|
2016-11-09 12:19:26 +00:00
|
|
|
|
|
|
|
#include "od_macro.h"
|
|
|
|
#include "od_list.h"
|
|
|
|
#include "od_log.h"
|
|
|
|
#include "od_scheme.h"
|
|
|
|
#include "od_lex.h"
|
|
|
|
#include "od_config.h"
|
|
|
|
#include "od_server.h"
|
|
|
|
#include "od_server_pool.h"
|
2016-11-11 09:56:56 +00:00
|
|
|
#include "od_route.h"
|
|
|
|
#include "od_route_pool.h"
|
2016-11-09 12:19:26 +00:00
|
|
|
#include "od_client.h"
|
|
|
|
#include "od_client_pool.h"
|
|
|
|
#include "od.h"
|
2016-11-10 12:39:25 +00:00
|
|
|
#include "od_read.h"
|
2016-11-09 12:19:26 +00:00
|
|
|
#include "od_pooler.h"
|
|
|
|
#include "od_router.h"
|
2016-11-10 12:39:25 +00:00
|
|
|
#include "od_fe.h"
|
|
|
|
#include "od_be.h"
|
2016-11-10 11:53:05 +00:00
|
|
|
|
2016-11-11 09:56:56 +00:00
|
|
|
static odroute_t*
|
2016-11-10 13:04:23 +00:00
|
|
|
od_route(odclient_t *client)
|
|
|
|
{
|
2016-11-11 09:56:56 +00:00
|
|
|
odroute_t *route = NULL;
|
2016-11-10 13:04:23 +00:00
|
|
|
return route;
|
|
|
|
}
|
|
|
|
|
2016-11-09 12:19:26 +00:00
|
|
|
void od_router(void *arg)
|
|
|
|
{
|
|
|
|
odclient_t *client = arg;
|
|
|
|
odpooler_t *pooler = client->pooler;
|
2016-11-09 12:31:17 +00:00
|
|
|
|
2016-11-10 11:53:05 +00:00
|
|
|
od_log(&pooler->od->log, "C: new connection");
|
|
|
|
|
|
|
|
/* client startup */
|
2016-11-10 12:15:46 +00:00
|
|
|
int rc = od_festartup(client);
|
2016-11-10 11:53:05 +00:00
|
|
|
if (rc == -1) {
|
2016-11-10 12:02:38 +00:00
|
|
|
od_feclose(client);
|
2016-11-10 11:53:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* client cancel request */
|
2016-11-10 12:15:46 +00:00
|
|
|
if (client->startup.is_cancel) {
|
2016-11-10 11:53:05 +00:00
|
|
|
od_log(&pooler->od->log, "C: cancel request");
|
2016-11-10 12:02:38 +00:00
|
|
|
od_feclose(client);
|
2016-11-10 11:53:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-11-09 12:31:17 +00:00
|
|
|
/* client auth */
|
2016-11-10 12:02:38 +00:00
|
|
|
rc = od_feauth(client);
|
2016-11-10 11:53:05 +00:00
|
|
|
if (rc == -1) {
|
2016-11-10 12:02:38 +00:00
|
|
|
od_feclose(client);
|
2016-11-10 11:53:05 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-11-09 12:31:17 +00:00
|
|
|
|
2016-11-10 13:04:23 +00:00
|
|
|
/* route client */
|
2016-11-11 09:56:56 +00:00
|
|
|
odroute_t *route = od_route(client);
|
2016-11-10 13:04:23 +00:00
|
|
|
|
|
|
|
/* get server connection for the route */
|
|
|
|
odserver_t *server = od_bepop(pooler, route);
|
2016-11-10 12:10:19 +00:00
|
|
|
if (server == NULL) {
|
|
|
|
od_feclose(client);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* link server with client */
|
2016-11-10 12:39:25 +00:00
|
|
|
client->server = server;
|
2016-11-09 12:31:17 +00:00
|
|
|
|
|
|
|
while (1) {
|
2016-11-10 12:02:38 +00:00
|
|
|
rc = od_read(client->io, &client->stream);
|
2016-11-10 11:53:05 +00:00
|
|
|
if (rc == -1) {
|
2016-11-10 12:02:38 +00:00
|
|
|
od_feclose(client);
|
2016-11-10 11:53:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
char type = *client->stream.s;
|
|
|
|
od_log(&pooler->od->log, "C: %c", type);
|
|
|
|
|
2016-11-09 12:31:17 +00:00
|
|
|
/* write(server, packet) */
|
|
|
|
while (1) {
|
|
|
|
/* packet = read(server) */
|
|
|
|
/* write(client, packet) */
|
|
|
|
/* if Z break */
|
|
|
|
}
|
|
|
|
}
|
2016-11-09 12:19:26 +00:00
|
|
|
}
|