Mercurial > vim
comparison src/channel.c @ 7982:5c30ba57aaea v7.4.1286
commit https://github.com/vim/vim/commit/7a84dbe6be0ef0e1ffbb7148cfe4ab50b9ba8f41
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 7 21:29:00 2016 +0100
patch 7.4.1286
Problem: ch_open() with a timeout doesn't work correctly.
Solution: Change how select() is used. Don't give an error on timeout.
Add a test for ch_open() failing.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 07 Feb 2016 21:30:05 +0100 |
parents | 45ea5ebf3a98 |
children | 8e0d4cd8157a |
comparison
equal
deleted
inserted
replaced
7981:a5f1bdd2007b | 7982:5c30ba57aaea |
---|---|
429 sock_close(sd); | 429 sock_close(sd); |
430 return -1; | 430 return -1; |
431 } | 431 } |
432 } | 432 } |
433 | 433 |
434 if (waittime >= 0) | 434 if (waittime >= 0 && ret < 0) |
435 { | 435 { |
436 struct timeval tv; | 436 struct timeval tv; |
437 fd_set rfds, wfds; | 437 fd_set wfds; |
438 | 438 |
439 FD_ZERO(&rfds); | |
440 FD_ZERO(&wfds); | 439 FD_ZERO(&wfds); |
441 FD_SET(sd, &rfds); | |
442 FD_SET(sd, &wfds); | 440 FD_SET(sd, &wfds); |
443 tv.tv_sec = waittime / 1000; | 441 tv.tv_sec = waittime / 1000; |
444 tv.tv_usec = (waittime % 1000) * 1000; | 442 tv.tv_usec = (waittime % 1000) * 1000; |
445 ret = select((int)sd+1, &rfds, &wfds, NULL, &tv); | 443 ret = select((int)sd + 1, NULL, &wfds, NULL, &tv); |
446 if (ret < 0) | 444 if (ret < 0) |
447 { | 445 { |
448 SOCK_ERRNO; | 446 SOCK_ERRNO; |
449 CHERROR("channel_open: Connect failed with errno %d\n", errno); | 447 CHERROR("channel_open: Connect failed with errno %d\n", errno); |
450 CHERROR("Cannot connect to port\n", ""); | 448 CHERROR("Cannot connect to port\n", ""); |
451 PERROR(_("E902: Cannot connect to port")); | 449 PERROR(_("E902: Cannot connect to port")); |
452 sock_close(sd); | 450 sock_close(sd); |
453 return -1; | 451 return -1; |
454 } | 452 } |
455 if (!FD_ISSET(sd, &rfds) && !FD_ISSET(sd, &wfds)) | 453 if (!FD_ISSET(sd, &wfds)) |
456 { | 454 { |
457 errno = ECONNREFUSED; | 455 /* don't give an error, we just timed out. */ |
458 CHERROR("Cannot connect to port\n", ""); | |
459 PERROR(_("E902: Cannot connect to port")); | |
460 sock_close(sd); | 456 sock_close(sd); |
461 return -1; | 457 return -1; |
462 } | 458 } |
463 | 459 } |
460 | |
461 if (waittime >= 0) | |
462 { | |
464 #ifdef _WIN32 | 463 #ifdef _WIN32 |
465 val = 0; | 464 val = 0; |
466 ioctlsocket(sd, FIONBIO, &val); | 465 ioctlsocket(sd, FIONBIO, &val); |
467 #else | 466 #else |
468 (void)fcntl(sd, F_SETFL, 0); | 467 (void)fcntl(sd, F_SETFL, 0); |