mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/io/wait/wait.c: wrong backport from trunk. fixed: [ruby-dev:26562]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@8790 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
861c5e26d3
commit
6b4ee352fb
2 changed files with 24 additions and 12 deletions
|
@ -17,14 +17,21 @@
|
|||
#include <sys/types.h>
|
||||
#if defined(FIONREAD_HEADER)
|
||||
#include FIONREAD_HEADER
|
||||
#elif defined(HAVE_RB_W32_IOCTLSOCKET)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RB_W32_IOCTLSOCKET
|
||||
#define ioctl ioctlsocket
|
||||
#define ioctl_arg u_long
|
||||
#define ioctl_arg2num(i) ULONG2NUM(i)
|
||||
#else
|
||||
#define ioctl_arg int
|
||||
#define ioctl_arg2num(i) INT2NUM(i)
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RB_W32_IS_SOCKET
|
||||
#define FIONREAD_POSSIBLE_P(fd) rb_w32_is_socket(fptr->fd)
|
||||
#define FIONREAD_POSSIBLE_P(fd) rb_w32_is_socket(fd)
|
||||
#else
|
||||
#define FIONREAD_POSSIBLE_P(fd) Qtrue
|
||||
#define FIONREAD_POSSIBLE_P(fd) ((fd),Qtrue)
|
||||
#endif
|
||||
|
||||
static VALUE io_ready_p _((VALUE io));
|
||||
|
@ -51,16 +58,16 @@ io_ready_p(io)
|
|||
{
|
||||
OpenFile *fptr;
|
||||
FILE *fp;
|
||||
int n;
|
||||
ioctl_arg n;
|
||||
|
||||
GetOpenFile(io, fptr);
|
||||
rb_io_check_readable(fptr);
|
||||
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
|
||||
if (!FIONREAD_POSSIBLE_P(fileno(fptr->f))) return Qfalse;
|
||||
fp = fptr->f;
|
||||
if (feof(fp)) return Qfalse;
|
||||
if (rb_read_pending(fp)) return Qtrue;
|
||||
if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
|
||||
if (n > 0) return INT2NUM(n);
|
||||
if (n > 0) return ioctl_arg2num(n);
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
|
@ -80,7 +87,8 @@ io_wait(argc, argv, io)
|
|||
OpenFile *fptr;
|
||||
fd_set rd;
|
||||
FILE *fp;
|
||||
int fd, n;
|
||||
int fd;
|
||||
ioctl_arg n;
|
||||
VALUE timeout;
|
||||
struct timeval *tp, timerec;
|
||||
|
||||
|
@ -104,7 +112,7 @@ io_wait(argc, argv, io)
|
|||
if (rb_thread_select(fd + 1, &rd, NULL, NULL, tp) < 0)
|
||||
rb_sys_fail(0);
|
||||
rb_io_check_closed(fptr);
|
||||
if (!FIONREAD_POSSIBLE_P(fptr->fd)) return Qfalse;
|
||||
if (!FIONREAD_POSSIBLE_P(fileno(fptr->f))) return Qfalse;
|
||||
if (ioctl(fileno(fp), FIONREAD, &n)) rb_sys_fail(0);
|
||||
if (n > 0) return io;
|
||||
return Qnil;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue