From fe5d8d3643c2bc2fdb95b0351b26fb286cf778b7 Mon Sep 17 00:00:00 2001 From: Krutika Dhananjay Date: Thu, 26 Jul 2018 21:47:24 +0530 Subject: socket: Remove code duplication While I was reading code, I saw that socket_submit_request() and socket_submit_reply() are identical except for @a_byte and the source of @msg object being different. This patch moves all of the common code to a new function with the differing vars passed as parameters by the callers. Change-Id: I7a62ae72f10c34dc8de01b250d89a77ec5ab490d fixes: bz#1608991 Signed-off-by: Krutika Dhananjay --- rpc/rpc-transport/socket/src/socket.c | 82 ++++++----------------------------- 1 file changed, 13 insertions(+), 69 deletions(-) (limited to 'rpc/rpc-transport') diff --git a/rpc/rpc-transport/socket/src/socket.c b/rpc/rpc-transport/socket/src/socket.c index fbf5d349b93..9518bb9d9df 100644 --- a/rpc/rpc-transport/socket/src/socket.c +++ b/rpc/rpc-transport/socket/src/socket.c @@ -3825,17 +3825,15 @@ out: return ret; } - static int32_t -socket_submit_request (rpc_transport_t *this, rpc_transport_req_t *req) +socket_submit_outgoing_msg (rpc_transport_t *this, rpc_transport_msg_t *msg) { - socket_private_t *priv = NULL; - int ret = -1; - struct ioq *entry = NULL; - glusterfs_ctx_t *ctx = NULL; + int ret = -1; char need_poll_out = 0; - char need_append = 1; - + char need_append = 1; + struct ioq *entry = NULL; + glusterfs_ctx_t *ctx = NULL; + socket_private_t *priv = NULL; GF_VALIDATE_OR_GOTO ("socket", this, out); GF_VALIDATE_OR_GOTO ("socket", this->private, out); @@ -3856,7 +3854,7 @@ socket_submit_request (rpc_transport_t *this, rpc_transport_req_t *req) } priv->submit_log = 0; - entry = __socket_ioq_new (this, &req->msg); + entry = __socket_ioq_new (this, msg); if (!entry) goto unlock; @@ -3889,72 +3887,18 @@ out: return ret; } +static int32_t +socket_submit_request (rpc_transport_t *this, rpc_transport_req_t *req) +{ + return socket_submit_outgoing_msg (this, &req->msg); +} static int32_t socket_submit_reply (rpc_transport_t *this, rpc_transport_reply_t *reply) { - socket_private_t *priv = NULL; - int ret = -1; - struct ioq *entry = NULL; - glusterfs_ctx_t *ctx = NULL; - char need_poll_out = 0; - char need_append = 1; - - - GF_VALIDATE_OR_GOTO ("socket", this, out); - GF_VALIDATE_OR_GOTO ("socket", this->private, out); - - priv = this->private; - ctx = this->ctx; - - pthread_mutex_lock (&priv->out_lock); - { - if (priv->connected != 1) { - if (!priv->submit_log && !priv->connect_finish_log) { - gf_log (this->name, GF_LOG_INFO, - "not connected (priv->connected = %d)", - priv->connected); - priv->submit_log = 1; - } - goto unlock; - } - - priv->submit_log = 0; - entry = __socket_ioq_new (this, &reply->msg); - - if (!entry) - goto unlock; - - if (list_empty (&priv->ioq)) { - ret = __socket_ioq_churn_entry (this, entry, 1); - - if (ret == 0) { - need_append = 0; - } - if (ret > 0) { - need_poll_out = 1; - } - } - - if (need_append) { - list_add_tail (&entry->list, &priv->ioq); - } - - if (need_poll_out) { - /* first entry to wait. continue writing on POLLOUT */ - priv->idx = event_select_on (ctx->event_pool, - priv->sock, - priv->idx, -1, 1); - } - } -unlock: - pthread_mutex_unlock (&priv->out_lock); - -out: - return ret; + return socket_submit_outgoing_msg (this, &reply->msg); } - static int32_t socket_getpeername (rpc_transport_t *this, char *hostname, int hostlen) { -- cgit