diff options
author | Krutika Dhananjay <kdhananj@redhat.com> | 2018-07-26 21:47:24 +0530 |
---|---|---|
committer | Raghavendra G <rgowdapp@redhat.com> | 2018-08-02 02:58:34 +0000 |
commit | fe5d8d3643c2bc2fdb95b0351b26fb286cf778b7 (patch) | |
tree | d955cf46b2c7761f8e06677d2033bea96c9219c1 /rpc/rpc-transport/socket | |
parent | e91bffad97da117f2c4eb8db45ab7874e59addf5 (diff) |
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 <kdhananj@redhat.com>
Diffstat (limited to 'rpc/rpc-transport/socket')
-rw-r--r-- | rpc/rpc-transport/socket/src/socket.c | 82 |
1 files changed, 13 insertions, 69 deletions
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) { |