* io.c (simple_sendfile): enable on Mac OS X.
* io.c (nogvl_copy_stream_sendfile): moved precheck of copy length. * io.c (nogvl_copy_stream_sendfile): should wait for both of read/write fds. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30215 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
7b5e72c3a9
commit
eb36519b96
@ -1,3 +1,12 @@
|
|||||||
|
Wed Dec 15 11:07:34 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* io.c (simple_sendfile): enable on Mac OS X.
|
||||||
|
|
||||||
|
* io.c (nogvl_copy_stream_sendfile): moved precheck of copy length.
|
||||||
|
|
||||||
|
* io.c (nogvl_copy_stream_sendfile): should wait for both of
|
||||||
|
read/write fds.
|
||||||
|
|
||||||
Wed Dec 15 07:11:55 2010 Tanaka Akira <akr@fsij.org>
|
Wed Dec 15 07:11:55 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* hash.c: parenthesize macro arguments.
|
* hash.c: parenthesize macro arguments.
|
||||||
|
45
io.c
45
io.c
@ -8196,6 +8196,22 @@ nogvl_copy_stream_wait_write(struct copy_stream_struct *stp)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
maygvl_copy_stream_wait_readwrite(struct copy_stream_struct *stp)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
rb_fd_zero(&stp->fds);
|
||||||
|
rb_fd_set(stp->src_fd, &stp->fds);
|
||||||
|
rb_fd_set(stp->dst_fd, &stp->fds);
|
||||||
|
ret = rb_fd_select(rb_fd_max(&stp->fds), &stp->fds, NULL, NULL, NULL);
|
||||||
|
if (ret == -1) {
|
||||||
|
stp->syserr = "select";
|
||||||
|
stp->error_no = errno;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_SENDFILE
|
#ifdef HAVE_SENDFILE
|
||||||
|
|
||||||
# ifdef __linux__
|
# ifdef __linux__
|
||||||
@ -8208,15 +8224,10 @@ nogvl_copy_stream_wait_write(struct copy_stream_struct *stp)
|
|||||||
static ssize_t
|
static ssize_t
|
||||||
simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count)
|
simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count)
|
||||||
{
|
{
|
||||||
# if SIZEOF_OFF_T > SIZEOF_SIZE_T
|
|
||||||
/* we are limited by the 32-bit ssize_t return value on 32-bit */
|
|
||||||
if (count > (off_t)SSIZE_MAX)
|
|
||||||
count = SSIZE_MAX;
|
|
||||||
# endif
|
|
||||||
return sendfile(out_fd, in_fd, offset, (size_t)count);
|
return sendfile(out_fd, in_fd, offset, (size_t)count);
|
||||||
}
|
}
|
||||||
|
|
||||||
# elif 0 /* defined(__FreeBSD__) || defined(__DragonFly__) */
|
# elif 0 /* defined(__FreeBSD__) || defined(__DragonFly__) */ || defined(__APPLE__)
|
||||||
/* This runs on FreeBSD8.1 r30210, but sendfiles blocks its execution
|
/* This runs on FreeBSD8.1 r30210, but sendfiles blocks its execution
|
||||||
* without cpuset -l 0.
|
* without cpuset -l 0.
|
||||||
*/
|
*/
|
||||||
@ -8232,19 +8243,19 @@ simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count)
|
|||||||
int r;
|
int r;
|
||||||
off_t pos = offset ? *offset : lseek(in_fd, 0, SEEK_CUR);
|
off_t pos = offset ? *offset : lseek(in_fd, 0, SEEK_CUR);
|
||||||
off_t sbytes;
|
off_t sbytes;
|
||||||
# if SIZEOF_OFF_T > SIZEOF_SIZE_T
|
# ifdef __APPLE__
|
||||||
/* we are limited by the 32-bit ssize_t return value on 32-bit */
|
r = sendfile(in_fd, out_fd, pos, &count, NULL, 0);
|
||||||
if (count > (off_t)SSIZE_MAX)
|
sbytes = count;
|
||||||
count = SSIZE_MAX;
|
# else
|
||||||
# endif
|
|
||||||
r = sendfile(in_fd, out_fd, pos, (size_t)count, NULL, &sbytes, 0);
|
r = sendfile(in_fd, out_fd, pos, (size_t)count, NULL, &sbytes, 0);
|
||||||
|
# endif
|
||||||
|
if (r != 0 && sbytes == 0) return -1;
|
||||||
if (offset) {
|
if (offset) {
|
||||||
*offset += sbytes;
|
*offset += sbytes;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
lseek(in_fd, sbytes, SEEK_CUR);
|
lseek(in_fd, sbytes, SEEK_CUR);
|
||||||
}
|
}
|
||||||
if (r != 0 && sbytes == 0) return -1;
|
|
||||||
return (ssize_t)sbytes;
|
return (ssize_t)sbytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -8303,11 +8314,15 @@ nogvl_copy_stream_sendfile(struct copy_stream_struct *stp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
retry_sendfile:
|
retry_sendfile:
|
||||||
|
# if SIZEOF_OFF_T > SIZEOF_SIZE_T
|
||||||
|
/* we are limited by the 32-bit ssize_t return value on 32-bit */
|
||||||
|
ss = (copy_length > (off_t)SSIZE_MAX) ? SSIZE_MAX : (ssize_t)copy_length;
|
||||||
|
# endif
|
||||||
if (use_pread) {
|
if (use_pread) {
|
||||||
ss = simple_sendfile(stp->dst_fd, stp->src_fd, &src_offset, copy_length);
|
ss = simple_sendfile(stp->dst_fd, stp->src_fd, &src_offset, ss);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ss = simple_sendfile(stp->dst_fd, stp->src_fd, NULL, copy_length);
|
ss = simple_sendfile(stp->dst_fd, stp->src_fd, NULL, ss);
|
||||||
}
|
}
|
||||||
if (0 < ss) {
|
if (0 < ss) {
|
||||||
stp->total += ss;
|
stp->total += ss;
|
||||||
@ -8327,7 +8342,7 @@ nogvl_copy_stream_sendfile(struct copy_stream_struct *stp)
|
|||||||
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
|
||||||
case EWOULDBLOCK:
|
case EWOULDBLOCK:
|
||||||
#endif
|
#endif
|
||||||
if (nogvl_copy_stream_wait_write(stp) == -1)
|
if (maygvl_copy_stream_wait_readwrite(stp) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
if (rb_thread_interrupted(stp->th))
|
if (rb_thread_interrupted(stp->th))
|
||||||
return -1;
|
return -1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user