* io.c (rb_readwrite_syserr_fail): works with the given errno than
  thread local errno.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53265 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-12-23 14:58:47 +00:00
Родитель f4166e2dd7
Коммит f9adadc5e6
6 изменённых файлов: 30 добавлений и 19 удалений

Просмотреть файл

@ -1,3 +1,8 @@
Wed Dec 23 23:58:44 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_readwrite_syserr_fail): works with the given errno than
thread local errno.
Wed Dec 23 17:57:45 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c, io.c, util.c: prefer rb_syserr_fail with saved errno

Просмотреть файл

@ -1285,8 +1285,8 @@ bsock_sendmsg_internal(VALUE sock, VALUE data, VALUE vflags,
if (ex == Qfalse) {
return sym_wait_writable;
}
rb_readwrite_sys_fail(RB_IO_WAIT_WRITABLE,
"sendmsg(2) would block");
rb_readwrite_syserr_fail(RB_IO_WAIT_WRITABLE, e,
"sendmsg(2) would block");
}
rb_syserr_fail(e, "sendmsg(2)");
}
@ -1559,7 +1559,7 @@ bsock_recvmsg_internal(VALUE sock,
if (ex == Qfalse) {
return sym_wait_readable;
}
rb_readwrite_sys_fail(RB_IO_WAIT_READABLE, "recvmsg(2) would block");
rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE, e, "recvmsg(2) would block");
}
#if defined(HAVE_STRUCT_MSGHDR_MSG_CONTROL)
if (!gc_done && (e == EMFILE || e == EMSGSIZE)) {

Просмотреть файл

@ -253,7 +253,7 @@ rsock_s_recvfrom_nonblock(VALUE sock, VALUE len, VALUE flg, VALUE str,
#endif
if (ex == Qfalse)
return sym_wait_readable;
rb_readwrite_sys_fail(RB_IO_WAIT_READABLE, "recvfrom(2) would block");
rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE, e, "recvfrom(2) would block");
}
rb_syserr_fail(e, "recvfrom(2)");
}
@ -570,7 +570,7 @@ rsock_s_accept_nonblock(VALUE klass, VALUE ex, rb_io_t *fptr,
#endif
if (ex == Qfalse)
return sym_wait_readable;
rb_readwrite_sys_fail(RB_IO_WAIT_READABLE, "accept(2) would block");
rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE, e, "accept(2) would block");
}
rb_syserr_fail(e, "accept(2)");
}

Просмотреть файл

@ -457,7 +457,7 @@ sock_connect_nonblock(VALUE sock, VALUE addr, VALUE ex)
if (ex == Qfalse) {
return sym_wait_writable;
}
rb_readwrite_sys_fail(RB_IO_WAIT_WRITABLE, "connect(2) would block");
rb_readwrite_syserr_fail(RB_IO_WAIT_WRITABLE, e, "connect(2) would block");
}
if (e == EISCONN) {
if (ex == Qfalse) {

Просмотреть файл

@ -1773,6 +1773,11 @@ VALUE *rb_ruby_debug_ptr(void);
#define ruby_verbose (*rb_ruby_verbose_ptr())
#define ruby_debug (*rb_ruby_debug_ptr())
/* for rb_readwrite_sys_fail first argument */
enum rb_io_wait_readwrite {RB_IO_WAIT_READABLE, RB_IO_WAIT_WRITABLE};
#define RB_IO_WAIT_READABLE RB_IO_WAIT_READABLE
#define RB_IO_WAIT_WRITABLE RB_IO_WAIT_WRITABLE
PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3);
PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2);
PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2);
@ -1781,7 +1786,7 @@ NORETURN(void rb_sys_fail(const char*));
NORETURN(void rb_sys_fail_str(VALUE));
NORETURN(void rb_mod_sys_fail(VALUE, const char*));
NORETURN(void rb_mod_sys_fail_str(VALUE, VALUE));
NORETURN(void rb_readwrite_sys_fail(int, const char*));
NORETURN(void rb_readwrite_sys_fail(enum rb_io_wait_readwrite, const char*));
NORETURN(void rb_iter_break(void));
NORETURN(void rb_iter_break_value(VALUE));
NORETURN(void rb_exit(int));
@ -1792,6 +1797,7 @@ NORETURN(void rb_syserr_fail(int, const char*));
NORETURN(void rb_syserr_fail_str(int, VALUE));
NORETURN(void rb_mod_syserr_fail(VALUE, int, const char*));
NORETURN(void rb_mod_syserr_fail_str(VALUE, int, VALUE));
NORETURN(void rb_readwrite_syserr_fail(enum rb_io_wait_readwrite, int, const char*));
/* reports if `-W' specified */
PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2);
@ -1801,10 +1807,6 @@ PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2);
PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2);
PRINTF_ARGS(void rb_compile_warn(const char *, int, const char*, ...), 3, 4);
/* for rb_readwrite_sys_fail first argument */
#define RB_IO_WAIT_READABLE 0
#define RB_IO_WAIT_WRITABLE 1
#define RUBY_BLOCK_CALL_FUNC_TAKES_BLOCKARG 1
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg) \
VALUE yielded_arg, VALUE callback_arg, int argc, const VALUE *argv, VALUE blockarg

20
io.c
Просмотреть файл

@ -2474,9 +2474,6 @@ rb_io_set_nonblock(rb_io_t *fptr)
#endif
}
void
rb_readwrite_sys_fail(int writable, const char *mesg);
struct read_internal_arg {
int fd;
char *str_ptr;
@ -2546,7 +2543,8 @@ io_getpartial(int argc, VALUE *argv, VALUE io, VALUE opts, int nonblock)
if (no_exception_p(opts))
return sym_wait_readable;
else
rb_readwrite_sys_fail(RB_IO_WAIT_READABLE, "read would block");
rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE,
e, "read would block");
}
rb_syserr_fail_path(e, fptr->pathv);
}
@ -2671,7 +2669,8 @@ io_read_nonblock(VALUE io, VALUE length, VALUE str, VALUE ex)
int e = errno;
if ((e == EWOULDBLOCK || e == EAGAIN)) {
if (ex == Qfalse) return sym_wait_readable;
rb_readwrite_sys_fail(RB_IO_WAIT_READABLE, "read would block");
rb_readwrite_syserr_fail(RB_IO_WAIT_READABLE,
e, "read would block");
}
rb_syserr_fail_path(e, fptr->pathv);
}
@ -2713,7 +2712,7 @@ io_write_nonblock(VALUE io, VALUE str, VALUE ex)
return sym_wait_writable;
}
else {
rb_readwrite_sys_fail(RB_IO_WAIT_WRITABLE, "write would block");
rb_readwrite_syserr_fail(RB_IO_WAIT_WRITABLE, e, "write would block");
}
}
rb_syserr_fail_path(e, fptr->pathv);
@ -11964,10 +11963,15 @@ argf_write(VALUE argf, VALUE str)
}
void
rb_readwrite_sys_fail(int writable, const char *mesg)
rb_readwrite_sys_fail(enum rb_io_wait_readwrite writable, const char *mesg)
{
rb_readwrite_syserr_fail(writable, errno, mesg);
}
void
rb_readwrite_syserr_fail(enum rb_io_wait_readwrite writable, int n, const char *mesg)
{
VALUE arg;
int n = errno;
arg = mesg ? rb_str_new2(mesg) : Qnil;
if (writable == RB_IO_WAIT_WRITABLE) {
switch (n) {