xref: /lighttpd1.4/src/network_write.c (revision 1cd73b08)
1 #include "first.h"
2 
3 #include "network_write.h"
4 
5 #include "base.h"
6 #include "ck.h"
7 #include "log.h"
8 
9 #include <sys/types.h>
10 #include "sys-socket.h"
11 
12 #include <errno.h>
13 #include <string.h>
14 #include <unistd.h>
15 
16 
17 /* on linux 2.4.x you get either sendfile or LFS */
18 #if defined HAVE_SYS_SENDFILE_H && defined HAVE_SENDFILE \
19  && (!defined _LARGEFILE_SOURCE || defined HAVE_SENDFILE64) \
20  && defined(__linux__) && !defined HAVE_SENDFILE_BROKEN
21 # ifdef NETWORK_WRITE_USE_SENDFILE
22 #  error "can't have more than one sendfile implementation"
23 # endif
24 # define NETWORK_WRITE_USE_SENDFILE "linux-sendfile"
25 # define NETWORK_WRITE_USE_LINUX_SENDFILE
26 #endif
27 
28 #if defined HAVE_SENDFILE && (defined(__FreeBSD__) || defined(__DragonFly__))
29 # ifdef NETWORK_WRITE_USE_SENDFILE
30 #  error "can't have more than one sendfile implementation"
31 # endif
32 # define NETWORK_WRITE_USE_SENDFILE "freebsd-sendfile"
33 # define NETWORK_WRITE_USE_FREEBSD_SENDFILE
34 #endif
35 
36 #if defined HAVE_SENDFILE && defined(__APPLE__)
37 # ifdef NETWORK_WRITE_USE_SENDFILE
38 #  error "can't have more than one sendfile implementation"
39 # endif
40 # define NETWORK_WRITE_USE_SENDFILE "darwin-sendfile"
41 # define NETWORK_WRITE_USE_DARWIN_SENDFILE
42 #endif
43 
44 #if defined HAVE_SYS_SENDFILE_H && defined HAVE_SENDFILEV && defined(__sun)
45 # ifdef NETWORK_WRITE_USE_SENDFILE
46 #  error "can't have more than one sendfile implementation"
47 # endif
48 # define NETWORK_WRITE_USE_SENDFILE "solaris-sendfilev"
49 # define NETWORK_WRITE_USE_SOLARIS_SENDFILEV
50 #endif
51 
52 /* not supported so far
53 #if defined HAVE_SEND_FILE && defined(__aix)
54 # ifdef NETWORK_WRITE_USE_SENDFILE
55 #  error "can't have more than one sendfile implementation"
56 # endif
57 # define NETWORK_WRITE_USE_SENDFILE "aix-sendfile"
58 # define NETWORK_WRITE_USE_AIX_SENDFILE
59 #endif
60 */
61 
62 #if defined HAVE_SYS_UIO_H && defined HAVE_WRITEV
63 # define NETWORK_WRITE_USE_WRITEV
64 #endif
65 
66 #if defined HAVE_SYS_MMAN_H && defined HAVE_MMAP && defined ENABLE_MMAP
67 # define NETWORK_WRITE_USE_MMAP
68 #endif
69 
70 
71 __attribute_cold__
72 static int network_write_error(int fd, log_error_st *errh) {
73   #if defined(__WIN32)
74     int lastError = WSAGetLastError();
75     switch (lastError) {
76       case WSAEINTR:
77       case WSAEWOULDBLOCK:
78         return -3;
79       case WSAECONNRESET:
80       case WSAETIMEDOUT:
81       case WSAECONNABORTED:
82         return -2;
83       default:
84         log_error(errh,__FILE__,__LINE__,"send failed: %d %d",lastError,fd);
85         return -1;
86     }
87   #else /* __WIN32 */
88     switch (errno) {
89       case EAGAIN:
90       case EINTR:
91         return -3;
92       case EPIPE:
93       case ECONNRESET:
94         return -2;
95       default:
96         log_perror(errh,__FILE__,__LINE__,"write failed: %d",fd);
97         return -1;
98     }
99   #endif /* __WIN32 */
100 }
101 
102 __attribute_cold__
103 static int network_remove_finished_chunks(chunkqueue * const cq, const off_t len) {
104     force_assert(len >= 0);
105     chunkqueue_remove_finished_chunks(cq);
106     return 0;
107 }
108 
109 inline
110 static ssize_t network_write_data_len(int fd, const char *data, off_t len) {
111   #if defined(__WIN32)
112     return send(fd, data, len, 0);
113   #else /* __WIN32 */
114     return write(fd, data, len);
115   #endif /* __WIN32 */
116 }
117 
118 static int network_write_accounting(const int fd, chunkqueue * const cq, off_t * const p_max_bytes, log_error_st * const errh, const ssize_t wr, const off_t toSend) {
119     if (wr >= 0) {
120         *p_max_bytes -= wr;/*(toSend > 0 if we reach this func)*/
121         const int rc = (wr == toSend && *p_max_bytes > 0) ? 0 : -3;
122         chunkqueue_mark_written(cq, wr);
123         return rc;
124     }
125     else
126         return network_write_error(fd, errh);
127 }
128 
129 
130 
131 
132 /* write next chunk(s); finished chunks are removed afterwards after successful writes.
133  * return values: similar as backends (0 success, -1 error, -2 remote close, -3 try again later (EINTR/EAGAIN)) */
134 /* next chunk must be MEM_CHUNK. use write()/send() */
135 #if !defined(NETWORK_WRITE_USE_WRITEV)
136 static int network_write_mem_chunk(const int fd, chunkqueue * const cq, off_t * const p_max_bytes, log_error_st * const errh) {
137     chunk* const c = cq->first;
138     off_t c_len = (off_t)buffer_clen(c->mem) - c->offset;
139     if (c_len > *p_max_bytes) c_len = *p_max_bytes;
140     if (c_len <= 0) return network_remove_finished_chunks(cq, c_len);
141 
142     ssize_t wr = network_write_data_len(fd, c->mem->ptr + c->offset, c_len);
143     return network_write_accounting(fd, cq, p_max_bytes, errh, wr, c_len);
144 }
145 #endif
146 
147 
148 
149 
150 #if !defined(NETWORK_WRITE_USE_MMAP)
151 
152 static int network_write_file_chunk_no_mmap(const int fd, chunkqueue * const cq, off_t * const p_max_bytes, log_error_st * const errh) {
153     chunk* const c = cq->first;
154     off_t offset, toSend;
155     char buf[16384]; /* max read 16kb in one step */
156 
157     offset = c->offset;
158     toSend = c->file.length - c->offset;
159     if (toSend > *p_max_bytes) toSend = *p_max_bytes;
160     if (toSend <= 0) return network_remove_finished_chunks(cq, toSend);
161 
162     if (c->file.fd < 0 && 0 != chunkqueue_open_file_chunk(cq, errh)) return -1;
163 
164     if (toSend > (off_t)sizeof(buf)) toSend = (off_t)sizeof(buf);
165 
166     if (-1 == lseek(c->file.fd, offset, SEEK_SET)) {
167         log_perror(errh, __FILE__, __LINE__, "lseek");
168         return -1;
169     }
170     if ((toSend = read(c->file.fd, buf, toSend)) <= 0) {
171         log_perror(errh, __FILE__, __LINE__, "read");/* err or unexpected EOF */
172         return -1;
173     }
174 
175     ssize_t wr = network_write_data_len(fd, buf, toSend);
176     return network_write_accounting(fd, cq, p_max_bytes, errh, wr, toSend);
177 }
178 
179 #endif
180 
181 
182 
183 
184 #if defined(NETWORK_WRITE_USE_MMAP)
185 
186 #include "sys-mmap.h"
187 
188 #include <setjmp.h>
189 #include <signal.h>
190 
191 #define MMAP_CHUNK_SIZE (512*1024)
192 
193 static off_t mmap_align_offset(off_t start) {
194     static long pagesize = 0;
195     if (0 == pagesize) {
196         pagesize = sysconf(_SC_PAGESIZE);
197         force_assert(pagesize < MMAP_CHUNK_SIZE);
198     }
199     force_assert(start >= (start % pagesize));
200     return start - (start % pagesize);
201 }
202 
203 static volatile int sigbus_jmp_valid;
204 static sigjmp_buf sigbus_jmp;
205 
206 static void sigbus_handler(int sig) {
207     UNUSED(sig);
208     if (sigbus_jmp_valid) siglongjmp(sigbus_jmp, 1);
209     ck_bt_abort(__FILE__, __LINE__, "SIGBUS");
210 }
211 
212 /* next chunk must be FILE_CHUNK. send mmap()ed file with write() */
213 static int network_write_file_chunk_mmap(const int fd, chunkqueue * const cq, off_t * const p_max_bytes, log_error_st * const errh) {
214     chunk* const c = cq->first;
215     off_t offset, toSend, file_end;
216     size_t mmap_offset, mmap_avail;
217     const char *data;
218 
219     file_end = c->file.length; /*file end offset in this chunk*/
220     offset = c->offset;
221     toSend = c->file.length - c->offset;
222     if (toSend > *p_max_bytes) toSend = *p_max_bytes;
223     if (toSend <= 0) return network_remove_finished_chunks(cq, toSend);
224 
225     if (c->file.fd < 0 && 0 != chunkqueue_open_file_chunk(cq, errh)) return -1;
226 
227     /* mmap buffer if offset is outside old mmap area or not mapped at all */
228     if (MAP_FAILED == c->file.mmap.start
229         || offset < c->file.mmap.offset
230         || offset >= (off_t)(c->file.mmap.offset + c->file.mmap.length)) {
231 
232         if (MAP_FAILED != c->file.mmap.start) {
233             munmap(c->file.mmap.start, c->file.mmap.length);
234             c->file.mmap.start = MAP_FAILED;
235         }
236 
237         /* Optimizations for the future:
238          *
239          * adaptive mem-mapping
240          *   the problem:
241          *     we mmap() the whole file. If someone has a lot of large files and
242          *     32-bit machine the virtual address area will be exhausted and we
243          *     will have a failing mmap() call.
244          *   solution:
245          *     only mmap 16M in one chunk and move the window as soon as we have
246          *     finished the first 8M
247          *
248          * read-ahead buffering
249          *   the problem:
250          *     sending out several large files in parallel trashes read-ahead
251          *     of the kernel leading to long wait-for-seek times.
252          *   solutions: (increasing complexity)
253          *     1. use madvise
254          *     2. use a internal read-ahead buffer in the chunk-structure
255          *     3. use non-blocking IO for file-transfers
256          *   */
257 
258         c->file.mmap.offset = mmap_align_offset(offset);
259 
260         /* all mmap()ed areas are MMAP_CHUNK_SIZE
261          * except the last which might be smaller */
262         c->file.mmap.length = MMAP_CHUNK_SIZE;
263         if (c->file.mmap.offset > file_end - (off_t)c->file.mmap.length) {
264             c->file.mmap.length = file_end - c->file.mmap.offset;
265         }
266 
267         c->file.mmap.start = mmap(NULL, c->file.mmap.length, PROT_READ,
268                                   MAP_SHARED, c->file.fd, c->file.mmap.offset);
269         if (MAP_FAILED == c->file.mmap.start) {
270             log_perror(errh, __FILE__, __LINE__,
271               "mmap failed: %s %d %lld %zu", c->mem->ptr, c->file.fd,
272               (long long)c->file.mmap.offset, c->file.mmap.length);
273             return -1;
274         }
275 
276       #if defined(HAVE_MADVISE)
277         /* don't advise files < 64Kb */
278         if (c->file.mmap.length > (64*1024)) {
279             /* darwin 7 is returning EINVAL all the time and I don't know how to
280              * detect this at runtime.
281              *
282              * ignore the return value for now */
283             madvise(c->file.mmap.start, c->file.mmap.length, MADV_WILLNEED);
284         }
285       #endif
286     }
287 
288     force_assert(offset >= c->file.mmap.offset);
289     mmap_offset = offset - c->file.mmap.offset;
290     force_assert(c->file.mmap.length > mmap_offset);
291     mmap_avail = c->file.mmap.length - mmap_offset;
292     if (toSend > (off_t) mmap_avail) toSend = mmap_avail;
293 
294     data = c->file.mmap.start + mmap_offset;
295 
296     /* setup SIGBUS handler, but don't activate sigbus_jmp_valid yet */
297     if (0 == sigsetjmp(sigbus_jmp, 1)) {
298         signal(SIGBUS, sigbus_handler);
299 
300         sigbus_jmp_valid = 1;
301         ssize_t wr = network_write_data_len(fd, data, toSend);
302         sigbus_jmp_valid = 0;
303         return network_write_accounting(fd, cq, p_max_bytes, errh, wr, toSend);
304     } else {
305         sigbus_jmp_valid = 0;
306 
307         log_error(errh, __FILE__, __LINE__,
308           "SIGBUS in mmap: %s %d", c->mem->ptr, c->file.fd);
309 
310         munmap(c->file.mmap.start, c->file.mmap.length);
311         c->file.mmap.start = MAP_FAILED;
312         return -1;
313     }
314 
315 }
316 
317 #endif /* NETWORK_WRITE_USE_MMAP */
318 
319 
320 
321 
322 #if defined(NETWORK_WRITE_USE_WRITEV)
323 
324 #if defined(HAVE_SYS_UIO_H)
325 # include <sys/uio.h>
326 #endif
327 
328 #if defined(UIO_MAXIOV)
329 # define SYS_MAX_CHUNKS UIO_MAXIOV
330 #elif defined(IOV_MAX)
331 /* new name for UIO_MAXIOV since IEEE Std 1003.1-2001 */
332 # define SYS_MAX_CHUNKS IOV_MAX
333 #elif defined(_XOPEN_IOV_MAX)
334 /* minimum value for sysconf(_SC_IOV_MAX); posix requires this to be at least 16, which is good enough - no need to call sysconf() */
335 # define SYS_MAX_CHUNKS _XOPEN_IOV_MAX
336 #else
337 # error neither UIO_MAXIOV nor IOV_MAX nor _XOPEN_IOV_MAX are defined
338 #endif
339 
340 /* allocate iovec[MAX_CHUNKS] on stack, so pick a sane limit:
341  * - each entry will use 1 pointer + 1 size_t
342  * - 32 chunks -> 256 / 512 bytes (32-bit/64-bit pointers)
343  */
344 #define STACK_MAX_ALLOC_CHUNKS 32
345 #if SYS_MAX_CHUNKS > STACK_MAX_ALLOC_CHUNKS
346 # define MAX_CHUNKS STACK_MAX_ALLOC_CHUNKS
347 #else
348 # define MAX_CHUNKS SYS_MAX_CHUNKS
349 #endif
350 
351 /* next chunk must be MEM_CHUNK. send multiple mem chunks using writev() */
352 static int network_writev_mem_chunks(const int fd, chunkqueue * const cq, off_t * const p_max_bytes, log_error_st * const errh) {
353     size_t num_chunks = 0;
354     off_t toSend = 0;
355     struct iovec chunks[MAX_CHUNKS];
356 
357     for (const chunk *c = cq->first; c && MEM_CHUNK == c->type; c = c->next) {
358         const off_t c_len = (off_t)buffer_clen(c->mem) - c->offset;
359         if (c_len > 0) {
360             toSend += c_len;
361 
362             chunks[num_chunks].iov_base = c->mem->ptr + c->offset;
363             chunks[num_chunks].iov_len = (size_t)c_len;
364 
365             if (++num_chunks == MAX_CHUNKS || toSend >= *p_max_bytes) break;
366         }
367         else if (c_len < 0) /*(should not happen; trigger assert)*/
368             return network_remove_finished_chunks(cq, c_len);
369     }
370     if (0 == num_chunks) return network_remove_finished_chunks(cq, 0);
371 
372     ssize_t wr = writev(fd, chunks, num_chunks);
373     return network_write_accounting(fd, cq, p_max_bytes, errh, wr, toSend);
374 }
375 
376 #endif /* NETWORK_WRITE_USE_WRITEV */
377 
378 
379 
380 
381 #if defined(NETWORK_WRITE_USE_SENDFILE)
382 
383 #if defined(NETWORK_WRITE_USE_LINUX_SENDFILE) \
384  || defined(NETWORK_WRITE_USE_SOLARIS_SENDFILEV)
385 #include <sys/sendfile.h>
386 #endif
387 
388 #if defined(NETWORK_WRITE_USE_FREEBSD_SENDFILE) \
389  || defined(NETWORK_WRITE_USE_DARWIN_SENDFILE)
390 #include <sys/uio.h>
391 #endif
392 
393 static int network_write_file_chunk_sendfile(const int fd, chunkqueue * const cq, off_t * const p_max_bytes, log_error_st * const errh) {
394     chunk * const c = cq->first;
395     ssize_t wr;
396     off_t offset;
397     off_t toSend;
398     off_t written = 0;
399 
400     offset = c->offset;
401     toSend = c->file.length - c->offset;
402     if (toSend > *p_max_bytes) toSend = *p_max_bytes;
403     if (toSend <= 0) return network_remove_finished_chunks(cq, toSend);
404 
405     if (c->file.fd < 0 && 0 != chunkqueue_open_file_chunk(cq, errh)) return -1;
406 
407     /* Darwin, FreeBSD, and Solaris variants support iovecs and could
408      * be optimized to send more than just file in single syscall */
409 
410   #if defined(NETWORK_WRITE_USE_LINUX_SENDFILE)
411 
412     wr = sendfile(fd, c->file.fd, &offset, toSend);
413     if (wr > 0) written = (off_t)wr;
414 
415   #elif defined(NETWORK_WRITE_USE_DARWIN_SENDFILE)
416 
417     written = toSend;
418     wr = sendfile(c->file.fd, fd, offset, &written, NULL, 0);
419     /* (for EAGAIN/EINTR written still contains the sent bytes) */
420 
421   #elif defined(NETWORK_WRITE_USE_FREEBSD_SENDFILE)
422 
423     wr = sendfile(c->file.fd, fd, offset, toSend, NULL, &written, 0);
424     /* (for EAGAIN/EINTR written still contains the sent bytes) */
425 
426   #elif defined(NETWORK_WRITE_USE_SOLARIS_SENDFILEV)
427     {
428         sendfilevec_t fvec;
429         fvec.sfv_fd = c->file.fd;
430         fvec.sfv_flag = 0;
431         fvec.sfv_off = offset;
432         fvec.sfv_len = toSend;
433 
434         /* Solaris sendfilev() */
435         wr = sendfilev(fd, &fvec, 1, (size_t *)&written);
436         /* (for EAGAIN/EINTR written still contains the sent bytes) */
437     }
438   #else
439 
440     wr = -1;
441     errno = ENOSYS;
442 
443   #endif
444 
445     if (-1 == wr) {
446         switch(errno) {
447           case EAGAIN:
448           case EINTR:
449             break; /* try again later */
450           case EPIPE:
451           case ECONNRESET:
452           case ENOTCONN:
453             return -2;
454           case EINVAL:
455           case ENOSYS:
456          #if defined(ENOTSUP) && (!defined(EOPNOTSUPP) || EOPNOTSUPP != ENOTSUP)
457           case ENOTSUP:
458          #endif
459          #ifdef EOPNOTSUPP
460           case EOPNOTSUPP:
461          #endif
462          #ifdef ESOCKTNOSUPPORT
463           case ESOCKTNOSUPPORT:
464          #endif
465          #ifdef EAFNOSUPPORT
466           case EAFNOSUPPORT:
467          #endif
468            #ifdef NETWORK_WRITE_USE_MMAP
469             return network_write_file_chunk_mmap(fd, cq, p_max_bytes, errh);
470            #else
471             return network_write_file_chunk_no_mmap(fd, cq, p_max_bytes, errh);
472            #endif
473           default:
474             log_perror(errh, __FILE__, __LINE__, "sendfile(): fd: %d", fd);
475             return -1;
476         }
477     }
478 
479     if (written > 0) {
480         chunkqueue_mark_written(cq, written);
481         *p_max_bytes -= written;
482         if (__builtin_expect( (*p_max_bytes <= 0), 0)) return -3;
483     }
484     else if (0 == wr) { /*(-1 != wr && 0 == written)*/
485         log_error(errh, __FILE__, __LINE__,
486                   "sendfile(): fd: %d file truncated", fd);
487         return -1;
488     }
489 
490     return (wr >= 0 && written == toSend) ? 0 : -3;
491 }
492 
493 #endif
494 
495 
496 
497 
498 /* return values:
499  * >= 0 : no error
500  *   -1 : error (on our side)
501  *   -2 : remote close
502  */
503 
504 static int network_write_chunkqueue_writev(const int fd, chunkqueue * const cq, off_t max_bytes, log_error_st * const errh) {
505     while (NULL != cq->first) {
506         int rc = -1;
507 
508         switch (cq->first->type) {
509         case MEM_CHUNK:
510           #if defined(NETWORK_WRITE_USE_WRITEV)
511             rc = network_writev_mem_chunks(fd, cq, &max_bytes, errh);
512           #else
513             rc = network_write_mem_chunk(fd, cq, &max_bytes, errh);
514           #endif
515             break;
516         case FILE_CHUNK:
517           #ifdef NETWORK_WRITE_USE_MMAP
518             rc = network_write_file_chunk_mmap(fd, cq, &max_bytes, errh);
519           #else
520             rc = network_write_file_chunk_no_mmap(fd, cq, &max_bytes, errh);
521           #endif
522             break;
523         }
524 
525         if (__builtin_expect( (0 != rc), 0)) return (-3 == rc) ? 0 : rc;
526     }
527 
528     return 0;
529 }
530 
531 #if defined(NETWORK_WRITE_USE_SENDFILE)
532 static int network_write_chunkqueue_sendfile(const int fd, chunkqueue * const cq, off_t max_bytes, log_error_st * const errh) {
533     while (NULL != cq->first) {
534         int rc = -1;
535 
536         switch (cq->first->type) {
537         case MEM_CHUNK:
538           #if defined(NETWORK_WRITE_USE_WRITEV)
539             rc = network_writev_mem_chunks(fd, cq, &max_bytes, errh);
540           #else
541             rc = network_write_mem_chunk(fd, cq, &max_bytes, errh);
542           #endif
543             break;
544         case FILE_CHUNK:
545           #if defined(NETWORK_WRITE_USE_SENDFILE)
546             rc = network_write_file_chunk_sendfile(fd, cq, &max_bytes, errh);
547           #elif defined(NETWORK_WRITE_USE_MMAP)
548             rc = network_write_file_chunk_mmap(fd, cq, &max_bytes, errh);
549           #else
550             rc = network_write_file_chunk_no_mmap(fd, cq, &max_bytes, errh);
551           #endif
552             break;
553         }
554 
555         if (__builtin_expect( (0 != rc), 0)) return (-3 == rc) ? 0 : rc;
556     }
557 
558     return 0;
559 }
560 #endif
561 
562 int network_write_init(server *srv) {
563     typedef enum {
564         NETWORK_BACKEND_UNSET,
565         NETWORK_BACKEND_WRITE,
566         NETWORK_BACKEND_WRITEV,
567         NETWORK_BACKEND_SENDFILE,
568     } network_backend_t;
569 
570     network_backend_t backend;
571 
572     struct nb_map {
573         network_backend_t nb;
574         const char *name;
575     } network_backends[] = {
576         /* lowest id wins */
577         { NETWORK_BACKEND_SENDFILE, "sendfile" },
578         { NETWORK_BACKEND_SENDFILE, "linux-sendfile" },
579         { NETWORK_BACKEND_SENDFILE, "freebsd-sendfile" },
580         { NETWORK_BACKEND_SENDFILE, "solaris-sendfilev" },
581         { NETWORK_BACKEND_WRITEV,   "writev" },
582         { NETWORK_BACKEND_WRITE,    "write" },
583         { NETWORK_BACKEND_UNSET,    NULL }
584     };
585 
586     /* get a useful default */
587     backend = network_backends[0].nb;
588 
589     /* match name against known types */
590     if (srv->srvconf.network_backend) {
591         const char *name, *confname = srv->srvconf.network_backend->ptr;
592         for (size_t i = 0; NULL != (name = network_backends[i].name); ++i) {
593             if (0 == strcmp(confname, name)) {
594                 backend = network_backends[i].nb;
595                 break;
596             }
597         }
598         if (NULL == name) {
599             log_error(srv->errh, __FILE__, __LINE__,
600               "server.network-backend has an unknown value: %s", confname);
601             return -1;
602         }
603     }
604 
605     switch(backend) {
606     case NETWORK_BACKEND_SENDFILE:
607       #if defined(NETWORK_WRITE_USE_SENDFILE)
608         srv->network_backend_write = network_write_chunkqueue_sendfile;
609         break;
610       #endif
611     case NETWORK_BACKEND_WRITEV:
612     case NETWORK_BACKEND_WRITE:
613         srv->network_backend_write = network_write_chunkqueue_writev;
614         break;
615     default:
616         return -1;
617     }
618 
619     return 0;
620 }
621 
622 const char * network_write_show_handlers(void) {
623     return
624       "\nNetwork handler:\n\n"
625      #if defined NETWORK_WRITE_USE_LINUX_SENDFILE
626       "\t+ linux-sendfile\n"
627      #else
628       "\t- linux-sendfile\n"
629      #endif
630      #if defined NETWORK_WRITE_USE_FREEBSD_SENDFILE
631       "\t+ freebsd-sendfile\n"
632      #else
633       "\t- freebsd-sendfile\n"
634      #endif
635      #if defined NETWORK_WRITE_USE_DARWIN_SENDFILE
636       "\t+ darwin-sendfile\n"
637      #else
638       "\t- darwin-sendfile\n"
639      #endif
640      #if defined NETWORK_WRITE_USE_SOLARIS_SENDFILEV
641       "\t+ solaris-sendfilev\n"
642      #else
643       "\t- solaris-sendfilev\n"
644      #endif
645      #if defined NETWORK_WRITE_USE_WRITEV
646       "\t+ writev\n"
647      #else
648       "\t- writev\n"
649      #endif
650       "\t+ write\n"
651      #ifdef NETWORK_WRITE_USE_MMAP
652       "\t+ mmap support\n"
653      #else
654       "\t- mmap support\n"
655      #endif
656       ;
657 }
658