if (FD_ISSET(dsi->socket, &readfds)) {
len = dsi->end - dsi->eof; /* it's ensured above that there's space */
- if ((len = read(dsi->socket, dsi->eof, len)) <= 0) {
+ if ((len = recv(dsi->socket, dsi->eof, len, 0)) <= 0) {
if (len == 0) {
LOG(log_error, logtype_dsi, "dsi_peek: EOF");
return -1;
buflen = MIN(8192, dsi->end - dsi->eof);
if (buflen > 0) {
ssize_t ret;
- ret = read(dsi->socket, dsi->eof, buflen);
+ ret = recv(dsi->socket, dsi->eof, buflen, 0);
if (ret > 0)
dsi->eof += ret;
}
int sfvcnt;
struct sendfilevec vec[2];
ssize_t nwritten;
+#elif defined(FREEBSD)
+ ssize_t nwritten;
+ void *hdrp;
+ struct sf_hdtr hdr;
+ struct iovec iovec;
+ hdr.headers = &iovec;
+ hdr.hdr_cnt = 1;
+ hdr.trailers = NULL;
+ hdr.trl_cnt = 0;
+ hdrp = &hdr;
#endif
LOG(log_maxdebug, logtype_dsi, "dsi_stream_read_file(off: %jd, len: %zu)", (intmax_t)offset, length);
sfvcnt = 2;
vec[0].sfv_fd = SFV_FD_SELF;
vec[0].sfv_flag = 0;
- vec[0].sfv_off = block;
+ /* Cast to unsigned long to prevent sign extension of the
+ * pointer value for the LFS case; see Apache PR 39463. */
+ vec[0].sfv_off = (unsigned long)block;
vec[0].sfv_len = DSI_BLOCKSIZ;
vec[1].sfv_fd = fromfd;
vec[1].sfv_flag = 0;
vec[1].sfv_off = offset;
vec[1].sfv_len = length;
+#elif defined(FREEBSD)
+ iovec.iov_base = block;
+ iovec.iov_len = DSI_BLOCKSIZ;
#else
dsi_stream_write(dsi, block, sizeof(block), DSI_MSG_MORE);
#endif
#ifdef HAVE_SENDFILEV
nwritten = 0;
len = sendfilev(dsi->socket, vec, sfvcnt, &nwritten);
+#elif defined(FREEBSD)
+ len = sendfile(fromfd, dsi->socket, pos, total - written, hdrp, &nwritten, 0);
+ if (len == 0)
+ len = nwritten;
#else
len = sys_sendfile(dsi->socket, fromfd, &pos, total - written);
#endif
switch (errno) {
case EINTR:
case EAGAIN:
-#if defined(SOLARIS) || defined(FREEBSD)
-#ifdef HAVE_SENDFILEV
+ len = 0;
+#if defined(HAVE_SENDFILEV) || defined(FREEBSD)
len = (size_t)nwritten;
-#else
+#elif defined(SOLARIS)
if (pos > offset) {
/* we actually have sent sth., adjust counters and keep trying */
len = pos - offset;
- written += len;
offset = pos;
}
#endif /* HAVE_SENDFILEV */
-#endif /* defined(SOLARIS) || defined(FREEBSD) */
- if (dsi_peek(dsi)) {
+
+ if (dsi_peek(dsi) != 0) {
ret = -1;
goto exit;
}
vec[0].sfv_off += len;
vec[0].sfv_len -= len;
}
+#elif defined(FREEBSD)
+ if (hdrp) {
+ if (len >= iovec.iov_len) {
+ hdrp = NULL;
+ len -= iovec.iov_len; /* len now contains how much sendfile() actually sent from the file */
+ } else {
+ iovec.iov_len -= len;
+ iovec.iov_base += len;
+ len = 0;
+ }
+ }
+ pos += len;
#endif /* HAVE_SENDFILEV */
-
+ LOG(log_maxdebug, logtype_dsi, "dsi_stream_read_file: wrote: %zd", len);
written += len;
}
#ifdef HAVE_SENDFILEV
stored += len;
} else { /* eof or error */
/* don't log EOF error if it's just after connect (OSX 10.3 probe) */
-#if 0
- if (errno == ECONNRESET)
- dsi->flags |= DSI_GOT_ECONNRESET;
-#endif
if (len || stored || dsi->read_count) {
if (! (dsi->flags & DSI_DISCONNECTED)) {
LOG(log_error, logtype_dsi, "dsi_stream_read: len:%d, %s",
break;
else if (len < 0) { /* error */
if (errno == EAGAIN || errno == EWOULDBLOCK) {
- if (!dsi_peek(dsi)) {
+ if (dsi_peek(dsi) == 0) {
continue;
}
}
dsi->clientID = ntohs(dsi->header.dsi_requestID);
/* make sure we don't over-write our buffers. */
- dsi->cmdlen = MIN(ntohl(dsi->header.dsi_len), DSI_CMDSIZ);
+ dsi->cmdlen = MIN(ntohl(dsi->header.dsi_len), dsi->server_quantum);
if (dsi_stream_read(dsi, dsi->commands, dsi->cmdlen) != dsi->cmdlen)
return 0;