0001-io.c-fix-busy-wait-with-sendfile.patch

Eric Wong, 05/13/2011 05:45 AM

Download (2.82 KB)

View differences:

io.c
8463 8463

  
8464 8464
#ifdef USE_SENDFILE
8465 8465
static int
8466
maygvl_copy_stream_wait_readwrite(struct copy_stream_struct *stp)
8467
{
8468
    int ret;
8469
    rb_fd_zero(&stp->fds);
8470
    rb_fd_set(stp->src_fd, &stp->fds);
8471
    rb_fd_set(stp->dst_fd, &stp->fds);
8472
    ret = rb_fd_select(rb_fd_max(&stp->fds), &stp->fds, NULL, NULL, NULL);
8473
    if (ret == -1) {
8474
        stp->syserr = "select";
8475
        stp->error_no = errno;
8476
        return -1;
8477
    }
8478
    return 0;
8479
}
8480

  
8481
static int
8482 8466
nogvl_copy_stream_sendfile(struct copy_stream_struct *stp)
8483 8467
{
8484 8468
    struct stat src_stat, dst_stat;
......
8558 8542
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
8559 8543
	  case EWOULDBLOCK:
8560 8544
#endif
8561
            if (maygvl_copy_stream_wait_readwrite(stp) == -1)
8545
#ifndef linux
8546
	    /*
8547
	     * Linux requires stp->src_fd to be a mmap-able (regular) file,
8548
	     * select() reports regular files to always be "ready", so
8549
	     * there is no need to select() on it.
8550
	     * Other OSes may have the same limitation for sendfile() which
8551
	     * allow us to bypass maygvl_copy_stream_wait_read()...
8552
	     */
8553
            if (maygvl_copy_stream_wait_read(stp) == -1)
8554
                return -1;
8555
#endif
8556
            if (nogvl_copy_stream_wait_write(stp) == -1)
8562 8557
                return -1;
8563 8558
            if (rb_thread_interrupted(stp->th))
8564 8559
                return -1;