File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / lighttpd / src / network_solaris_sendfilev.c
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Nov 2 10:35:00 2016 UTC (7 years, 8 months ago) by misho
Branches: lighttpd, MAIN
CVS tags: v1_4_41p8, HEAD
lighttpd 1.4.41

    1: #include "first.h"
    2: 
    3: #include "network_backends.h"
    4: 
    5: #if defined(USE_SOLARIS_SENDFILEV)
    6: 
    7: #include "network.h"
    8: #include "log.h"
    9: 
   10: #include <sys/sendfile.h>
   11: 
   12: #include <errno.h>
   13: #include <string.h>
   14: 
   15: /**
   16:  * a very simple sendfilev() interface for solaris which can be optimised a lot more
   17:  * as solaris sendfilev() supports 'sending everythin in one syscall()'
   18:  */
   19: 
   20: int network_write_file_chunk_sendfile(server *srv, connection *con, int fd, chunkqueue *cq, off_t *p_max_bytes) {
   21: 	chunk* const c = cq->first;
   22: 	off_t offset;
   23: 	off_t toSend;
   24: 	size_t written = 0;
   25: 	int r;
   26: 	sendfilevec_t fvec;
   27: 
   28: 	force_assert(NULL != c);
   29: 	force_assert(FILE_CHUNK == c->type);
   30: 	force_assert(c->offset >= 0 && c->offset <= c->file.length);
   31: 
   32: 	offset = c->file.start + c->offset;
   33: 	toSend = c->file.length - c->offset;
   34: 	if (toSend > *p_max_bytes) toSend = *p_max_bytes;
   35: 
   36: 	if (0 == toSend) {
   37: 		chunkqueue_remove_finished_chunks(cq);
   38: 		return 0;
   39: 	}
   40: 
   41: 	if (0 != network_open_file_chunk(srv, con, cq)) return -1;
   42: 
   43: 	fvec.sfv_fd = c->file.fd;
   44: 	fvec.sfv_flag = 0;
   45: 	fvec.sfv_off = offset;
   46: 	fvec.sfv_len = toSend;
   47: 
   48: 	/* Solaris sendfilev() */
   49: 
   50: 	if (-1 == (r = sendfilev(fd, &fvec, 1, &written))) {
   51: 		switch(errno) {
   52: 		case EAGAIN:
   53: 		case EINTR:
   54: 			/* for EAGAIN/EINTR written still contains the sent bytes */
   55: 			break; /* try again later */
   56: 		case EPIPE:
   57: 		case ENOTCONN:
   58: 			return -2;
   59: 		case EINVAL:
   60: 		case ENOSYS:
   61: 	      #if defined(ENOTSUP) \
   62: 		&& (!defined(EOPNOTSUPP) || EOPNOTSUPP != ENOTSUP)
   63: 		case ENOTSUP:
   64: 	      #endif
   65: 	      #ifdef EOPNOTSUPP
   66: 		case EOPNOTSUPP:
   67: 	      #endif
   68: 	      #ifdef ESOCKTNOSUPPORT
   69: 		case ESOCKTNOSUPPORT:
   70: 	      #endif
   71: 	      #ifdef EAFNOSUPPORT
   72: 		case EAFNOSUPPORT:
   73: 	      #endif
   74: 		      #ifdef USE_MMAP
   75: 			return network_write_file_chunk_mmap(srv, con, fd, cq, p_max_bytes);
   76: 		      #else
   77: 			return network_write_file_chunk_no_mmap(srv, con, fd, cq, p_max_bytes);
   78: 		      #endif
   79: 		default:
   80: 			log_error_write(srv, __FILE__, __LINE__, "ssd", "sendfile: ", strerror(errno), errno);
   81: 			return -1;
   82: 		}
   83: 	}
   84: 
   85: 	if (written >= 0) {
   86: 		chunkqueue_mark_written(cq, written);
   87: 		*p_max_bytes -= written;
   88: 	}
   89: 
   90: 	return (r >= 0 && (off_t) written == toSend) ? 0 : -3;
   91: }
   92: 
   93: #endif /* USE_SOLARIS_SENDFILEV */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>