From e53b391e0f6bc606c1f36a1dca027c2dd287bab7 Mon Sep 17 00:00:00 2001 From: Dmitry Simonenko Date: Wed, 14 Jun 2017 15:35:04 +0300 Subject: [PATCH] odissey: exit on signal; minor fixes --- lib/machinarium | 2 +- src/od_backend.c | 6 +++--- src/od_cancel.c | 4 ++-- src/od_frontend.c | 2 +- src/od_io.c | 9 +++------ src/od_pooler.c | 8 ++++---- src/od_router.c | 2 +- src/od_tls.c | 2 +- 8 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/machinarium b/lib/machinarium index d5ac45b6..b1f2b554 160000 --- a/lib/machinarium +++ b/lib/machinarium @@ -1 +1 @@ -Subproject commit d5ac45b6513e006b5da362b5dfa32d2608cf166d +Subproject commit b1f2b5545f2809d81cccbc5a7a25503d6d3b1a0a diff --git a/src/od_backend.c b/src/od_backend.c index 49a58614..c0295738 100644 --- a/src/od_backend.c +++ b/src/od_backend.c @@ -232,7 +232,7 @@ od_backend_connect(od_server_t *server) struct addrinfo *ai = NULL; int rc; rc = machine_getaddrinfo(server_scheme->host, port, NULL, &ai, 0); - if (rc < 0) { + if (rc == -1) { od_error_server(&instance->log, server->id, NULL, "failed to resolve %s:%d", server_scheme->host, @@ -244,7 +244,7 @@ od_backend_connect(od_server_t *server) /* connect to server */ rc = machine_connect(server->io, ai->ai_addr, UINT32_MAX); freeaddrinfo(ai); - if (rc < 0) { + if (rc == -1) { od_error_server(&instance->log, server->id, NULL, "failed to connect to %s:%d", server_scheme->host, @@ -461,7 +461,7 @@ int od_backend_reset(od_server_t *server) wait_try_cancel); wait_try_cancel++; rc = od_cancel(instance, route->scheme->server, &server->key, server->id); - if (rc < 0) + if (rc == -1) goto error; continue; } diff --git a/src/od_cancel.c b/src/od_cancel.c index 1c901d56..35e65fcf 100644 --- a/src/od_cancel.c +++ b/src/od_cancel.c @@ -68,7 +68,7 @@ int od_cancel(od_instance_t *instance, struct addrinfo *ai = NULL; int rc; rc = machine_getaddrinfo(server_scheme->host, port, NULL, &ai, 0); - if (rc < 0) { + if (rc == -1) { od_error_server(&instance->log, 0, "cancel", "failed to resolve %s:%d", server_scheme->host, server_scheme->port); @@ -91,7 +91,7 @@ int od_cancel(od_instance_t *instance, /* connect to server */ rc = machine_connect(server.io, ai->ai_addr, UINT32_MAX); freeaddrinfo(ai); - if (rc < 0) { + if (rc == -1) { od_error_server(&instance->log, 0, "cancel", "failed to connect to %s:%d", server_scheme->host, diff --git a/src/od_frontend.c b/src/od_frontend.c index 9a330e5c..51d4ce33 100644 --- a/src/od_frontend.c +++ b/src/od_frontend.c @@ -102,7 +102,7 @@ od_frontend_startup_read(od_client_t *client) if (rc == -1) return -1; rc = machine_read(client->io, (char*)stream->p, to_read, UINT32_MAX); - if (rc < 0) { + if (rc == -1) { od_error_client(&instance->log, client->id, "startup", "read error: %s", machine_error(client->io)); diff --git a/src/od_io.c b/src/od_io.c index 7acb75a0..ba50d58b 100644 --- a/src/od_io.c +++ b/src/od_io.c @@ -42,7 +42,7 @@ int od_read(machine_io_t *io, so_stream_t *stream, int time_ms) if (rc == -1) return -1; rc = machine_read(io, (char*)stream->p, to_read, time_ms); - if (rc < 0) + if (rc == -1) return -1; so_stream_advance(stream, to_read); request_size += to_read; @@ -53,12 +53,9 @@ int od_read(machine_io_t *io, so_stream_t *stream, int time_ms) int od_write(machine_io_t *io, so_stream_t *stream) { int rc; - rc = machine_write(io, (char*)stream->s, - so_stream_used(stream), + rc = machine_write(io, (char*)stream->s, so_stream_used(stream), UINT32_MAX); - if (rc < 0) - return -1; - return 0; + return rc; } int od_getpeername(machine_io_t *io, char *buf, int size) diff --git a/src/od_pooler.c b/src/od_pooler.c index f1d76b8c..bb29517b 100644 --- a/src/od_pooler.c +++ b/src/od_pooler.c @@ -79,7 +79,7 @@ od_pooler_main(od_pooler_t *pooler) struct addrinfo *ai = NULL; int rc; rc = machine_getaddrinfo(host, port, hints_ptr, &ai, UINT32_MAX); - if (rc < 0) { + if (rc == -1) { od_error(&instance->log, "failed to resolve %s:%d", instance->scheme.host, instance->scheme.port); @@ -97,7 +97,7 @@ od_pooler_main(od_pooler_t *pooler) /* bind to listen address and port */ rc = machine_bind(pooler->server, ai->ai_addr); freeaddrinfo(ai); - if (rc < 0) { + if (rc == -1) { od_error(&instance->log, "bind %s:%d failed", instance->scheme.host, instance->scheme.port); @@ -116,7 +116,7 @@ od_pooler_main(od_pooler_t *pooler) machine_io_t *client_io; rc = machine_accept(pooler->server, &client_io, instance->scheme.backlog, UINT32_MAX); - if (rc < 0) { + if (rc == -1) { od_error(&instance->log, "pooler: accept failed"); continue; } @@ -171,7 +171,6 @@ od_signalizer(void *arg) sigset_t mask; sigemptyset(&mask); sigaddset(&mask, SIGINT); - int rc; rc = machine_signal_init(&mask); if (rc == -1) { @@ -187,6 +186,7 @@ od_signalizer(void *arg) switch (rc) { case SIGINT: od_log(&instance->log, "pooler: SIGINT"); + exit(0); break; } } diff --git a/src/od_router.c b/src/od_router.c index a6f2bbb5..5551d2fd 100644 --- a/src/od_router.c +++ b/src/od_router.c @@ -154,7 +154,7 @@ od_router_attacher(void *arg) int rc; rc = machine_condition(route->scheme->pool_timeout); - if (rc < 0) { + if (rc == -1) { od_clientpool_set(&route->client_pool, client, OD_CPENDING); od_debug_client(&instance->log, client->id, "router", "server pool wait timedout, closing"); diff --git a/src/od_tls.c b/src/od_tls.c index b54e3412..af35af5c 100644 --- a/src/od_tls.c +++ b/src/od_tls.c @@ -205,7 +205,7 @@ od_tls_backend_connect(od_server_t *server, /* read server reply */ so_stream_reset(stream); rc = machine_read(server->io, (char*)stream->p, 1, UINT32_MAX); - if (rc < 0) { + if (rc == -1) { od_error_server(log, server->id, "tls", "read error: %s", machine_error(server->io)); return -1;