Bug #15386 ยป 0001-io.c-rb_io_check_char_readable-do-not-io_fflush-buff.patch
| io.c | ||
|---|---|---|
|
void
|
||
|
rb_io_check_char_readable(rb_io_t *fptr)
|
||
|
{
|
||
|
static const int rw_socket = FMODE_READWRITE|FMODE_DUPLEX;
|
||
|
rb_io_check_closed(fptr);
|
||
|
if (!(fptr->mode & FMODE_READABLE)) {
|
||
|
rb_raise(rb_eIOError, "not opened for reading");
|
||
|
}
|
||
|
if (fptr->wbuf.len) {
|
||
|
if (io_fflush(fptr) < 0)
|
||
|
rb_sys_fail(0);
|
||
|
/*
|
||
|
* Don't flush sockets in the reading thread. We may have a
|
||
|
* situation where a user shares one buffered socket between two
|
||
|
* threads: one thread dedicated to reading, and another thread
|
||
|
* dedicated to writing. Trying to flush from the reader can
|
||
|
* deadlock the writer.
|
||
|
*/
|
||
|
if ((fptr->mode & rw_socket) != rw_socket) {
|
||
|
if (fptr->wbuf.len) {
|
||
|
if (io_fflush(fptr) < 0)
|
||
|
rb_sys_fail(0);
|
||
|
}
|
||
|
}
|
||
|
if (fptr->tied_io_for_writing) {
|
||
|
rb_io_t *wfptr;
|
||
|
GetOpenFile(fptr->tied_io_for_writing, wfptr);
|
||
|
if (io_fflush(wfptr) < 0)
|
||
|
rb_sys_fail(0);
|
||
|
rb_io_t *wfptr;
|
||
|
GetOpenFile(fptr->tied_io_for_writing, wfptr);
|
||
|
if ((wfptr->mode & rw_socket) != rw_socket) {
|
||
|
if (io_fflush(wfptr) < 0)
|
||
|
rb_sys_fail(0);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
-
|
||