comparison dbutil.c @ 70:b0316ce64e4b

Merging in the changes from 0.41-0.43 main Dropbear tree
author Matt Johnston <matt@ucc.asn.au>
date Thu, 12 Aug 2004 16:41:58 +0000
parents eee77ac31ccc
children 0bf5cebe622c
comparison
equal deleted inserted replaced
69:59d16db56e9f 70:b0316ce64e4b
119 * failure, if errstring wasn't NULL, it'll be a newly malloced error 119 * failure, if errstring wasn't NULL, it'll be a newly malloced error
120 * string.*/ 120 * string.*/
121 int dropbear_listen(const char* address, const char* port, 121 int dropbear_listen(const char* address, const char* port,
122 int *socks, unsigned int sockcount, char **errstring, int *maxfd) { 122 int *socks, unsigned int sockcount, char **errstring, int *maxfd) {
123 123
124 struct addrinfo hints, *res, *res0; 124 struct addrinfo hints, *res = NULL, *res0 = NULL;
125 int err; 125 int err;
126 unsigned int nsock; 126 unsigned int nsock;
127 struct linger linger; 127 struct linger linger;
128 int val; 128 int val;
129 int sock; 129 int sock;
271 continue; 271 continue;
272 } 272 }
273 } 273 }
274 274
275 if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) { 275 if (connect(sock, res->ai_addr, res->ai_addrlen) < 0) {
276 if (errno == EINPROGRESS) { 276 if (errno == EINPROGRESS && nonblocking) {
277 TRACE(("Connect in progress")); 277 TRACE(("Connect in progress"));
278 break; 278 break;
279 } else { 279 } else {
280 err = errno; 280 err = errno;
281 close(sock); 281 close(sock);
285 } 285 }
286 286
287 break; /* Success */ 287 break; /* Success */
288 } 288 }
289 289
290 if (sock < 0) { 290 if (sock < 0 && !(errno == EINPROGRESS && nonblocking)) {
291 /* Failed */ 291 /* Failed */
292 if (errstring != NULL && *errstring == NULL) { 292 if (errstring != NULL && *errstring == NULL) {
293 int len; 293 int len;
294 len = 20 + strlen(strerror(err)); 294 len = 20 + strlen(strerror(err));
295 *errstring = (char*)m_malloc(len); 295 *errstring = (char*)m_malloc(len);