eagain_readwrite.diff

Charles Nutter, 03/16/2012 01:02 PM

Download (5.73 KB)

View differences:

error.c
37 37
#define WEXITSTATUS(status) (status)
38 38
#endif
39 39

  
40
VALUE rb_eEAGAIN;
41

  
40 42
extern const char ruby_description[];
41 43

  
42 44
#define REPORTBUG_MSG \
......
1148 1150

  
1149 1151
    if (!st_lookup(syserr_tbl, n, &error)) {
1150 1152
	error = rb_define_class_under(rb_mErrno, name, rb_eSystemCallError);
1153
  if (n == EAGAIN) rb_eEAGAIN = error;
1151 1154
	rb_define_const(error, "Errno", INT2NUM(n));
1152 1155
	st_add_direct(syserr_tbl, n, error);
1153 1156
    }
ext/openssl/ossl_ssl.c
26 26

  
27 27
VALUE mSSL;
28 28
VALUE eSSLError;
29
VALUE eSSLErrorReadable;
29 30
VALUE cSSLContext;
30 31
VALUE cSSLSocket;
31 32

  
......
1108 1109
read_would_block(int nonblock)
1109 1110
{
1110 1111
    if (nonblock) {
1111
        VALUE exc = ossl_exc_new(eSSLError, "read would block");
1112
        VALUE exc = ossl_exc_new(eSSLErrorReadable, "read would block");
1112 1113
        rb_extend_object(exc, rb_mWaitReadable);
1113 1114
        rb_exc_raise(exc);
1114 1115
    }
......
1696 1697

  
1697 1698
    mSSL = rb_define_module_under(mOSSL, "SSL");
1698 1699
    eSSLError = rb_define_class_under(mSSL, "SSLError", eOSSLError);
1700
    eSSLErrorReadable = rb_define_class_under(mSSL, "SSLErrorReaable", eSSLError);
1701
    rb_include_module(eSSLErrorReadable, rb_mWaitReadable);
1699 1702

  
1700 1703
    Init_ossl_ssl_session();
1701 1704

  
ext/socket/ancdata.c
1284 1284

  
1285 1285
    if (ss == -1) {
1286 1286
        if (nonblock && (errno == EWOULDBLOCK || errno == EAGAIN))
1287
            rb_mod_sys_fail(rb_mWaitWritable, "sendmsg(2) would block");
1287
            rb_eagain_readwrite(1, "sendmsg(2) would block");
1288 1288
	rb_sys_fail("sendmsg(2)");
1289 1289
    }
1290 1290

  
......
1593 1593

  
1594 1594
    if (ss == -1) {
1595 1595
        if (nonblock && (errno == EWOULDBLOCK || errno == EAGAIN))
1596
            rb_mod_sys_fail(rb_mWaitReadable, "recvmsg(2) would block");
1596
            rb_eagain_readwrite(0, "recvmsg(2) would block");
1597 1597
#if defined(HAVE_ST_MSG_CONTROL)
1598 1598
        if (!gc_done && (errno == EMFILE || errno == EMSGSIZE)) {
1599 1599
          /*
ext/socket/init.c
212 212
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
213 213
	  case EWOULDBLOCK:
214 214
#endif
215
            rb_mod_sys_fail(rb_mWaitReadable, "recvfrom(2) would block");
215
            rb_eagain_readwrite(0, "recvfrom(2) would block");
216 216
	}
217 217
	rb_sys_fail("recvfrom(2)");
218 218
    }
......
525 525
#if defined EPROTO
526 526
	  case EPROTO:
527 527
#endif
528
            rb_mod_sys_fail(rb_mWaitReadable, "accept(2) would block");
528
            rb_eagain_readwrite(0, "accept(2) would block");
529 529
	}
530 530
        rb_sys_fail("accept(2)");
531 531
    }
include/ruby/ruby.h
1189 1189
NORETURN(void rb_sys_fail_str(VALUE));
1190 1190
NORETURN(void rb_mod_sys_fail(VALUE, const char*));
1191 1191
NORETURN(void rb_mod_sys_fail_str(VALUE, VALUE));
1192
NORETURN(void rb_eagain_readwrite(int, const char*));
1192 1193
NORETURN(void rb_iter_break(void));
1193 1194
NORETURN(void rb_iter_break_value(VALUE));
1194 1195
NORETURN(void rb_exit(int));
io.c
120 120
VALUE rb_eIOError;
121 121
VALUE rb_mWaitReadable;
122 122
VALUE rb_mWaitWritable;
123
extern VALUE rb_eEAGAIN;
124
VALUE rb_eEAGAINReadable;
125
VALUE rb_eEAGAINWritable;
123 126

  
124 127
VALUE rb_stdin, rb_stdout, rb_stderr;
125 128
VALUE rb_deferr;		/* rescue VIM plugin */
......
2221 2224
            if (!nonblock && rb_io_wait_readable(fptr->fd))
2222 2225
                goto again;
2223 2226
            if (nonblock && (errno == EWOULDBLOCK || errno == EAGAIN))
2224
                rb_mod_sys_fail(rb_mWaitReadable, "read would block");
2227
                rb_eagain_readwrite(0, "read would block");
2225 2228
            rb_sys_fail_path(fptr->pathv);
2226 2229
        }
2227 2230
    }
......
2438 2441

  
2439 2442
    if (n == -1) {
2440 2443
        if (errno == EWOULDBLOCK || errno == EAGAIN)
2441
            rb_mod_sys_fail(rb_mWaitWritable, "write would block");
2444
            rb_eagain_readwrite(1, "write would block");
2442 2445
        rb_sys_fail_path(fptr->pathv);
2443 2446
    }
2444 2447

  
......
11071 11074
    return rb_io_write(argf_write_io(argf), str);
11072 11075
}
11073 11076

  
11077
void
11078
rb_eagain_readwrite(int w, const char *mesg)
11079
{
11080
    VALUE arg;
11081
    arg = mesg ? rb_str_new2(mesg) : Qnil;
11082
    if (w) {
11083
        rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEAGAINWritable));
11084
    }
11085
    else {
11086
        rb_exc_raise(rb_class_new_instance(1, &arg, rb_eEAGAINReadable));
11087
    }
11088
}
11089

  
11074 11090
/*
11075 11091
 * Document-class: IOError
11076 11092
 *
......
11311 11327

  
11312 11328
    rb_mWaitReadable = rb_define_module_under(rb_cIO, "WaitReadable");
11313 11329
    rb_mWaitWritable = rb_define_module_under(rb_cIO, "WaitWritable");
11330
    rb_eEAGAINReadable = rb_define_class_under(rb_cIO, "EAGAINReadable", rb_eEAGAIN);
11331
    rb_include_module(rb_eEAGAINReadable, rb_mWaitReadable);
11332
    rb_eEAGAINWritable = rb_define_class_under(rb_cIO, "EAGAINWritable", rb_eEAGAIN);
11333
    rb_include_module(rb_eEAGAINWritable, rb_mWaitWritable);
11314 11334

  
11315 11335
#if 0
11316 11336
    /* This is necessary only for forcing rdoc handle File::open */