* io.c (simple_sendfile): added for BSD version of sendfile(2).

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30190 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
naruse 2010-12-13 02:34:50 +00:00
Родитель e1dc8e0c22
Коммит b36c91b6b5
2 изменённых файлов: 32 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,7 @@
Mon Dec 13 11:21:14 2010 NARUSE, Yui <naruse@ruby-lang.org>
* io.c (simple_sendfile): added for BSD version of sendfile(2).
Mon Dec 13 09:50:09 2010 NARUSE, Yui <naruse@ruby-lang.org>
* lib/net/http.rb (Net::HTTPRequest#set_form): Added to support

36
io.c
Просмотреть файл

@ -8198,25 +8198,45 @@ nogvl_copy_stream_wait_write(struct copy_stream_struct *stp)
#ifdef HAVE_SENDFILE
#ifdef __linux__
#define USE_SENDFILE
# ifdef __linux__
# define USE_SENDFILE
#ifdef HAVE_SYS_SENDFILE_H
#include <sys/sendfile.h>
#endif
# ifdef HAVE_SYS_SENDFILE_H
# include <sys/sendfile.h>
# endif
static ssize_t
simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count)
{
#if SIZEOF_OFF_T > SIZEOF_SIZE_T
# 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
# endif
return sendfile(out_fd, in_fd, offset, (size_t)count);
}
#endif
# elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__APPLE__)
# ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
# endif
static ssize_t
simple_sendfile(int out_fd, int in_fd, off_t *offset, off_t count)
{
int r;
size_t sbytes;
# 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
r = sendfile(in_fd, out_fd, *offset, (size_t)count, NULL, &sbytes, 0);
if (r != 0) return -1;
return (ssize_t)sbytes;
}
# endif
#endif