From 3fe9f2c6a1a80e9ccb408bd3cf0dd53d657bebb0 Mon Sep 17 00:00:00 2001 From: Patrick J Cherry Date: Wed, 14 Nov 2018 10:23:05 +0000 Subject: [PATCH] Removed a couple of gotos. Hadn't you heard? They're considered harmful. --- Makefile | 3 ++- src/proxy/proxy.c | 17 +++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index e8869db..12b038d 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ VPATH=src:tests/unit DESTDIR?=/ PREFIX?=/usr/local/bin INSTALLDIR=$(DESTDIR)/$(PREFIX) - +DEBUG=1 + ifdef DEBUG CFLAGS_EXTRA=-g -DDEBUG LDFLAGS_EXTRA=-g diff --git a/src/proxy/proxy.c b/src/proxy/proxy.c index f08d00d..b17dd11 100644 --- a/src/proxy/proxy.c +++ b/src/proxy/proxy.c @@ -537,7 +537,7 @@ int proxy_read_init_from_upstream(struct proxier *proxy, int state) if (count == -1) { warn(SHOW_ERRNO("Failed to read init from upstream")); - goto disconnect; + return CONNECT_TO_UPSTREAM; } if (proxy->init.needle == proxy->init.size) { @@ -547,7 +547,7 @@ int proxy_read_init_from_upstream(struct proxier *proxy, int state) ((struct nbd_init_raw *) proxy->init.buf, &upstream_size, &upstream_flags)) { warn("Upstream sent invalid init"); - goto disconnect; + return CONNECT_TO_UPSTREAM; } /* record the flags, and log the reconnection, set TCP_NODELAY */ @@ -565,9 +565,6 @@ int proxy_read_init_from_upstream(struct proxier *proxy, int state) } return state; - - disconnect: - return CONNECT_TO_UPSTREAM; } int proxy_write_to_upstream(struct proxier *proxy, int state) @@ -625,7 +622,7 @@ int proxy_read_from_upstream(struct proxier *proxy, int state) if (count == -1) { warn(SHOW_ERRNO("Failed to get reply from upstream")); - goto disconnect; + return CONNECT_TO_UPSTREAM; } if (proxy->rsp.needle == NBD_REPLY_SIZE) { @@ -633,7 +630,7 @@ int proxy_read_from_upstream(struct proxier *proxy, int state) if (reply->magic != REPLY_MAGIC) { warn("Reply magic is incorrect"); - goto disconnect; + return CONNECT_TO_UPSTREAM; } if (proxy->req_hdr.type == REQUEST_READ) { @@ -649,9 +646,6 @@ int proxy_read_from_upstream(struct proxier *proxy, int state) } return state; - - disconnect: - return CONNECT_TO_UPSTREAM; } @@ -861,8 +855,7 @@ void proxy_session(struct proxier *proxy) */ if (old_state == state && proxy_state_upstream(state)) { if ((monotonic_time_ms()) - state_started > UPSTREAM_TIMEOUT) { - warn("Timed out in state %s while communicating with upstream", proxy_session_state_names[state] - ); + warn("Timed out in state %s while communicating with upstream", proxy_session_state_names[state]); state = CONNECT_TO_UPSTREAM; } }