odyssey/core/od_router.c

98 lines
1.7 KiB
C
Raw Normal View History

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>
#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"
#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"
static odroute_t*
2016-11-10 13:04:23 +00:00
od_route(odclient_t *client)
{
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
od_log(&pooler->od->log, "C: new connection");
/* client startup */
int rc = od_festartup(client);
if (rc == -1) {
od_feclose(client);
return;
}
/* client cancel request */
if (client->startup.is_cancel) {
od_log(&pooler->od->log, "C: cancel request");
od_feclose(client);
return;
}
2016-11-09 12:31:17 +00:00
/* client auth */
rc = od_feauth(client);
if (rc == -1) {
od_feclose(client);
return;
}
2016-11-09 12:31:17 +00:00
2016-11-10 13:04:23 +00:00
/* route client */
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) {
rc = od_read(client->io, &client->stream);
if (rc == -1) {
od_feclose(client);
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
}