Skip to content

Commit

Permalink
code cleanup: we prefer 'CURLcode result'
Browse files Browse the repository at this point in the history
... for the local variable name in functions holding the return
code. Using the same name universally makes code easier to read and
follow.

Also, unify code for checking for CURLcode errors with:

 if(result) or if(!result)

instead of

 if(result == CURLE_OK), if(CURLE_OK == result) or if(result != CURLE_OK)
  • Loading branch information
bagder committed Oct 24, 2014
1 parent 1752e9c commit 0eb3d15
Show file tree
Hide file tree
Showing 27 changed files with 413 additions and 423 deletions.
4 changes: 2 additions & 2 deletions lib/conncache.c
Expand Up @@ -131,7 +131,7 @@ CURLcode Curl_conncache_add_conn(struct conncache *connc,
conn->host.name);
if(!bundle) {
result = Curl_bundle_create(data, &new_bundle);
if(result != CURLE_OK)
if(result)
return result;

if(!conncache_add_bundle(data->state.conn_cache,
Expand All @@ -143,7 +143,7 @@ CURLcode Curl_conncache_add_conn(struct conncache *connc,
}

result = Curl_bundle_add_conn(bundle, conn);
if(result != CURLE_OK) {
if(result) {
if(new_bundle)
conncache_remove_bundle(data->state.conn_cache, new_bundle);
return result;
Expand Down
41 changes: 20 additions & 21 deletions lib/connect.c
Expand Up @@ -717,11 +717,11 @@ CURLcode Curl_is_connected(struct connectdata *conn,
bool *connected)
{
struct SessionHandle *data = conn->data;
CURLcode code = CURLE_OK;
CURLcode result = CURLE_OK;
long allow;
int error = 0;
struct timeval now;
int result;
int rc;
int i;

DEBUGASSERT(sockindex >= FIRSTSOCKET && sockindex <= SECONDARYSOCKET);
Expand Down Expand Up @@ -757,9 +757,9 @@ CURLcode Curl_is_connected(struct connectdata *conn,
#endif

/* check socket for connect */
result = Curl_socket_ready(CURL_SOCKET_BAD, conn->tempsock[i], 0);
rc = Curl_socket_ready(CURL_SOCKET_BAD, conn->tempsock[i], 0);

if(result == 0) { /* no connection yet */
if(rc == 0) { /* no connection yet */
if(curlx_tvdiff(now, conn->connecttime) >= conn->timeoutms_per_addr) {
infof(data, "After %ldms connect time, move on!\n",
conn->timeoutms_per_addr);
Expand All @@ -772,7 +772,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
trynextip(conn, sockindex, 1);
}
}
else if(result == CURL_CSELECT_OUT) {
else if(rc == CURL_CSELECT_OUT) {
if(verifyconnect(conn->tempsock[i], &error)) {
/* we are connected with TCP, awesome! */
int other = i ^ 1;
Expand All @@ -789,9 +789,9 @@ CURLcode Curl_is_connected(struct connectdata *conn,
}

/* see if we need to do any proxy magic first once we connected */
code = Curl_connected_proxy(conn, sockindex);
if(code)
return code;
result = Curl_connected_proxy(conn, sockindex);
if(result)
return result;

conn->bits.tcpconnect[sockindex] = TRUE;

Expand All @@ -806,7 +806,7 @@ CURLcode Curl_is_connected(struct connectdata *conn,
else
infof(data, "Connection failed\n");
}
else if(result & CURL_CSELECT_ERR)
else if(rc & CURL_CSELECT_ERR)
(void)verifyconnect(conn->tempsock[i], &error);

/*
Expand All @@ -825,29 +825,28 @@ CURLcode Curl_is_connected(struct connectdata *conn,
conn->timeoutms_per_addr = conn->tempaddr[i]->ai_next == NULL ?
allow : allow / 2;

code = trynextip(conn, sockindex, i);
result = trynextip(conn, sockindex, i);
}
}
}

if(code) {
if(result) {
/* no more addresses to try */

/* if the first address family runs out of addresses to try before
the happy eyeball timeout, go ahead and try the next family now */
if(conn->tempaddr[1] == NULL) {
int rc;
rc = trynextip(conn, sockindex, 1);
if(rc == CURLE_OK)
return CURLE_OK;
result = trynextip(conn, sockindex, 1);
if(!result)
return result;
}

failf(data, "Failed to connect to %s port %ld: %s",
conn->bits.proxy?conn->proxy.name:conn->host.name,
conn->port, Curl_strerror(conn, error));
}

return code;
return result;
}

static void tcpnodelay(struct connectdata *conn,
Expand Down Expand Up @@ -1117,7 +1116,7 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */
{
struct SessionHandle *data = conn->data;
struct timeval before = Curl_tvnow();
CURLcode res = CURLE_COULDNT_CONNECT;
CURLcode result = CURLE_COULDNT_CONNECT;

long timeout_ms = Curl_timeleft(data, &before, TRUE);

Expand All @@ -1140,14 +1139,14 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */

/* start connecting to first IP */
while(conn->tempaddr[0]) {
res = singleipconnect(conn, conn->tempaddr[0], &(conn->tempsock[0]));
if(res == CURLE_OK)
break;
result = singleipconnect(conn, conn->tempaddr[0], &(conn->tempsock[0]));
if(!result)
break;
conn->tempaddr[0] = conn->tempaddr[0]->ai_next;
}

if(conn->tempsock[0] == CURL_SOCKET_BAD)
return res;
return result;

data->info.numconnects++; /* to track the number of connections made */

Expand Down
4 changes: 2 additions & 2 deletions lib/curl_addrinfo.c
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2012, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2014, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -354,7 +354,7 @@ Curl_he2ai(const struct hostent *he, int port)
prevai = ai;
}

if(result != CURLE_OK) {
if(result) {
Curl_freeaddrinfo(firstai);
firstai = NULL;
}
Expand Down

0 comments on commit 0eb3d15

Please sign in to comment.