Commit 15983d10 authored by Sebastien Decugis's avatar Sebastien Decugis
Browse files

Cleanup verbosity and fix unintialized variable

parent a6dbe7b5
......@@ -286,14 +286,31 @@ error:
/* Client side: connect to a remote server -- cancelable */
struct cnxctx * fd_cnx_cli_connect_tcp(sSA * sa /* contains the port already */, socklen_t addrlen)
{
int sock;
int sock = 0;
struct cnxctx * cnx = NULL;
TRACE_ENTRY("%p %d", sa, addrlen);
CHECK_PARAMS_DO( sa && addrlen, return NULL );
/* Create the socket and connect, which can take some time and/or fail */
CHECK_FCT_DO( fd_tcp_client( &sock, sa, addrlen ), return NULL );
{
int ret = fd_tcp_client( &sock, sa, addrlen );
if (ret != 0) {
int lvl;
switch (ret) {
case ECONNREFUSED:
/* "Normal" errors */
lvl = FULL;
break;
default:
lvl = INFO;
}
/* Some errors are expected, we log at different level */
TRACE_DEBUG( lvl, "fd_tcp_client returned an error: %s", strerror(ret));
return NULL;
}
}
if (TRACE_BOOL(INFO)) {
fd_log_debug("Connection established to server '");
......@@ -343,14 +360,31 @@ struct cnxctx * fd_cnx_cli_connect_sctp(int no_ip6, uint16_t port, struct fd_lis
ASSERT(0);
CHECK_FCT_DO( ENOTSUP, return NULL);
#else /* DISABLE_SCTP */
int sock;
int sock = 0;
struct cnxctx * cnx = NULL;
sSS primary;
TRACE_ENTRY("%p", list);
CHECK_PARAMS_DO( list && !FD_IS_LIST_EMPTY(list), return NULL );
CHECK_FCT_DO( fd_sctp_client( &sock, no_ip6, port, list ), return NULL );
{
int ret = fd_sctp_client( &sock, no_ip6, port, list );
if (ret != 0) {
int lvl;
switch (ret) {
case ECONNREFUSED:
/* "Normal" errors */
lvl = FULL;
break;
default:
lvl = INFO;
}
/* Some errors are expected, we log at different level */
TRACE_DEBUG( lvl, "fd_sctp_client returned an error: %s", strerror(ret));
return NULL;
}
}
/* Once the socket is created successfuly, prepare the remaining of the cnx */
CHECK_MALLOC_DO( cnx = fd_cnx_init(1), { shutdown(sock, SHUT_RDWR); close(sock); return NULL; } );
......
......@@ -840,11 +840,27 @@ int fd_sctp_client( int *sock, int no_ip6, uint16_t port, struct fd_list * list
}
#ifdef SCTP_CONNECTX_4_ARGS
CHECK_SYS_DO( sctp_connectx(*sock, sar.sa, count, NULL), { ret = errno; goto fail; } );
ret = sctp_connectx(*sock, sar.sa, count, NULL);
#else /* SCTP_CONNECTX_4_ARGS */
CHECK_SYS_DO( sctp_connectx(*sock, sar.sa, count), { ret = errno; goto fail; } );
ret = sctp_connectx(*sock, sar.sa, count);
#endif /* SCTP_CONNECTX_4_ARGS */
if (ret < 0) {
int lvl;
switch (ret = errno) {
case ECONNREFUSED:
/* "Normal" errors */
lvl = FULL;
break;
default:
lvl = INFO;
}
/* Some errors are expected, we log at different level */
TRACE_DEBUG( lvl, "sctp_connectx returned an error: %s", strerror(ret));
goto fail;
}
free(sar.buf); sar.buf = NULL;
/* Set the remaining sockopts */
......
......@@ -237,7 +237,7 @@ struct sr_store {
struct fd_list list; /* list of sr_data, ordered by key.size then key.data */
pthread_rwlock_t lock;
struct cnxctx *parent;
/* Add another list to chain in a global list to implement a garbage collector on sessions -- TODO */
/* Add another list to chain in a global list to implement a garbage collector on sessions -- TODO if needed */
};
/* Saved master session data for resuming sessions */
......
......@@ -273,7 +273,7 @@ int fd_servers_start()
if (empty_conf_ep) {
(void) fd_cnx_getendpoints(s->conn, &fd_g_config->cnf_endpoints, NULL);
if (TRACE_BOOL(FULL)){
fd_log_debug("Server bound on the following addresses :\n");
fd_log_debug(" Local server address(es) :\n");
fd_ep_dump( 5, &fd_g_config->cnf_endpoints );
}
}
......
......@@ -135,10 +135,29 @@ int fd_tcp_client( int *sock, sSA * sa, socklen_t salen )
TRACE_DEBUG_sSA(FULL, "Attempting TCP connection with peer: ", sa, NI_NUMERICHOST | NI_NUMERICSERV, "..." );
/* Try connecting to the remote address */
CHECK_SYS_DO( connect(s, sa, salen), { ret = errno; close(s); s = -1; } );
ret = connect(s, sa, salen);
/* Done! */
pthread_cleanup_pop(0);
if (ret < 0) {
int lvl;
switch (ret = errno) {
case ECONNREFUSED:
/* "Normal" errors */
lvl = FULL;
break;
default:
lvl = INFO;
}
/* Some errors are expected, we log at different level */
TRACE_DEBUG( lvl, "connect returned an error: %s", strerror(ret));
CHECK_SYS_DO( close(s), /* continue */ );
*sock = -1;
return ret;
}
/* Done! */
*sock = s;
return ret;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment