1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/socket/socket.c (ruby_connect): many systems seem to have

a problem in select() after EINPROGRESS.  [ruby-list:38080]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@4415 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2003-08-20 07:44:53 +00:00
parent 360b0a015a
commit b1f0115394
2 changed files with 28 additions and 5 deletions

View file

@ -1,3 +1,8 @@
Wed Aug 20 16:44:49 2003 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ext/socket/socket.c (ruby_connect): many systems seem to have
a problem in select() after EINPROGRESS. [ruby-list:38080]
Wed Aug 20 01:31:17 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net> Wed Aug 20 01:31:17 2003 why the lucky stiff <ruby-cvs@whytheluckystiff.net>
* ext/syck/syck.h: Parser definition problems on HP-UX. [ruby-talk:79389] * ext/syck/syck.h: Parser definition problems on HP-UX. [ruby-talk:79389]

View file

@ -731,6 +731,14 @@ thread_write_select(fd)
#ifdef __APPLE__ #ifdef __APPLE__
#define WAIT_IN_PROGRESS 10 #define WAIT_IN_PROGRESS 10
#endif #endif
#ifdef __linux__
/* returns correct error */
#define WAIT_IN_PROGRESS 0
#endif
#ifndef WAIT_IN_PROGRESS
/* BSD origin code apparently has a problem */
#define WAIT_IN_PROGRESS 1
#endif
static int static int
ruby_connect(fd, sockaddr, len, socks) ruby_connect(fd, sockaddr, len, socks)
@ -741,8 +749,9 @@ ruby_connect(fd, sockaddr, len, socks)
{ {
int status; int status;
int mode; int mode;
#ifdef WAIT_IN_PROGRESS #if WAIT_IN_PROGRESS > 0
int wait_in_progress = -1; int wait_in_progress = -1;
int sockerr, sockerrlen;
#endif #endif
#if defined(HAVE_FCNTL) #if defined(HAVE_FCNTL)
@ -779,25 +788,34 @@ ruby_connect(fd, sockaddr, len, socks)
#ifdef EINPROGRESS #ifdef EINPROGRESS
case EINPROGRESS: case EINPROGRESS:
#endif #endif
#if WAIT_IN_PROGRESS > 0
sockerrlen = sizeof(sockerr);
status = getsockopt(fd, SOL_SOCKET, SO_ERROR, &sockerr, &sockerrlen);
if (status) break;
if (sockerr) {
status = -1;
errno = sockerr;
break;
}
#endif
#ifdef EALREADY #ifdef EALREADY
case EALREADY: case EALREADY:
#endif #endif
#ifdef WAIT_IN_PROGRESS #if WAIT_IN_PROGRESS > 0
wait_in_progress = WAIT_IN_PROGRESS; wait_in_progress = WAIT_IN_PROGRESS;
#endif #endif
thread_write_select(fd); thread_write_select(fd);
continue; continue;
#ifdef WAIT_IN_PROGRESS #if WAIT_IN_PROGRESS > 0
case EINVAL: case EINVAL:
if (wait_in_progress-- > 0) { if (wait_in_progress-- > 0) {
int sockerr, sockerrlen = sizeof(sockerr);
/* /*
* connect() after EINPROGRESS returns EINVAL on * connect() after EINPROGRESS returns EINVAL on
* some platforms, need to check true error * some platforms, need to check true error
* status. * status.
*/ */
sockerrlen = sizeof(sockerr);
status = getsockopt(fd, SOL_SOCKET, SO_ERROR, &sockerr, &sockerrlen); status = getsockopt(fd, SOL_SOCKET, SO_ERROR, &sockerr, &sockerrlen);
if (!status && !sockerr) { if (!status && !sockerr) {
struct timeval tv = {0, 100000}; struct timeval tv = {0, 100000};