зеркало из https://github.com/github/ruby.git
* {bcc32,win32,wince}/Makefile.sub (config.h): add fcntl.
* win32/win32.[ch] (fcntl): ditto. * win32/win32.c (rb_w32_connect): support nonblocking mode. * ext/socket/socket.c (wait_connectable, ruby_connect): support nonblocking connect on various platforms. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6863 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
70f8c054b2
Коммит
f4d60b5f63
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
Tue Sep 7 12:48:22 2004 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* {bcc32,win32,wince}/Makefile.sub (config.h): add fcntl.
|
||||
|
||||
* win32/win32.[ch] (fcntl): ditto.
|
||||
|
||||
* win32/win32.c (rb_w32_connect): support nonblocking mode.
|
||||
|
||||
* ext/socket/socket.c (wait_connectable, ruby_connect): support
|
||||
nonblocking connect on various platforms.
|
||||
|
||||
Mon Sep 6 10:57:40 2004 Hirokazu Yamamoto <ocean@m2.ccsnet.ne.jp>
|
||||
|
||||
* ext/tk/lib/tk/menu.rb(TkOptionMenubutton#insert): call correct method
|
||||
|
|
|
@ -252,6 +252,7 @@ config.h:
|
|||
\#define HAVE_GETCWD 1
|
||||
\#define HAVE_CHSIZE 1
|
||||
\#define HAVE_TIMES 1
|
||||
\#define HAVE_FCNTL 1
|
||||
\#define HAVE_LINK 1
|
||||
\#define HAVE_TELLDIR 1
|
||||
\#define HAVE_SEEKDIR 1
|
||||
|
|
|
@ -52,10 +52,16 @@
|
|||
#ifdef HAVE_SYS_SELECT_H
|
||||
#include <sys/select.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TYPES_H
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
#include <sys/time.h>
|
||||
#endif
|
||||
#ifdef HAVE_FCNTL_H
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
#endif
|
||||
#ifndef EWOULDBLOCK
|
||||
#define EWOULDBLOCK EAGAIN
|
||||
#endif
|
||||
|
@ -794,15 +800,36 @@ ruby_socket(domain, type, proto)
|
|||
return fd;
|
||||
}
|
||||
|
||||
static void
|
||||
thread_write_select(fd)
|
||||
static int
|
||||
wait_connectable(fd)
|
||||
int fd;
|
||||
{
|
||||
fd_set fds;
|
||||
int sockerr, sockerrlen;
|
||||
fd_set fds_w;
|
||||
fd_set fds_e;
|
||||
|
||||
FD_ZERO(&fds);
|
||||
FD_SET(fd, &fds);
|
||||
rb_thread_select(fd+1, 0, &fds, 0, 0);
|
||||
for (;;) {
|
||||
FD_ZERO(&fds_w);
|
||||
FD_ZERO(&fds_e);
|
||||
|
||||
FD_SET(fd, &fds_w);
|
||||
FD_SET(fd, &fds_e);
|
||||
|
||||
rb_thread_select(fd+1, 0, &fds_w, &fds_e, 0);
|
||||
|
||||
if (FD_ISSET(fd, &fds_w)) {
|
||||
return 0;
|
||||
}
|
||||
else if (FD_ISSET(fd, &fds_e)) {
|
||||
sockerrlen = sizeof(sockerr);
|
||||
if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void *)&sockerr,
|
||||
&sockerrlen))
|
||||
errno = sockerr;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
|
@ -835,7 +862,11 @@ ruby_connect(fd, sockaddr, len, socks)
|
|||
#endif
|
||||
|
||||
#if defined(HAVE_FCNTL)
|
||||
# if defined(F_GETFL)
|
||||
mode = fcntl(fd, F_GETFL, 0);
|
||||
# else
|
||||
mode = 0;
|
||||
# endif
|
||||
|
||||
#ifdef O_NDELAY
|
||||
# define NONBLOCKING O_NDELAY
|
||||
|
@ -884,7 +915,11 @@ ruby_connect(fd, sockaddr, len, socks)
|
|||
#if WAIT_IN_PROGRESS > 0
|
||||
wait_in_progress = WAIT_IN_PROGRESS;
|
||||
#endif
|
||||
thread_write_select(fd);
|
||||
status = wait_connectable(fd);
|
||||
if (status) {
|
||||
break;
|
||||
}
|
||||
errno = 0;
|
||||
continue;
|
||||
|
||||
#if WAIT_IN_PROGRESS > 0
|
||||
|
|
|
@ -243,6 +243,7 @@ config.h:
|
|||
#define HAVE_GETCWD 1
|
||||
#define HAVE_CHSIZE 1
|
||||
#define HAVE_TIMES 1
|
||||
#define HAVE_FCNTL 1
|
||||
#define HAVE_LINK 1
|
||||
#define HAVE__SETJMP 1
|
||||
#define HAVE_TELLDIR 1
|
||||
|
|
|
@ -2047,8 +2047,16 @@ rb_w32_connect(int s, struct sockaddr *addr, int addrlen)
|
|||
}
|
||||
RUBY_CRITICAL({
|
||||
r = connect(TO_SOCKET(s), addr, addrlen);
|
||||
if (r == SOCKET_ERROR)
|
||||
errno = map_errno(WSAGetLastError());
|
||||
if (r == SOCKET_ERROR) {
|
||||
r = WSAGetLastError();
|
||||
if (r != WSAEWOULDBLOCK) {
|
||||
errno = map_errno(r);
|
||||
}
|
||||
else {
|
||||
errno = EINPROGRESS;
|
||||
r = -1;
|
||||
}
|
||||
}
|
||||
});
|
||||
return r;
|
||||
}
|
||||
|
@ -2411,6 +2419,43 @@ void setprotoent (int stayopen) {}
|
|||
|
||||
void setservent (int stayopen) {}
|
||||
|
||||
int
|
||||
fcntl(int fd, int cmd, ...)
|
||||
{
|
||||
SOCKET sock = TO_SOCKET(fd);
|
||||
va_list va;
|
||||
int arg;
|
||||
int ret;
|
||||
u_long ioctlArg;
|
||||
|
||||
if (!is_socket(sock)) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
if (cmd != F_SETFL) {
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
va_start(va, cmd);
|
||||
arg = va_arg(va, int);
|
||||
va_end(va);
|
||||
if (arg & O_NONBLOCK) {
|
||||
ioctlArg = 1;
|
||||
}
|
||||
else {
|
||||
ioctlArg = 0;
|
||||
}
|
||||
RUBY_CRITICAL({
|
||||
ret = ioctlsocket(sock, FIONBIO, &ioctlArg);
|
||||
if (ret == -1) {
|
||||
errno = map_errno(WSAGetLastError());
|
||||
}
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef WNOHANG
|
||||
#define WNOHANG -1
|
||||
#endif
|
||||
|
|
|
@ -183,6 +183,7 @@ extern char *rb_w32_join_argv(char *, char *const *);
|
|||
extern int rb_w32_spawn(int, const char *, const char*);
|
||||
extern int rb_w32_aspawn(int, const char *, char *const *);
|
||||
extern int kill(int, int);
|
||||
extern int fcntl(int, int, ...);
|
||||
extern pid_t rb_w32_getpid(void);
|
||||
|
||||
#ifdef __BORLANDC__
|
||||
|
@ -324,6 +325,9 @@ extern char *rb_w32_strerror(int);
|
|||
#define ESTALE WSAESTALE
|
||||
#define EREMOTE WSAEREMOTE
|
||||
|
||||
#define F_SETFL 1
|
||||
#define O_NONBLOCK 1
|
||||
|
||||
#ifdef accept
|
||||
#undef accept
|
||||
#endif
|
||||
|
|
|
@ -247,6 +247,7 @@ config.h:
|
|||
#define HAVE_GETCWD 1
|
||||
#define HAVE_CHSIZE 0
|
||||
#define HAVE_TIMES 1
|
||||
#define HAVE_FCNTL 1
|
||||
#define HAVE_TELLDIR 1
|
||||
#define HAVE_SEEKDIR 1
|
||||
#define HAVE_MKTIME 1
|
||||
|
|
Загрузка…
Ссылка в новой задаче