Extract io_again_p to check if EAGAIN or EWOULDBLOCK
This commit is contained in:
parent
9822ebee5b
commit
3d7c92df08
Notes:
git
2021-10-24 19:25:21 +09:00
18
io.c
18
io.c
@ -302,6 +302,12 @@ rb_fix_detect_o_cloexec(int fd)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
io_again_p(int e)
|
||||||
|
{
|
||||||
|
return (e == EWOULDBLOCK) || (e == EAGAIN);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
rb_cloexec_open(const char *pathname, int flags, mode_t mode)
|
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)
|
|||||||
|
|
||||||
while ((ret = open(pathname, flags, mode)) == -1) {
|
while ((ret = open(pathname, flags, mode)) == -1) {
|
||||||
int e = errno;
|
int e = errno;
|
||||||
if ((e != EAGAIN) && (e != EWOULDBLOCK)) break;
|
if (!io_again_p(e)) break;
|
||||||
if (retry_count++ >= retry_max_count) break;
|
if (retry_count++ >= retry_max_count) break;
|
||||||
|
|
||||||
sleep(retry_interval);
|
sleep(retry_interval);
|
||||||
@ -1084,7 +1090,7 @@ retry:
|
|||||||
r = read(iis->fd, iis->buf, iis->capa);
|
r = read(iis->fd, iis->buf, iis->capa);
|
||||||
if (r < 0 && !iis->nonblock) {
|
if (r < 0 && !iis->nonblock) {
|
||||||
int e = errno;
|
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) {
|
if (nogvl_wait_for_single_fd(iis->th, iis->fd, RB_WAITFD_IN) != -1) {
|
||||||
goto retry;
|
goto retry;
|
||||||
}
|
}
|
||||||
@ -3082,7 +3088,7 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int no_exception, int nonblock)
|
|||||||
int e = errno;
|
int e = errno;
|
||||||
if (!nonblock && fptr_wait_readable(fptr))
|
if (!nonblock && fptr_wait_readable(fptr))
|
||||||
goto again;
|
goto again;
|
||||||
if (nonblock && ((e == EWOULDBLOCK) || (e == EAGAIN))) {
|
if (nonblock && (io_again_p(e))) {
|
||||||
if (no_exception)
|
if (no_exception)
|
||||||
return sym_wait_readable;
|
return sym_wait_readable;
|
||||||
else
|
else
|
||||||
@ -3218,7 +3224,7 @@ io_read_nonblock(rb_execution_context_t *ec, VALUE io, VALUE length, VALUE str,
|
|||||||
n = read_internal_locktmp(str, &iis);
|
n = read_internal_locktmp(str, &iis);
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
int e = errno;
|
int e = errno;
|
||||||
if ((e == EWOULDBLOCK) || (e == EAGAIN)) {
|
if (io_again_p(e)) {
|
||||||
if (!ex) return sym_wait_readable;
|
if (!ex) return sym_wait_readable;
|
||||||
rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE,
|
rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE,
|
||||||
e, "read would block");
|
e, "read would block");
|
||||||
@ -3260,7 +3266,7 @@ io_write_nonblock(rb_execution_context_t *ec, VALUE io, VALUE str, VALUE ex)
|
|||||||
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
int e = errno;
|
int e = errno;
|
||||||
if ((e == EWOULDBLOCK) || (e == EAGAIN)) {
|
if (io_again_p(e)) {
|
||||||
if (!ex) {
|
if (!ex) {
|
||||||
return sym_wait_writable;
|
return sym_wait_writable;
|
||||||
}
|
}
|
||||||
@ -11688,7 +11694,7 @@ nogvl_copy_stream_write(struct copy_stream_struct *stp, char *buf, size_t len)
|
|||||||
if (ss < 0) {
|
if (ss < 0) {
|
||||||
if (maygvl_copy_stream_continue_p(0, stp))
|
if (maygvl_copy_stream_continue_p(0, stp))
|
||||||
continue;
|
continue;
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
if (io_again_p(errno)) {
|
||||||
int ret = nogvl_copy_stream_wait_write(stp);
|
int ret = nogvl_copy_stream_wait_write(stp);
|
||||||
if (ret < 0) return ret;
|
if (ret < 0) return ret;
|
||||||
continue;
|
continue;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user