2017-05-29 15:33:44 +00:00
|
|
|
|
|
|
|
/*
|
2018-03-12 14:03:15 +00:00
|
|
|
* Odyssey.
|
2017-05-29 15:33:44 +00:00
|
|
|
*
|
2018-04-04 13:19:58 +00:00
|
|
|
* Scalable PostgreSQL connection pooler.
|
2017-05-29 15:33:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2018-08-28 14:43:46 +00:00
|
|
|
#include <ctype.h>
|
2017-05-31 15:47:15 +00:00
|
|
|
#include <inttypes.h>
|
2018-08-28 14:43:46 +00:00
|
|
|
#include <assert.h>
|
2017-05-29 15:33:44 +00:00
|
|
|
|
|
|
|
#include <machinarium.h>
|
2018-08-28 14:43:46 +00:00
|
|
|
#include <kiwi.h>
|
|
|
|
#include <odyssey.h>
|
2017-05-29 15:33:44 +00:00
|
|
|
|
2018-08-28 14:43:46 +00:00
|
|
|
int
|
|
|
|
od_cancel(od_global_t *global,
|
|
|
|
od_config_storage_t *server_config,
|
|
|
|
kiwi_key_t *key,
|
|
|
|
od_id_t *server_id)
|
2017-05-29 15:33:44 +00:00
|
|
|
{
|
2018-03-13 13:17:27 +00:00
|
|
|
od_instance_t *instance = global->instance;
|
2017-09-21 13:44:19 +00:00
|
|
|
od_log(&instance->logger, "cancel", NULL, NULL,
|
|
|
|
"cancel for %s%.*s",
|
2017-07-26 14:35:39 +00:00
|
|
|
server_id->id_prefix,
|
2017-07-26 14:05:29 +00:00
|
|
|
sizeof(server_id->id), server_id->id);
|
2017-06-16 12:28:37 +00:00
|
|
|
od_server_t server;
|
|
|
|
od_server_init(&server);
|
2018-03-13 13:17:27 +00:00
|
|
|
server.global = global;
|
2018-08-28 14:43:46 +00:00
|
|
|
od_backend_connect_cancel(&server, server_config, key);
|
2018-02-15 13:06:46 +00:00
|
|
|
od_backend_close_connection(&server);
|
2017-06-02 13:49:20 +00:00
|
|
|
od_backend_close(&server);
|
2017-05-29 15:33:44 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2017-05-30 11:34:08 +00:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
od_cancel_cmp(od_server_t *server, void *arg)
|
|
|
|
{
|
2018-08-28 14:43:46 +00:00
|
|
|
kiwi_key_t *key = arg;
|
|
|
|
return kiwi_key_cmp(&server->key_client, key);
|
2017-05-30 11:34:08 +00:00
|
|
|
}
|
|
|
|
|
2018-08-28 14:43:46 +00:00
|
|
|
int od_cancel_find(od_route_pool_t *route_pool, kiwi_key_t *key,
|
|
|
|
od_router_cancel_t *cancel)
|
2017-05-30 11:34:08 +00:00
|
|
|
{
|
|
|
|
/* match server by client key (forge) */
|
|
|
|
od_server_t *server;
|
2018-08-28 14:43:46 +00:00
|
|
|
server = od_route_pool_server_foreach(route_pool, OD_SERVER_ACTIVE,
|
|
|
|
od_cancel_cmp,
|
|
|
|
key);
|
2017-05-30 11:34:08 +00:00
|
|
|
if (server == NULL)
|
|
|
|
return -1;
|
|
|
|
od_route_t *route = server->route;
|
2018-02-22 13:43:52 +00:00
|
|
|
cancel->id = server->id;
|
2018-08-28 14:43:46 +00:00
|
|
|
cancel->config = od_config_storage_copy(route->config->storage);
|
2018-03-06 15:23:52 +00:00
|
|
|
if (cancel->config == NULL)
|
2018-02-22 13:43:52 +00:00
|
|
|
return -1;
|
|
|
|
cancel->key = server->key;
|
|
|
|
return 0;
|
2017-05-30 11:34:08 +00:00
|
|
|
}
|