File 0010-select_internal-add-additional-argument-for-poll-err.patch of Package ruby2.5
From 0684ba7956a8afc7bbc5c96949228866d6d57995 Mon Sep 17 00:00:00 2001
From: Michal Suchanek <msuchanek@suse.de>
Date: Mon, 3 Feb 2020 19:26:58 +0100
Subject: [PATCH 10/19] select_internal: add additional argument for poll()
error fd list
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
---
io.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 49 insertions(+), 8 deletions(-)
diff --git a/io.c b/io.c
index f514f7822541..4b0d9d5510fd 100644
--- a/io.c
+++ b/io.c
@@ -8906,7 +8906,7 @@ rb_f_backquote(VALUE obj, VALUE str)
#endif
static VALUE
-select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fdset_t *fds)
+select_internal(VALUE read, VALUE write, VALUE except, VALUE error, struct timeval *tp, rb_fdset_t *fds)
{
VALUE res, list;
rb_fdset_t *rp, *wp, *ep, *erp;
@@ -8923,7 +8923,7 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
rb_fd_set(fptr->fd, &fds[0]);
if (READ_DATA_PENDING(fptr) || READ_CHAR_PENDING(fptr)) { /* check for buffered data */
pending++;
- rb_fd_set(fptr->fd, &fds[3]);
+ rb_fd_set(fptr->fd, &fds[4]);
}
if (max < fptr->fd) max = fptr->fd;
}
@@ -8969,7 +8969,25 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
ep = 0;
}
- erp = 0;
+ if (!NIL_P(error)) {
+ Check_Type(error, T_ARRAY);
+ for (i=0; i<RARRAY_LEN(error); i++) {
+ VALUE io = rb_io_get_io(RARRAY_AREF(error, i));
+ VALUE write_io = GetWriteIO(io);
+ GetOpenFile(io, fptr);
+ rb_fd_set(fptr->fd, &fds[3]);
+ if (max < fptr->fd) max = fptr->fd;
+ if (io != write_io) {
+ GetOpenFile(write_io, fptr);
+ rb_fd_set(fptr->fd, &fds[3]);
+ if (max < fptr->fd) max = fptr->fd;
+ }
+ }
+ erp = &fds[3];
+ }
+ else {
+ erp = 0;
+ }
max++;
@@ -8979,10 +8997,11 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
}
if (!pending && n == 0) return Qnil; /* returns nil on timeout */
- res = rb_ary_new2(3);
+ res = rb_ary_new2(4);
rb_ary_push(res, rp?rb_ary_new():rb_ary_new2(0));
rb_ary_push(res, wp?rb_ary_new():rb_ary_new2(0));
rb_ary_push(res, ep?rb_ary_new():rb_ary_new2(0));
+ rb_ary_push(res, erp?rb_ary_new():rb_ary_new2(0));
if (rp) {
list = RARRAY_AREF(res, 0);
@@ -8991,7 +9010,7 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
VALUE io = rb_io_get_io(obj);
GetOpenFile(io, fptr);
if (rb_fd_isset(fptr->fd, &fds[0]) ||
- rb_fd_isset(fptr->fd, &fds[3])) {
+ rb_fd_isset(fptr->fd, &fds[4])) {
rb_ary_push(list, obj);
}
}
@@ -9029,6 +9048,25 @@ select_internal(VALUE read, VALUE write, VALUE except, struct timeval *tp, rb_fd
}
}
+ if (erp) {
+ list = RARRAY_AREF(res, 3);
+ for (i=0; i< RARRAY_LEN(error); i++) {
+ VALUE obj = rb_ary_entry(error, i);
+ VALUE io = rb_io_get_io(obj);
+ VALUE write_io = GetWriteIO(io);
+ GetOpenFile(io, fptr);
+ if (rb_fd_isset(fptr->fd, &fds[3])) {
+ rb_ary_push(list, obj);
+ }
+ else if (io != write_io) {
+ GetOpenFile(write_io, fptr);
+ if (rb_fd_isset(fptr->fd, &fds[3])) {
+ rb_ary_push(list, obj);
+ }
+ }
+ }
+ }
+
return res; /* returns an empty array on interrupt */
}
@@ -9043,7 +9081,7 @@ select_call(VALUE arg)
{
struct select_args *p = (struct select_args *)arg;
- return select_internal(p->read, p->write, p->except, p->timeout, p->fdsets);
+ return select_internal(p->read, p->write, p->except, p->error, p->timeout, p->fdsets);
}
static VALUE
@@ -9375,7 +9413,7 @@ rb_io_advise(int argc, VALUE *argv, VALUE io)
static VALUE
rb_f_select(int argc, VALUE *argv, VALUE obj)
{
- VALUE timeout;
+ VALUE timeout, rv;
struct select_args args;
struct timeval timerec;
int i;
@@ -9393,7 +9431,10 @@ rb_f_select(int argc, VALUE *argv, VALUE obj)
for (i = 0; i < numberof(args.fdsets); ++i)
rb_fd_init(&args.fdsets[i]);
- return rb_ensure(select_call, (VALUE)&args, select_end, (VALUE)&args);
+ rv = rb_ensure(select_call, (VALUE)&args, select_end, (VALUE)&args);
+ if (RB_TYPE_P(rv, T_ARRAY))
+ rb_ary_pop(rv);
+ return rv;
}
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
--
2.26.2