mirror of
https://github.com/vim/vim.git
synced 2025-09-25 03:54:15 -04:00
patch 7.4.1457
Problem: Opening a channel with select() is not done properly. Solution: Also used read-fds. Use getsockopt() to check for errors. (Ozaki Kiichi)
This commit is contained in:
@@ -28,6 +28,8 @@
|
|||||||
# define ECONNREFUSED WSAECONNREFUSED
|
# define ECONNREFUSED WSAECONNREFUSED
|
||||||
# undef EWOULDBLOCK
|
# undef EWOULDBLOCK
|
||||||
# define EWOULDBLOCK WSAEWOULDBLOCK
|
# define EWOULDBLOCK WSAEWOULDBLOCK
|
||||||
|
# undef EINPROGRESS
|
||||||
|
# define EINPROGRESS WSAEINPROGRESS
|
||||||
# ifdef EINTR
|
# ifdef EINTR
|
||||||
# undef EINTR
|
# undef EINTR
|
||||||
# endif
|
# endif
|
||||||
@@ -550,8 +552,6 @@ channel_open(
|
|||||||
#else
|
#else
|
||||||
int port = port_in;
|
int port = port_in;
|
||||||
struct timeval start_tv;
|
struct timeval start_tv;
|
||||||
int so_error;
|
|
||||||
socklen_t so_error_len = sizeof(so_error);
|
|
||||||
#endif
|
#endif
|
||||||
channel_T *channel;
|
channel_T *channel;
|
||||||
int ret;
|
int ret;
|
||||||
@@ -633,7 +633,6 @@ channel_open(
|
|||||||
{
|
{
|
||||||
if (errno != EWOULDBLOCK
|
if (errno != EWOULDBLOCK
|
||||||
&& errno != ECONNREFUSED
|
&& errno != ECONNREFUSED
|
||||||
|
|
||||||
#ifdef EINPROGRESS
|
#ifdef EINPROGRESS
|
||||||
&& errno != EINPROGRESS
|
&& errno != EINPROGRESS
|
||||||
#endif
|
#endif
|
||||||
@@ -653,14 +652,13 @@ channel_open(
|
|||||||
if (waittime >= 0 && ret < 0)
|
if (waittime >= 0 && ret < 0)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
|
fd_set rfds;
|
||||||
fd_set wfds;
|
fd_set wfds;
|
||||||
#if defined(__APPLE__) && __APPLE__ == 1
|
int so_error = 0;
|
||||||
# define PASS_RFDS
|
socklen_t so_error_len = sizeof(so_error);
|
||||||
fd_set rfds;
|
|
||||||
|
|
||||||
FD_ZERO(&rfds);
|
FD_ZERO(&rfds);
|
||||||
FD_SET(sd, &rfds);
|
FD_SET(sd, &rfds);
|
||||||
#endif
|
|
||||||
FD_ZERO(&wfds);
|
FD_ZERO(&wfds);
|
||||||
FD_SET(sd, &wfds);
|
FD_SET(sd, &wfds);
|
||||||
|
|
||||||
@@ -671,13 +669,7 @@ channel_open(
|
|||||||
#endif
|
#endif
|
||||||
ch_logn(channel,
|
ch_logn(channel,
|
||||||
"Waiting for connection (waittime %d msec)...", waittime);
|
"Waiting for connection (waittime %d msec)...", waittime);
|
||||||
ret = select((int)sd + 1,
|
ret = select((int)sd + 1, &rfds, &wfds, NULL, &tv);
|
||||||
#ifdef PASS_RFDS
|
|
||||||
&rfds,
|
|
||||||
#else
|
|
||||||
NULL,
|
|
||||||
#endif
|
|
||||||
&wfds, NULL, &tv);
|
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@@ -689,30 +681,39 @@ channel_open(
|
|||||||
channel_free(channel);
|
channel_free(channel);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#ifdef PASS_RFDS
|
|
||||||
if (ret == 0 && FD_ISSET(sd, &rfds) && FD_ISSET(sd, &wfds))
|
/* On Win32: select() is expected to work and wait for up to the
|
||||||
{
|
* waittime for the socket to be open.
|
||||||
/* For OS X, this implies error. See tcp(4). */
|
* On Linux-like systems: See socket(7) for the behavior
|
||||||
ch_error(channel, "channel_open: Connect failed");
|
|
||||||
EMSG(_(e_cannot_connect));
|
|
||||||
sock_close(sd);
|
|
||||||
channel_free(channel);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
#ifdef WIN32
|
|
||||||
/* On Win32 select() is expected to work and wait for up to the
|
|
||||||
* waittime for the socket to be open. */
|
|
||||||
if (!FD_ISSET(sd, &wfds) || ret == 0)
|
|
||||||
#else
|
|
||||||
/* See socket(7) for the behavior on Linux-like systems:
|
|
||||||
* After putting the socket in non-blocking mode, connect() will
|
* After putting the socket in non-blocking mode, connect() will
|
||||||
* return EINPROGRESS, select() will not wait (as if writing is
|
* return EINPROGRESS, select() will not wait (as if writing is
|
||||||
* possible), need to use getsockopt() to check if the socket is
|
* possible), need to use getsockopt() to check if the socket is
|
||||||
* actually open. */
|
* actually connect.
|
||||||
getsockopt(sd, SOL_SOCKET, SO_ERROR, &so_error, &so_error_len);
|
* We detect an failure to connect when both read and write fds
|
||||||
if (!FD_ISSET(sd, &wfds) || ret == 0 || so_error != 0)
|
* are set. Use getsockopt() to find out what kind of failure. */
|
||||||
|
if (FD_ISSET(sd, &rfds) && FD_ISSET(sd, &wfds))
|
||||||
|
{
|
||||||
|
ret = getsockopt(sd,
|
||||||
|
SOL_SOCKET, SO_ERROR, &so_error, &so_error_len);
|
||||||
|
if (ret < 0 || (so_error != 0
|
||||||
|
&& so_error != EWOULDBLOCK
|
||||||
|
&& so_error != ECONNREFUSED
|
||||||
|
#ifdef EINPROGRESS
|
||||||
|
&& so_error != EINPROGRESS
|
||||||
#endif
|
#endif
|
||||||
|
))
|
||||||
|
{
|
||||||
|
ch_errorn(channel,
|
||||||
|
"channel_open: Connect failed with errno %d",
|
||||||
|
so_error);
|
||||||
|
PERROR(_(e_cannot_connect));
|
||||||
|
sock_close(sd);
|
||||||
|
channel_free(channel);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!FD_ISSET(sd, &wfds) || so_error != 0)
|
||||||
{
|
{
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
struct timeval end_tv;
|
struct timeval end_tv;
|
||||||
|
@@ -743,6 +743,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1457,
|
||||||
/**/
|
/**/
|
||||||
1456,
|
1456,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user