summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--ext/socket/ancdata.c6
-rw-r--r--ext/socket/init.c4
-rw-r--r--ext/socket/socket.c2
-rw-r--r--include/ruby/ruby.h12
-rw-r--r--io.c20
6 files changed, 30 insertions, 19 deletions
diff --git a/ChangeLog b/ChangeLog
index e9f36e5..64bbf14 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/ext/socket/ancdata.c b/ext/socket/ancdata.c
index b19f605..02766ba 100644
--- a/ext/socket/ancdata.c
+++ b/ext/socket/ancdata.c
@@ -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)) {
diff --git a/ext/socket/init.c b/ext/socket/init.c
index 797e4a1..1ecd4fe 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -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)");
}
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index d71a94a..dcf2498 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -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) {
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index d54c511..14fe7c3 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -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
diff --git a/io.c b/io.c
index 976dd8f..2bf7cd7 100644
--- a/io.c
+++ b/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) {