Skip to content

Commit

Permalink
Switch handling of errno.
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Sep 21, 2022
1 parent acc6e61 commit 07612ea
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion io.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,11 +1355,13 @@ io_flush_buffer_sync(void *arg)
fptr->wbuf.len = 0;
return 0;
}

if (0 <= r) {
fptr->wbuf.off += (int)r;
fptr->wbuf.len -= (int)r;
errno = EAGAIN;
}

return (VALUE)-1;
}

Expand Down Expand Up @@ -12303,7 +12305,11 @@ nogvl_wait_for(VALUE th, rb_io_t *fptr, short events, struct timeval *timeout)
}

int fd = fptr->fd;
if (fd == -1) return -1;

if (fd == -1) {
errno = EBADF;
return -1;
}

rb_fdset_t fds;
int ret;
Expand Down
4 changes: 4 additions & 0 deletions thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,10 @@ rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd)
.th = rb_ec_thread_ptr(ec)
};

// `errno` is only valid when there is an actual error - but we can't
// extract that from the return value of `func` alone, so we clear any
// prior `errno` value here so that we can later check if it was set by
// `func` or not (as opposed to some previously set value).
errno = 0;

RB_VM_LOCK_ENTER();
Expand Down

0 comments on commit 07612ea

Please sign in to comment.