From 15774384770f1f14a21ed712ae7ec136ced65f79 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Wed, 9 Sep 2020 13:58:27 +0200 Subject: [PATCH] client: factor out connect request --- kernel/mars_client.c | 53 +++++++++++++++++++++++++------------------- kernel/mars_client.h | 2 +- 2 files changed, 31 insertions(+), 24 deletions(-) diff --git a/kernel/mars_client.c b/kernel/mars_client.c index cf90a97d..1af41b31 100644 --- a/kernel/mars_client.c +++ b/kernel/mars_client.c @@ -218,6 +218,33 @@ void _maintain_bundle(struct client_bundle *bundle) } } +static +int _request_connect(struct client_channel *ch, const char *path) +{ + struct mars_cmd cmd = { + .cmd_code = CMD_CONNECT, + .cmd_str1 = path, + }; + int status; + + status = mars_send_cmd(&ch->socket, &cmd, false); + MARS_DBG("send CMD_CONNECT status = %d\n", status); + return status; +} + +static +int _request_info(struct client_channel *ch) +{ + struct mars_cmd cmd = { + .cmd_code = CMD_GETINFO, + }; + int status; + + status = mars_send_cmd(&ch->socket, &cmd, false); + MARS_DBG("send CMD_GETINFO status = %d\n", status); + return status; +} + static struct client_channel *_get_channel(struct client_bundle *bundle, int min_channel, int max_channel) { @@ -295,12 +322,9 @@ struct client_channel *_get_channel(struct client_bundle *bundle, int min_channe // send initial connect command if (unlikely(!res->is_connected)) { - struct mars_cmd cmd = { - .cmd_code = CMD_CONNECT, - .cmd_str1 = bundle->path, - }; - int status = mars_send_cmd(&res->socket, &cmd, false); - MARS_DBG("send CMD_CONNECT status = %d\n", status); + int status; + + status = _request_connect(res, bundle->path); if (unlikely(status < 0)) { MARS_WRN("connect '%s' @%s on channel %d failed, status = %d\n", bundle->path, @@ -321,23 +345,6 @@ found: return res; } -static -int _request_info(struct client_channel *ch) -{ - struct mars_cmd cmd = { - .cmd_code = CMD_GETINFO, - }; - int status; - - MARS_DBG("\n"); - status = mars_send_cmd(&ch->socket, &cmd, false); - MARS_DBG("send CMD_GETINFO status = %d\n", status); - if (unlikely(status < 0)) { - MARS_DBG("send of getinfo failed, status = %d\n", status); - } - return status; -} - static int sender_thread(void *data); static diff --git a/kernel/mars_client.h b/kernel/mars_client.h index a3be55aa..48876217 100644 --- a/kernel/mars_client.h +++ b/kernel/mars_client.h @@ -100,9 +100,9 @@ struct client_output { MARS_OUTPUT(client); struct mutex mutex; struct list_head mref_list; - int last_id; struct client_bundle bundle; struct mars_info info; + int last_id; bool get_info; bool got_info; struct list_head *hash_table;