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 38typedef struct { 39 nxt_buf_t *buf; 40 nxt_socket_t socket; 41 nxt_err_t error; 42 nxt_off_t sent; 43 size_t size; 44 size_t limit; 45 46 uint8_t ready; /* 1 bit */ 47 uint8_t once; /* 1 bit */ 48 uint8_t sync; /* 1 bit */ 49 uint8_t last; /* 1 bit */ 50} nxt_sendbuf_t; 51 52 53typedef struct { 54 nxt_buf_t *buf; 55 nxt_iobuf_t *iobuf; 56 nxt_uint_t niov; 57 58 uint32_t nmax; 59 uint8_t sync; /* 1 bit */ 60 uint8_t last; /* 1 bit */ 61 62 size_t size; 63 size_t limit; 64} nxt_sendbuf_coalesce_t; 65 66 67#if (NXT_HAVE_LINUX_SENDFILE) 68#define NXT_HAVE_SENDFILE 1
| 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 38typedef struct { 39 nxt_buf_t *buf; 40 nxt_socket_t socket; 41 nxt_err_t error; 42 nxt_off_t sent; 43 size_t size; 44 size_t limit; 45 46 uint8_t ready; /* 1 bit */ 47 uint8_t once; /* 1 bit */ 48 uint8_t sync; /* 1 bit */ 49 uint8_t last; /* 1 bit */ 50} nxt_sendbuf_t; 51 52 53typedef struct { 54 nxt_buf_t *buf; 55 nxt_iobuf_t *iobuf; 56 nxt_uint_t niov; 57 58 uint32_t nmax; 59 uint8_t sync; /* 1 bit */ 60 uint8_t last; /* 1 bit */ 61 62 size_t size; 63 size_t limit; 64} nxt_sendbuf_coalesce_t; 65 66 67#if (NXT_HAVE_LINUX_SENDFILE) 68#define NXT_HAVE_SENDFILE 1
|
69ssize_t nxt_linux_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b,
| 69ssize_t nxt_linux_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b,
|
70 size_t limit); 71#endif 72 73#if (NXT_HAVE_FREEBSD_SENDFILE) 74#define NXT_HAVE_SENDFILE 1
| 70 size_t limit); 71#endif 72 73#if (NXT_HAVE_FREEBSD_SENDFILE) 74#define NXT_HAVE_SENDFILE 1
|
75ssize_t nxt_freebsd_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b,
| 75ssize_t nxt_freebsd_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b,
|
76 size_t limit); 77#endif 78 79#if (NXT_HAVE_SOLARIS_SENDFILEV) 80#define NXT_HAVE_SENDFILE 1
| 76 size_t limit); 77#endif 78 79#if (NXT_HAVE_SOLARIS_SENDFILEV) 80#define NXT_HAVE_SENDFILE 1
|
81ssize_t nxt_solaris_event_conn_io_sendfilev(nxt_event_conn_t *c, nxt_buf_t *b,
| 81ssize_t nxt_solaris_event_conn_io_sendfilev(nxt_conn_t *c, nxt_buf_t *b,
|
82 size_t limit); 83#endif 84 85#if (NXT_HAVE_MACOSX_SENDFILE) 86#define NXT_HAVE_SENDFILE 1
| 82 size_t limit); 83#endif 84 85#if (NXT_HAVE_MACOSX_SENDFILE) 86#define NXT_HAVE_SENDFILE 1
|
87ssize_t nxt_macosx_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b,
| 87ssize_t nxt_macosx_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b,
|
88 size_t limit); 89#endif 90 91#if (NXT_HAVE_AIX_SEND_FILE) 92#define NXT_HAVE_SENDFILE 1
| 88 size_t limit); 89#endif 90 91#if (NXT_HAVE_AIX_SEND_FILE) 92#define NXT_HAVE_SENDFILE 1
|
93ssize_t nxt_aix_event_conn_io_send_file(nxt_event_conn_t *c, nxt_buf_t *b,
| 93ssize_t nxt_aix_event_conn_io_send_file(nxt_conn_t *c, nxt_buf_t *b,
|
94 size_t limit); 95#endif 96 97#if (NXT_HAVE_HPUX_SENDFILE) 98#define NXT_HAVE_SENDFILE 1
| 94 size_t limit); 95#endif 96 97#if (NXT_HAVE_HPUX_SENDFILE) 98#define NXT_HAVE_SENDFILE 1
|
99ssize_t nxt_hpux_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b,
| 99ssize_t nxt_hpux_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b,
|
100 size_t limit); 101#endif 102
| 100 size_t limit); 101#endif 102
|
103ssize_t nxt_event_conn_io_sendbuf(nxt_event_conn_t *c, nxt_buf_t *b,
| 103ssize_t nxt_event_conn_io_sendbuf(nxt_conn_t *c, nxt_buf_t *b,
|
104 size_t limit); 105 106 107nxt_uint_t nxt_sendbuf_mem_coalesce0(nxt_task_t *task, nxt_sendbuf_t *sb, 108 struct iovec *iov, nxt_uint_t niov_max); 109nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_task_t *task, 110 nxt_sendbuf_coalesce_t *sb); 111size_t nxt_sendbuf_file_coalesce(nxt_sendbuf_coalesce_t *sb); 112 113/* 114 * Auxiliary nxt_sendbuf_copy_coalesce() interface copies small memory 115 * buffers into internal buffer before output. It is intended for 116 * SSL/TLS libraries which lack vector I/O interface yet add noticeable 117 * overhead to each SSL/TLS record. 118 */
| 104 size_t limit); 105 106 107nxt_uint_t nxt_sendbuf_mem_coalesce0(nxt_task_t *task, nxt_sendbuf_t *sb, 108 struct iovec *iov, nxt_uint_t niov_max); 109nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_task_t *task, 110 nxt_sendbuf_coalesce_t *sb); 111size_t nxt_sendbuf_file_coalesce(nxt_sendbuf_coalesce_t *sb); 112 113/* 114 * Auxiliary nxt_sendbuf_copy_coalesce() interface copies small memory 115 * buffers into internal buffer before output. It is intended for 116 * SSL/TLS libraries which lack vector I/O interface yet add noticeable 117 * overhead to each SSL/TLS record. 118 */
|
119ssize_t nxt_sendbuf_copy_coalesce(nxt_event_conn_t *c, nxt_buf_mem_t *bm,
| 119ssize_t nxt_sendbuf_copy_coalesce(nxt_conn_t *c, nxt_buf_mem_t *bm,
|
120 nxt_buf_t *b, size_t limit); 121 122nxt_buf_t *nxt_sendbuf_update(nxt_buf_t *b, size_t sent); 123nxt_buf_t *nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq, 124 nxt_buf_t *b, size_t sent); 125 126 127#endif /* _NXT_SENDBUF_H_INCLUDED_ */
| 120 nxt_buf_t *b, size_t limit); 121 122nxt_buf_t *nxt_sendbuf_update(nxt_buf_t *b, size_t sent); 123nxt_buf_t *nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq, 124 nxt_buf_t *b, size_t sent); 125 126 127#endif /* _NXT_SENDBUF_H_INCLUDED_ */
|