comparison libfdcore/tcp.c @ 1198:8c4dd4b693c6

Some cleanups in the traces
author Sebastien Decugis <sdecugis@freediameter.net>
date Thu, 13 Jun 2013 17:30:14 +0800
parents 1af09cc156d6
children
comparison
equal deleted inserted replaced
1197:823829bf1037 1198:8c4dd4b693c6
121 /* Create a client socket and connect to remote server */ 121 /* Create a client socket and connect to remote server */
122 int fd_tcp_client( int *sock, sSA * sa, socklen_t salen ) 122 int fd_tcp_client( int *sock, sSA * sa, socklen_t salen )
123 { 123 {
124 int ret = 0; 124 int ret = 0;
125 int s; 125 int s;
126 char * buf = NULL; size_t len = 0;
127 126
128 TRACE_ENTRY("%p %p %d", sock, sa, salen); 127 TRACE_ENTRY("%p %p %d", sock, sa, salen);
129 CHECK_PARAMS( sock && (*sock <= 0) && sa && salen ); 128 CHECK_PARAMS( sock && (*sock <= 0) && sa && salen );
130 129
131 /* Create the socket */ 130 /* Create the socket */
135 CHECK_FCT( fd_tcp_setsockopt(sa->sa_family, s) ); 134 CHECK_FCT( fd_tcp_setsockopt(sa->sa_family, s) );
136 135
137 /* Cleanup if we are cancelled */ 136 /* Cleanup if we are cancelled */
138 pthread_cleanup_push(fd_cleanup_socket, &s); 137 pthread_cleanup_push(fd_cleanup_socket, &s);
139 138
140 LOG_D( "Attempting TCP connection to %s...", fd_sa_dump(&buf, &len, NULL, sa, NI_NUMERICHOST | NI_NUMERICSERV)?:"<error>" );
141 free(buf);
142
143 /* Try connecting to the remote address */ 139 /* Try connecting to the remote address */
144 ret = connect(s, sa, salen); 140 ret = connect(s, sa, salen);
145 141
146 pthread_cleanup_pop(0); 142 pthread_cleanup_pop(0);
147 143
148 if (ret < 0) { 144 if (ret < 0) {
149 int lvl; 145 ret = errno;
150 switch (ret = errno) { 146 LOG_A( "connect returned an error: %s", strerror(ret));
151 case ECONNREFUSED:
152
153 /* "Normal" errors */
154 lvl = FULL;
155 break;
156 default:
157 lvl = INFO;
158 }
159 /* Some errors are expected, we log at different level */
160 TRACE_DEBUG( lvl, "connect returned an error: %s", strerror(ret));
161 CHECK_SYS_DO( close(s), /* continue */ ); 147 CHECK_SYS_DO( close(s), /* continue */ );
162 *sock = -1; 148 *sock = -1;
163 return ret; 149 return ret;
164 } 150 }
165 151
"Welcome to our mercurial repository"