1 2 /* 3 * Copyright (C) Igor Sysoev 4 * Copyright (C) NGINX, Inc. 5 */ 6 7 #ifndef _NXT_SENDBUF_H_INCLUDED_ 8 #define _NXT_SENDBUF_H_INCLUDED_ 9 10 11 /* 12 * The sendbuf interface is intended to send a buffer chain to a connection. 13 * It uses sendfile interface if available. Otherwise it can send only 14 * memory buffers, so file buffers must be read in memory in advance. 15 * 16 * The sendbuf interface sets c->socket.write_ready to appropriate state 17 * and returns: 18 * 19 * N > 0 if sendbuf sent N bytes. 20 * 21 * 0 if sendbuf was interrupted (EINTR and so on), 22 * or sendbuf sent previously buffered data, 23 * or single sync buffer has been encountered. 24 * In all these cases sendbuf is ready to continue 25 * operation, unless c->socket.write_ready is cleared. 26 * 27 * NXT_AGAIN if sendbuf did not send any bytes. 28 * 29 * NXT_ERROR if there was erorr. 30 * 31 * The sendbuf limit is size_t type since size_t is large enough and many 32 * sendfile implementations do not support anyway sending more than size_t 33 * at once. The limit support is located at the sendbuf level otherwise 34 * an additional limited chain must be created on each sendbuf call. 35 */ 36 37 38 typedef struct { 39 nxt_buf_t *buf; 40 nxt_iobuf_t *iobuf; 41 42 uint32_t nmax; 43 uint8_t sync; /* 1 bit */ 44 uint8_t last; /* 1 bit */ 45 46 size_t size; 47 size_t limit; 48 } nxt_sendbuf_coalesce_t; 49 50 51 #if (NXT_HAVE_LINUX_SENDFILE) 52 #define NXT_HAVE_SENDFILE 1 53 ssize_t nxt_linux_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 54 size_t limit); 55 #endif 56 57 #if (NXT_HAVE_FREEBSD_SENDFILE) 58 #define NXT_HAVE_SENDFILE 1 59 ssize_t nxt_freebsd_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 60 size_t limit); 61 #endif 62 63 #if (NXT_HAVE_SOLARIS_SENDFILEV) 64 #define NXT_HAVE_SENDFILE 1 65 ssize_t nxt_solaris_event_conn_io_sendfilev(nxt_event_conn_t *c, nxt_buf_t *b, 66 size_t limit); 67 #endif 68 69 #if (NXT_HAVE_MACOSX_SENDFILE) 70 #define NXT_HAVE_SENDFILE 1 71 ssize_t nxt_macosx_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 72 size_t limit); 73 #endif 74 75 #if (NXT_HAVE_AIX_SEND_FILE) 76 #define NXT_HAVE_SENDFILE 1 77 ssize_t nxt_aix_event_conn_io_send_file(nxt_event_conn_t *c, nxt_buf_t *b, 78 size_t limit); 79 #endif 80 81 #if (NXT_HAVE_HPUX_SENDFILE) 82 #define NXT_HAVE_SENDFILE 1 83 ssize_t nxt_hpux_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 84 size_t limit); 85 #endif 86 87 ssize_t nxt_event_conn_io_sendbuf(nxt_event_conn_t *c, nxt_buf_t *b, 88 size_t limit); 89 90 91 nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_task_t *task, 92 nxt_sendbuf_coalesce_t *sb); 93 size_t nxt_sendbuf_file_coalesce(nxt_sendbuf_coalesce_t *sb); 94 95 /* 96 * Auxiliary nxt_sendbuf_copy_coalesce() interface copies small memory 97 * buffers into internal buffer before output. It is intended for 98 * SSL/TLS libraries which lack vector I/O interface yet add noticeable 99 * overhead to each SSL/TLS record. 100 */ 101 ssize_t nxt_sendbuf_copy_coalesce(nxt_event_conn_t *c, nxt_buf_mem_t *bm, 102 nxt_buf_t *b, size_t limit); 103 104 nxt_buf_t *nxt_sendbuf_update(nxt_buf_t *b, size_t sent); 105 nxt_buf_t *nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq, 106 nxt_buf_t *b, size_t sent); 107 108 109 #endif /* _NXT_SENDBUF_H_INCLUDED_ */ 110