From ff8e08e6c7af2a6d4172b78f0224bf5bd3d3852c Mon Sep 17 00:00:00 2001 From: Oleg Zhurakivskyy Date: Wed, 27 May 2020 16:16:01 +0300 Subject: [PATCH] net: tcp2: Refactor net_tcp_connect() In order to improve readability, refactor and simplify the control flow in net_tcp_connect(). Signed-off-by: Oleg Zhurakivskyy --- subsys/net/ip/tcp2.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/subsys/net/ip/tcp2.c b/subsys/net/ip/tcp2.c index cf6ad3dce76..8d3d52d2f91 100644 --- a/subsys/net/ip/tcp2.c +++ b/subsys/net/ip/tcp2.c @@ -1374,7 +1374,7 @@ int net_tcp_connect(struct net_context *context, void *user_data) { struct tcp *conn; - int ret; + int ret = 0; ARG_UNUSED(timeout); @@ -1434,7 +1434,7 @@ int net_tcp_connect(struct net_context *context, break; default: - return -EPROTONOSUPPORT; + ret = -EPROTONOSUPPORT; } NET_DBG("conn: %p src: %s, dst: %s", conn, @@ -1452,7 +1452,7 @@ int net_tcp_connect(struct net_context *context, tcp_recv, context, &context->conn_handler); if (ret < 0) { - return ret; + goto out; } /* Input of a (nonexistent) packet with no flags set will cause @@ -1460,7 +1460,10 @@ int net_tcp_connect(struct net_context *context, */ tcp_in(conn, NULL); - return 0; + out: + NET_DBG("conn: %p, ret=%d", conn, ret); + + return ret; } int net_tcp_accept(struct net_context *context, net_tcp_accept_cb_t cb,