[前][次][番号順一覧][スレッド一覧]

ruby-changes:69385

From: Nobuyoshi <ko1@a...>
Date: Sun, 24 Oct 2021 19:25:15 +0900 (JST)
Subject: [ruby-changes:69385] 3d7c92df08 (master): Extract io_again_p to check if EAGAIN or EWOULDBLOCK

https://git.ruby-lang.org/ruby.git/commit/?id=3d7c92df08

From 3d7c92df089226f3608757c45da1a4403b1dcee9 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sun, 24 Oct 2021 17:42:28 +0900
Subject: Extract io_again_p to check if EAGAIN or EWOULDBLOCK

---
 io.c | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/io.c b/io.c
index a340f5b150..32f3053616 100644
--- a/io.c
+++ b/io.c
@@ -302,6 +302,12 @@ rb_fix_detect_o_cloexec(int fd) https://github.com/ruby/ruby/blob/trunk/io.c#L302
     return 0;
 }
 
+static inline bool
+io_again_p(int e)
+{
+    return (e == EWOULDBLOCK) || (e == EAGAIN);
+}
+
 int
 rb_cloexec_open(const char *pathname, int flags, mode_t mode)
 {
@@ -322,7 +328,7 @@ rb_cloexec_open(const char *pathname, int flags, mode_t mode) https://github.com/ruby/ruby/blob/trunk/io.c#L328
 
     while ((ret = open(pathname, flags, mode)) == -1) {
         int e = errno;
-        if ((e != EAGAIN) && (e != EWOULDBLOCK)) break;
+        if (!io_again_p(e)) break;
         if (retry_count++ >= retry_max_count) break;
 
         sleep(retry_interval);
@@ -1084,7 +1090,7 @@ retry: https://github.com/ruby/ruby/blob/trunk/io.c#L1090
     r = read(iis->fd, iis->buf, iis->capa);
     if (r < 0 && !iis->nonblock) {
         int e = errno;
-        if (e == EAGAIN || e == EWOULDBLOCK) {
+        if (io_again_p(e)) {
             if (nogvl_wait_for_single_fd(iis->th, iis->fd, RB_WAITFD_IN) != -1) {
                 goto retry;
             }
@@ -3082,7 +3088,7 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int no_exception, int nonblock) https://github.com/ruby/ruby/blob/trunk/io.c#L3088
 	    int e = errno;
             if (!nonblock && fptr_wait_readable(fptr))
                 goto again;
-	    if (nonblock && ((e == EWOULDBLOCK) || (e == EAGAIN))) {
+	    if (nonblock && (io_again_p(e))) {
                 if (no_exception)
                     return sym_wait_readable;
                 else
@@ -3218,7 +3224,7 @@ io_read_nonblock(rb_execution_context_t *ec, VALUE io, VALUE length, VALUE str, https://github.com/ruby/ruby/blob/trunk/io.c#L3224
         n = read_internal_locktmp(str, &iis);
         if (n < 0) {
 	    int e = errno;
-	    if ((e == EWOULDBLOCK) || (e == EAGAIN)) {
+	    if (io_again_p(e)) {
                 if (!ex) return sym_wait_readable;
 		rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE,
 					 e, "read would block");
@@ -3260,7 +3266,7 @@ io_write_nonblock(rb_execution_context_t *ec, VALUE io, VALUE str, VALUE ex) https://github.com/ruby/ruby/blob/trunk/io.c#L3266
 
     if (n < 0) {
 	int e = errno;
-	if ((e == EWOULDBLOCK) || (e == EAGAIN)) {
+	if (io_again_p(e)) {
             if (!ex) {
 		return sym_wait_writable;
 	    }
@@ -11688,7 +11694,7 @@ nogvl_copy_stream_write(struct copy_stream_struct *stp, char *buf, size_t len) https://github.com/ruby/ruby/blob/trunk/io.c#L11694
         if (ss < 0) {
             if (maygvl_copy_stream_continue_p(0, stp))
                 continue;
-            if (errno == EAGAIN || errno == EWOULDBLOCK) {
+            if (io_again_p(errno)) {
                 int ret = nogvl_copy_stream_wait_write(stp);
                 if (ret < 0) return ret;
                 continue;
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]