diff --git a/lib/machinarium b/lib/machinarium index f84548fe..e6580454 160000 --- a/lib/machinarium +++ b/lib/machinarium @@ -1 +1 @@ -Subproject commit f84548fe783356568de956131049692b9f41d410 +Subproject commit e65804541052244b17677c8b037ae37e0b389baf diff --git a/src/od_auth.c b/src/od_auth.c index 0b14c367..4317c361 100644 --- a/src/od_auth.c +++ b/src/od_auth.c @@ -36,8 +36,10 @@ #include "od_client_pool.h" #include "od_route_id.h" #include "od_route.h" +#include "od_route_pool.h" #include "od_io.h" +#include "od_router.h" #include "od_pooler.h" #include "od_relay.h" #include "od_frontend.h" diff --git a/src/od_backend.c b/src/od_backend.c index aa24d8cd..ccb685e8 100644 --- a/src/od_backend.c +++ b/src/od_backend.c @@ -39,8 +39,8 @@ #include "od_route_pool.h" #include "od_io.h" -#include "od_pooler.h" #include "od_router.h" +#include "od_pooler.h" #include "od_relay.h" #include "od_frontend.h" #include "od_backend.h" diff --git a/src/od_cancel.c b/src/od_cancel.c index 588b6dcb..f344a943 100644 --- a/src/od_cancel.c +++ b/src/od_cancel.c @@ -39,8 +39,8 @@ #include "od_route_pool.h" #include "od_io.h" -#include "od_pooler.h" #include "od_router.h" +#include "od_pooler.h" #include "od_relay.h" #include "od_frontend.h" #include "od_backend.h" diff --git a/src/od_frontend.c b/src/od_frontend.c index 124c9714..f3eeece5 100644 --- a/src/od_frontend.c +++ b/src/od_frontend.c @@ -39,8 +39,8 @@ #include "od_route_pool.h" #include "od_io.h" -#include "od_pooler.h" #include "od_router.h" +#include "od_pooler.h" #include "od_relay.h" #include "od_frontend.h" #include "od_backend.h" @@ -488,7 +488,10 @@ void od_frontend(void *arg) od_log_client(&instance->log, client->id, NULL, "disconnected (read/write error): %s", machine_error(client->io)); - + if (! client->server) { + od_unroute(client); + break; + } rc = od_backend_reset(server); if (rc != 1) { /* close backend connection */ diff --git a/src/od_instance.c b/src/od_instance.c index 0d913a10..33101626 100644 --- a/src/od_instance.c +++ b/src/od_instance.c @@ -39,8 +39,8 @@ #include "od_route_pool.h" #include "od_io.h" -#include "od_pooler.h" #include "od_router.h" +#include "od_pooler.h" #include "od_relay.h" #include "od_relay_pool.h" #include "od_frontend.h" @@ -158,13 +158,10 @@ int od_instance_main(od_instance_t *instance, int argc, char **argv) return 1; } - od_pooler_init(&pooler, &system); - rc = od_pooler_start(&pooler); - if (rc == -1) - return 1; - od_router_init(&router, &system); - rc = od_router_start(&router); + od_pooler_init(&pooler, &system); + + rc = od_pooler_start(&pooler); if (rc == -1) return 1; diff --git a/src/od_periodic.c b/src/od_periodic.c index b4aacb11..58fff311 100644 --- a/src/od_periodic.c +++ b/src/od_periodic.c @@ -39,8 +39,8 @@ #include "od_route_pool.h" #include "od_io.h" -#include "od_pooler.h" #include "od_router.h" +#include "od_pooler.h" #include "od_relay.h" #include "od_frontend.h" #include "od_backend.h" diff --git a/src/od_pooler.c b/src/od_pooler.c index 2a344b61..a9b3094b 100644 --- a/src/od_pooler.c +++ b/src/od_pooler.c @@ -35,6 +35,8 @@ #include "od_client_pool.h" #include "od_route_id.h" #include "od_route.h" +#include "od_route_pool.h" +#include "od_router.h" #include "od_pooler.h" #include "od_tls.h" @@ -42,12 +44,18 @@ static inline void od_pooler(void *arg) { od_pooler_t *pooler = arg; + od_router_t *router = pooler->system->router; od_instance_t *instance = pooler->system->instance; od_log(&instance->log, "pooler: started"); - /* init pooler tls */ + /* start router coroutine */ int rc; + rc = od_router_start(router); + if (rc == -1) + return; + + /* init pooler tls */ pooler->tls = NULL; od_scheme_t *scheme = &instance->scheme; if (scheme->tls_verify != OD_TDISABLE) { diff --git a/src/od_relay.c b/src/od_relay.c index d562e1db..d2a4b1e1 100644 --- a/src/od_relay.c +++ b/src/od_relay.c @@ -36,7 +36,9 @@ #include "od_client_pool.h" #include "od_route_id.h" #include "od_route.h" +#include "od_route_pool.h" +#include "od_router.h" #include "od_pooler.h" #include "od_relay.h" #include "od_frontend.h" diff --git a/src/od_relay_pool.c b/src/od_relay_pool.c index ad8cc556..88ae4a20 100644 --- a/src/od_relay_pool.c +++ b/src/od_relay_pool.c @@ -36,7 +36,9 @@ #include "od_client_pool.h" #include "od_route_id.h" #include "od_route.h" +#include "od_route_pool.h" +#include "od_router.h" #include "od_pooler.h" #include "od_relay.h" #include "od_relay_pool.h" diff --git a/src/od_router.c b/src/od_router.c index 0f7265b2..a5b76d1f 100644 --- a/src/od_router.c +++ b/src/od_router.c @@ -39,9 +39,9 @@ #include "od_route_pool.h" #include "od_io.h" +#include "od_router.h" #include "od_pooler.h" #include "od_relay.h" -#include "od_router.h" #include "od_frontend.h" #include "od_backend.h" #include "od_cancel.h" @@ -344,7 +344,6 @@ int od_router_init(od_router_t *router, od_system_t *system) { od_instance_t *instance = system->instance; od_routepool_init(&router->route_pool); - router->machine = -1; router->system = system; router->server_seq = 0; router->queue = machine_queue_create(); @@ -358,8 +357,9 @@ int od_router_init(od_router_t *router, od_system_t *system) int od_router_start(od_router_t *router) { od_instance_t *instance = router->system->instance; - router->machine = machine_create("router", od_router, router); - if (router->machine == -1) { + int64_t coroutine_id; + coroutine_id = machine_coroutine_create(od_router, router); + if (coroutine_id == -1) { od_error(&instance->log, "failed to start router"); return 1; } diff --git a/src/od_router.h b/src/od_router.h index 5614fe56..b07f84e2 100644 --- a/src/od_router.h +++ b/src/od_router.h @@ -19,7 +19,6 @@ typedef enum struct od_router { - int64_t machine; od_routepool_t route_pool; machine_queue_t queue; uint64_t server_seq; diff --git a/src/od_tls.c b/src/od_tls.c index efa9f9b1..dfbf24d2 100644 --- a/src/od_tls.c +++ b/src/od_tls.c @@ -39,8 +39,8 @@ #include "od_route_pool.h" #include "od_io.h" -#include "od_pooler.h" #include "od_router.h" +#include "od_pooler.h" #include "od_relay.h" #include "od_tls.h"