[前][次][番号順一覧][スレッド一覧]

ruby-changes:18169

From: naruse <ko1@a...>
Date: Mon, 13 Dec 2010 12:01:45 +0900 (JST)
Subject: [ruby-changes:18169] Ruby:r30190 (trunk): * io.c (simple_sendfile): added for BSD version of sendfile(2).

naruse	2010-12-13 11:34:50 +0900 (Mon, 13 Dec 2010)

  New Revision: 30190

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30190

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

  Modified files:
    trunk/ChangeLog
    trunk/io.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 30189)
+++ ChangeLog	(revision 30190)
@@ -1,3 +1,7 @@
+Mon Dec 13 11:21:14 2010  NARUSE, Yui  <naruse@r...>
+
+	* io.c (simple_sendfile): added for BSD version of sendfile(2).
+
 Mon Dec 13 09:50:09 2010  NARUSE, Yui  <naruse@r...>
 
 	* lib/net/http.rb (Net::HTTPRequest#set_form): Added to support
Index: io.c
===================================================================
--- io.c	(revision 30189)
+++ io.c	(revision 30190)
@@ -8198,26 +8198,46 @@
 
 #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
 
 #ifdef USE_SENDFILE

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]