diff options
author | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2000-07-07 02:54:54 +0000 |
---|---|---|
committer | trawick <trawick@13f79535-47bb-0310-9956-ffa450edef68> | 2000-07-07 02:54:54 +0000 |
commit | 2a8ef05436b45a994eb41c27f5ae54139d816320 (patch) | |
tree | a6f31744c3971327478332a0b77661a16fa633f5 /network_io | |
parent | 7e8d61cde83cd0a745e767e27a6789ff4f12771d (diff) | |
download | libapr-2a8ef05436b45a994eb41c27f5ae54139d816320.tar.gz |
ap_sendfile() fixes:
all Unix flavors: fix the check for whether or not we have a timeout
FreeBSD flavor: make it work correct with a non-blocking socket that
doesn't have a timeout
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@60310 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'network_io')
-rw-r--r-- | network_io/unix/sendrecv.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/network_io/unix/sendrecv.c b/network_io/unix/sendrecv.c index 1cd627624..3d749e0fe 100644 --- a/network_io/unix/sendrecv.c +++ b/network_io/unix/sendrecv.c @@ -253,7 +253,7 @@ ap_status_t ap_sendfile(ap_socket_t *sock, ap_file_t *file, if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && - sock->timeout != 0) { + sock->timeout > 0) { arv = wait_for_io_or_timeout(sock, 0); if (arv != APR_SUCCESS) { *len = 0; @@ -331,20 +331,37 @@ ap_status_t ap_sendfile(ap_socket_t * sock, ap_file_t * file, headerstruct.trl_cnt = hdtr->numtrailers; /* FreeBSD can send the headers/footers as part of the system call */ + do { - rv = sendfile(file->filedes, /* open file descriptor of the file to be sent */ - sock->socketdes, /* socket */ - *offset, /* where in the file to start */ - bytes_to_send, /* number of bytes to send */ - &headerstruct, /* Headers/footers */ - &nbytes, /* number of bytes written */ - flags /* undefined, set to 0 */ - ); + if (bytes_to_send) { + /* We won't dare call sendfile() if we don't have + * header or file bytes to send because bytes_to_send == 0 + * means send the whole file. + */ + rv = sendfile(file->filedes, /* file to be sent */ + sock->socketdes, /* socket */ + *offset, /* where in the file to start */ + bytes_to_send, /* number of bytes to send */ + &headerstruct, /* Headers/footers */ + &nbytes, /* number of bytes written */ + flags); /* undefined, set to 0 */ + } + else { + /* just trailer bytes... use writev() + */ + rv = writev(sock->socketdes, + hdtr->trailers, + hdtr->numtrailers); + if (rv > 0) { + nbytes = rv; + rv = 0; + } + } } while (rv == -1 && errno == EINTR); if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && - sock->timeout != 0) { + sock->timeout > 0) { ap_status_t arv = wait_for_io_or_timeout(sock, 0); if (arv != APR_SUCCESS) { *len = 0; @@ -435,7 +452,7 @@ ap_status_t ap_sendfile(ap_socket_t * sock, ap_file_t * file, if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && - sock->timeout != 0) { + sock->timeout > 0) { ap_status_t arv = wait_for_io_or_timeout(sock, 0); if (arv != APR_SUCCESS) { @@ -564,7 +581,7 @@ ap_status_t ap_sendfile(ap_socket_t * sock, ap_file_t * file, if (rv == -1 && (errno == EAGAIN || errno == EWOULDBLOCK) && - sock->timeout != 0) { + sock->timeout > 0) { arv = wait_for_io_or_timeout(sock, 0); if (arv != APR_SUCCESS) { *len = 0; |