summaryrefslogtreecommitdiff
path: root/network_io
diff options
context:
space:
mode:
authorjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2004-03-27 13:11:18 +0000
committerjorton <jorton@13f79535-47bb-0310-9956-ffa450edef68>2004-03-27 13:11:18 +0000
commit263ebecba3310066882fe83f7309c4f101ff34d2 (patch)
tree5919e52a5b6b9ae68ac09f9e288751d4b6a8034f /network_io
parentc3da8b59b2241ac249f2e52e06aec980a69769d8 (diff)
downloadlibapr-263ebecba3310066882fe83f7309c4f101ff34d2.tar.gz
Add LFS support:
* configure.in: Check for off64_t and necessary LFS functions, define apr_off_t as off64_t where available. Add --disable-lfs flag. Forward-port changes from 0.9.5 to define apr_off_t as long on systems systems with a 32-bit off_t which don't have LFS enabled. * include/apr.h.in: Let configure define APR_HAS_LARGE_FILES. * include/arch/netware/apr_arch_file_io.h: Redefine lseek and ftruncate. * include/arch/unix/apr_arch_file_io.h: Redefine stat, lstat, fstat, lseek, ftruncate here; define struct_stat. * file_io/unix/filestat.c: Use struct_stat. * file_io/unix/mktemp.c: Use mkstemp64 where available. * file_io/unix/open.c (apr_file_open): Use O_LARGEFILE by default when LFS is enabled. * file_io/unix/readwrite.c, file_io/unix/seek.c: Don't redefine lseek and ftruncate here. * mmap/unix/mmap.c (apr_mmap_create): Use mmap64 if available; otherwise check for overflow when LFS is enabled. * network_io/unix/sendrecv.c (apr_socket_sendfile) [Linux/HPUX]: Use sendfile64 if available; otherwise check for overflow when LFS is enabled. [solaris]: Use sendfilev64/sendfilevec64_t. * test/Makefile.in, test/test_apr.h, test/testlfs.c: Add tests. Reviewed by: Jeff Trawick git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@65027 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'network_io')
-rw-r--r--network_io/unix/sendrecv.c52
1 files changed, 47 insertions, 5 deletions
diff --git a/network_io/unix/sendrecv.c b/network_io/unix/sendrecv.c
index 60fae1a88..9381693ed 100644
--- a/network_io/unix/sendrecv.c
+++ b/network_io/unix/sendrecv.c
@@ -243,10 +243,28 @@ apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
apr_hdtr_t *hdtr, apr_off_t *offset,
apr_size_t *len, apr_int32_t flags)
{
- off_t off = *offset;
int rv, nbytes = 0, total_hdrbytes, i;
apr_status_t arv;
+#if APR_HAS_LARGE_FILES && defined(HAVE_SENDFILE64)
+ apr_off_t off = *offset;
+#define sendfile sendfile64
+
+#elif APR_HAS_LARGE_FILES && SIZEOF_OFF_T == 4
+ /* 64-bit apr_off_t but no sendfile64(): fail if trying to send
+ * past the 2Gb limit. */
+ off_t off;
+
+ if ((apr_int64_t)*offset + *len > INT_MAX) {
+ return EINVAL;
+ }
+
+ off = *offset;
+
+#else
+ off_t off = *offset;
+#endif
+
if (!hdtr) {
hdtr = &no_hdtr;
}
@@ -562,6 +580,24 @@ apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
struct iovec hdtrarray[2];
char *headerbuf, *trailerbuf;
+#if APR_HAS_LARGE_FILES && defined(HAVE_SENDFILE64)
+ /* later HP-UXes have a sendfile64() */
+#define sendfile sendfile64
+ apr_off_t off = *offset;
+
+#elif APR_HAS_LARGE_FILES && SIZEOF_OFF_T == 4
+ /* HP-UX 11.00 doesn't have a sendfile64(): fail if trying to send
+ * past the 2Gb limit */
+ off_t off;
+
+ if ((apr_int64_t)*offset + *len > INT_MAX) {
+ return EINVAL;
+ }
+ off = *offset;
+#else
+ apr_off_t off = *offset;
+#endif
+
if (!hdtr) {
hdtr = &no_hdtr;
}
@@ -627,7 +663,7 @@ apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
if (nbytes) { /* any bytes to send from the file? */
rc = sendfile(sock->socketdes, /* socket */
file->filedes, /* file descriptor to send */
- *offset, /* where in the file to start */
+ off, /* where in the file to start */
nbytes, /* number of bytes to send from file */
hdtrarray, /* Headers/footers */
flags); /* undefined, set to 0 */
@@ -650,7 +686,7 @@ apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
if (nbytes) {
rc = sendfile(sock->socketdes, /* socket */
file->filedes, /* file descriptor to send */
- *offset, /* where in the file to start */
+ off, /* where in the file to start */
nbytes, /* number of bytes to send from file */
hdtrarray, /* Headers/footers */
flags); /* undefined, set to 0 */
@@ -838,6 +874,12 @@ do_select:
* 111298-01, 108529-09, 109473-06, 109235-04, 108996-02, 111296-01, 109026-04,
* 108992-13
*/
+
+#if APR_HAS_LARGE_FILES && defined(HAVE_SENDFILEV64)
+#define sendfilevec_t sendfilevec64_t
+#define sendfilev sendfilev64
+#endif
+
apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
apr_hdtr_t *hdtr, apr_off_t *offset,
apr_size_t *len, apr_int32_t flags)
@@ -865,7 +907,7 @@ apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
for (i = 0; i < hdtr->numheaders; i++, curvec++) {
sfv[curvec].sfv_fd = SFV_FD_SELF;
sfv[curvec].sfv_flag = 0;
- sfv[curvec].sfv_off = (off_t)hdtr->headers[i].iov_base;
+ sfv[curvec].sfv_off = (apr_off_t)hdtr->headers[i].iov_base;
sfv[curvec].sfv_len = hdtr->headers[i].iov_len;
requested_len += sfv[curvec].sfv_len;
}
@@ -889,7 +931,7 @@ apr_status_t apr_socket_sendfile(apr_socket_t *sock, apr_file_t *file,
for (i = 0; i < hdtr->numtrailers; i++, curvec++) {
sfv[curvec].sfv_fd = SFV_FD_SELF;
sfv[curvec].sfv_flag = 0;
- sfv[curvec].sfv_off = (off_t)hdtr->trailers[i].iov_base;
+ sfv[curvec].sfv_off = (apr_off_t)hdtr->trailers[i].iov_base;
sfv[curvec].sfv_len = hdtr->trailers[i].iov_len;
requested_len += sfv[curvec].sfv_len;
}