httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Victor J. Orlikowski" <...@raleigh.ibm.com>
Subject [PATCH] AIX ap_sendfile
Date Wed, 14 Jun 2000 22:21:08 GMT
In the interest of performance, an implementation of ap_sendfile for AIX.

Index: src/CHANGES
===================================================================
RCS file: /cvs/apache/apache-2.0/src/CHANGES,v
retrieving revision 1.151
diff -u -r1.151 CHANGES
--- CHANGES 2000/06/14 00:19:29 1.151
+++ CHANGES 2000/06/14 22:15:52
@@ -1,4 +1,6 @@
 Changes with Apache 2.0a5
+  *) Add ap_sendfile implementation for AIX
+     [Victor J. Orlikowski]

   *) Add support for the new Beos NetwOrking Environment (BONE)
      [David Reid]
Index: src/lib/apr/configure.in
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/configure.in,v
retrieving revision 1.112
diff -u -r1.112 configure.in
--- configure.in 2000/06/14 20:38:13 1.112
+++ configure.in 2000/06/14 22:15:53
@@ -196,7 +196,7 @@
 AC_CHECK_FUNCS(strcasecmp stricmp setsid nl_langinfo)
 AC_CHECK_FUNCS(sigaction, [ have_sigaction="1" ], [ have_sigaction="0" ])
 AC_CHECK_FUNCS(writev)
-AC_CHECK_FUNCS(sendfile, [ sendfile="1" ], [ sendfile="0" ])
+AC_CHECK_FUNCS(sendfile send_file, [ sendfile="1" ], [ sendfile="0" ])
 AC_CHECK_FUNCS(fork, [ fork="1" ], [ fork="0" ])
 AC_CHECK_FUNCS(getpass)
 AC_CHECK_FUNC(inet_addr, [ inet_addr="1" ], [ inet_addr="0" ])
Index: src/lib/apr/network_io/unix/sendrecv.c
===================================================================
RCS file: /cvs/apache/apache-2.0/src/lib/apr/network_io/unix/sendrecv.c,v
retrieving revision 1.22
diff -u -r1.22 sendrecv.c
--- sendrecv.c 2000/05/16 20:35:39 1.22
+++ sendrecv.c 2000/06/14 22:15:54
@@ -65,7 +65,7 @@
 #define READ(x,y,z)   read(x,y,z)
 #endif

-#ifdef HAVE_SENDFILE
+#if defined(HAVE_SENDFILE) || defined(HAVE_SEND_FILE)
 /* This file is needed to allow us access to the ap_file_t internals. */
 #include "../../file_io/unix/fileio.h"

@@ -76,7 +76,7 @@
 #define TCP_CORK 3
 #endif

-#endif /* HAVE_SENDFILE */
+#endif /* HAVE_SENDFILE || HAVE_SEND_FILE */

 static ap_status_t wait_for_io_or_timeout(ap_socket_t *sock, int for_read)
 {
@@ -204,7 +204,7 @@
 }
 #endif

-#if defined(HAVE_SENDFILE)
+#if defined(HAVE_SENDFILE) || defined(HAVE_SEND_FILE)

  /* TODO: Verify that all platforms handle the fd the same way
   *     (i.e. not moving current file pointer)
@@ -451,8 +451,109 @@
     (*len) = rv;
     return APR_SUCCESS;
 }
+#elif defined(_AIX)
+/* Need another check to make sure the dependencies are checked */
+/* AIX, version 4.3.2 with APAR IX85388, or version 4.3.3 and above */
+ap_status_t ap_sendfile(ap_socket_t * sock, ap_file_t * file,
+                        ap_hdtr_t * hdtr, ap_off_t * offset, ap_size_t *
len,
+                        ap_int32_t flags)
+{
+    int i, ptr, rv = 0;
+    void * hbuf=NULL, * tbuf=NULL;
+    ap_status_t arv;
+    struct sf_parms parms;
+
+    /* AIX can also send the headers/footers as part of the system call
+       ... badly.*/
+    parms.header_length = 0;
+    if (hdtr && hdtr->numheaders) {
+        if (hdtr->numheaders == 1) {
+            parms.header_data = hdtr->headers[0].iov_base;
+            parms.header_length = hdtr->headers[0].iov_len;
+        }
+        else {
+            for (i = 0; i < hdtr->numheaders; i++)

+                parms.header_length += hdtr->headers[i].iov_len;
+            }
+            /* Keepalives make ap_palloc a bad idea */
+            hbuf = malloc(parms.header_length);
+     ptr = 0;
+            for (i = 0; i < hdtr->numheaders; i++) {
+                memcpy(hbuf + ptr, hdtr->headers[i].iov_base,
+                       hdtr->headers[i].iov_len);
+                ptr += hdtr->headers[i].iov_len;
+            }
+            parms.header_data = hbuf;
+        }
+    }
+    else parms.header_data = NULL;
+    parms.trailer_length = 0;
+    if (hdtr && hdtr->numtrailers) {
+        if (hdtr->numtrailers == 1) {
+            parms.trailer_data = hdtr->trailers[0].iov_base;
+            parms.trailer_length = hdtr->trailers[0].iov_len;
+        }
+        else {
+            for (i = 0; i < hdtr->numtrailers; i++) {
+                parms.trailer_length += hdtr->trailers[i].iov_len;
+            }
+            /* Keepalives make ap_palloc a bad idea */
+            tbuf = malloc(parms.trailer_length);
+            ptr = 0;
+            for (i = 0; i < hdtr->numtrailers; i++) {
+                memcpy(tbuf + ptr, hdtr->trailers[i].iov_base,
+                       hdtr->trailers[i].iov_len);
+                ptr += hdtr->trailers[i].iov_len;
+            }
+            parms.trailer_data = tbuf;
+        }
+    }
+    else parms.trailer_data = NULL;
+
+    /* Whew! Headers and trailers set up. Now for the file data */
+
+    parms.file_descriptor = file->filedes;
+    parms.file_offset = *offset;
+    parms.file_bytes = *len;
+
+    /* O.K. All set up now. Let's go to town */
+
+    do {
+        rv = send_file(&(sock->socketdes), /* socket */
+                       &(parms),           /* all data */
+                       flags               /* flags */
+                      );
+    } while (rv == -1 && errno == EINTR);
+
+    if (rv == -1 &&
+        (errno == EAGAIN || errno == EWOULDBLOCK) &&
+        sock->timeout != 0) {
+        arv = wait_for_io_or_timeout(sock, 0);
+        if (arv != APR_SUCCESS) {
+            *len = 0;
+            return arv;
+        }
+        else {
+            do {
+                rv = send_file(&(sock->socketdes), /* socket */
+                               &(parms),           /* all data */
+                               flags               /* flags */
+                              );
+            } while (rv == -1 && errno == EINTR);
+        }
+    }
+
+    (*len) = parms.bytes_sent;
+
+    /* Clean up after ourselves */
+    if(hbuf) free(hbuf);
+    if(tbuf) free(tbuf);
+
+    if (rv == -1) {
+        return errno;
+    }
+    return APR_SUCCESS;
+}
 #else
-/* TODO: Add AIX support */
-#endif /* __linux__, __FreeBSD__, __HPUX__ */
+#endif /* __linux__, __FreeBSD__, __HPUX__, _AIX */
 #endif /* HAVE_SENDFILE */
-



Mime
View raw message