ruby-changes:41193
From: nobu <ko1@a...>
Date: Wed, 23 Dec 2015 23:59:07 +0900 (JST)
Subject: [ruby-changes:41193] nobu:r53265 (trunk): rb_readwrite_syserr_fail
nobu 2015-12-23 23:58:47 +0900 (Wed, 23 Dec 2015) New Revision: 53265 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53265 Log: rb_readwrite_syserr_fail * io.c (rb_readwrite_syserr_fail): works with the given errno than thread local errno. Modified files: trunk/ChangeLog trunk/ext/socket/ancdata.c trunk/ext/socket/init.c trunk/ext/socket/socket.c trunk/include/ruby/ruby.h trunk/io.c Index: include/ruby/ruby.h =================================================================== --- include/ruby/ruby.h (revision 53264) +++ include/ruby/ruby.h (revision 53265) @@ -1773,6 +1773,11 @@ VALUE *rb_ruby_debug_ptr(void); https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1773 #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*)); https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1786 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 https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1797 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 ch https://github.com/ruby/ruby/blob/trunk/include/ruby/ruby.h#L1807 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 Index: ChangeLog =================================================================== --- ChangeLog (revision 53264) +++ ChangeLog (revision 53265) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Dec 23 23:58:44 2015 Nobuyoshi Nakada <nobu@r...> + + * 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@r...> * file.c, io.c, util.c: prefer rb_syserr_fail with saved errno Index: io.c =================================================================== --- io.c (revision 53264) +++ io.c (revision 53265) @@ -2474,9 +2474,6 @@ rb_io_set_nonblock(rb_io_t *fptr) https://github.com/ruby/ruby/blob/trunk/io.c#L2474 #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, VAL https://github.com/ruby/ruby/blob/trunk/io.c#L2543 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, https://github.com/ruby/ruby/blob/trunk/io.c#L2669 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, V https://github.com/ruby/ruby/blob/trunk/io.c#L2712 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) https://github.com/ruby/ruby/blob/trunk/io.c#L11963 } 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) { Index: ext/socket/init.c =================================================================== --- ext/socket/init.c (revision 53264) +++ ext/socket/init.c (revision 53265) @@ -253,7 +253,7 @@ rsock_s_recvfrom_nonblock(VALUE sock, VA https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L253 #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, VAL https://github.com/ruby/ruby/blob/trunk/ext/socket/init.c#L570 #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)"); } Index: ext/socket/socket.c =================================================================== --- ext/socket/socket.c (revision 53264) +++ ext/socket/socket.c (revision 53265) @@ -457,7 +457,7 @@ sock_connect_nonblock(VALUE sock, VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/socket.c#L457 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) { Index: ext/socket/ancdata.c =================================================================== --- ext/socket/ancdata.c (revision 53264) +++ ext/socket/ancdata.c (revision 53265) @@ -1285,8 +1285,8 @@ bsock_sendmsg_internal(VALUE sock, VALUE https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1285 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, https://github.com/ruby/ruby/blob/trunk/ext/socket/ancdata.c#L1559 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)) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/