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 uint8_t limit_reached; 62 uint8_t nmax_reached; 63 64 size_t size; 65 size_t limit; 66} nxt_sendbuf_coalesce_t; 67 68 69#if (NXT_HAVE_LINUX_SENDFILE) 70#define NXT_HAVE_SENDFILE 1 71ssize_t nxt_linux_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b, 72 size_t limit); 73#endif 74 75#if (NXT_HAVE_FREEBSD_SENDFILE) 76#define NXT_HAVE_SENDFILE 1 77ssize_t nxt_freebsd_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b, 78 size_t limit); 79#endif 80 81#if (NXT_HAVE_SOLARIS_SENDFILEV) 82#define NXT_HAVE_SENDFILE 1 83ssize_t nxt_solaris_event_conn_io_sendfilev(nxt_conn_t *c, nxt_buf_t *b, 84 size_t limit); 85#endif 86 87#if (NXT_HAVE_MACOSX_SENDFILE) 88#define NXT_HAVE_SENDFILE 1 89ssize_t nxt_macosx_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b, 90 size_t limit); 91#endif 92 93#if (NXT_HAVE_AIX_SEND_FILE) 94#define NXT_HAVE_SENDFILE 1 95ssize_t nxt_aix_event_conn_io_send_file(nxt_conn_t *c, nxt_buf_t *b, 96 size_t limit); 97#endif 98 99#if (NXT_HAVE_HPUX_SENDFILE) 100#define NXT_HAVE_SENDFILE 1 101ssize_t nxt_hpux_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b, 102 size_t limit); 103#endif 104 105ssize_t nxt_event_conn_io_sendbuf(nxt_conn_t *c, nxt_buf_t *b, 106 size_t limit); 107 108 109nxt_uint_t nxt_sendbuf_mem_coalesce0(nxt_task_t *task, nxt_sendbuf_t *sb, 110 struct iovec *iov, nxt_uint_t niov_max); 111nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_task_t *task, 112 nxt_sendbuf_coalesce_t *sb); 113size_t nxt_sendbuf_file_coalesce(nxt_sendbuf_coalesce_t *sb); 114 115/* 116 * Auxiliary nxt_sendbuf_copy_coalesce() interface copies small memory 117 * buffers into internal buffer before output. It is intended for 118 * SSL/TLS libraries which lack vector I/O interface yet add noticeable 119 * overhead to each SSL/TLS record. 120 */ 121ssize_t nxt_sendbuf_copy_coalesce(nxt_conn_t *c, nxt_buf_mem_t *bm, 122 nxt_buf_t *b, size_t limit); 123 124nxt_buf_t *nxt_sendbuf_update(nxt_buf_t *b, size_t sent); 125nxt_buf_t *nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq, 126 nxt_buf_t *b, size_t sent, nxt_bool_t mmap_mode);
| 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 uint8_t limit_reached; 62 uint8_t nmax_reached; 63 64 size_t size; 65 size_t limit; 66} nxt_sendbuf_coalesce_t; 67 68 69#if (NXT_HAVE_LINUX_SENDFILE) 70#define NXT_HAVE_SENDFILE 1 71ssize_t nxt_linux_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b, 72 size_t limit); 73#endif 74 75#if (NXT_HAVE_FREEBSD_SENDFILE) 76#define NXT_HAVE_SENDFILE 1 77ssize_t nxt_freebsd_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b, 78 size_t limit); 79#endif 80 81#if (NXT_HAVE_SOLARIS_SENDFILEV) 82#define NXT_HAVE_SENDFILE 1 83ssize_t nxt_solaris_event_conn_io_sendfilev(nxt_conn_t *c, nxt_buf_t *b, 84 size_t limit); 85#endif 86 87#if (NXT_HAVE_MACOSX_SENDFILE) 88#define NXT_HAVE_SENDFILE 1 89ssize_t nxt_macosx_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b, 90 size_t limit); 91#endif 92 93#if (NXT_HAVE_AIX_SEND_FILE) 94#define NXT_HAVE_SENDFILE 1 95ssize_t nxt_aix_event_conn_io_send_file(nxt_conn_t *c, nxt_buf_t *b, 96 size_t limit); 97#endif 98 99#if (NXT_HAVE_HPUX_SENDFILE) 100#define NXT_HAVE_SENDFILE 1 101ssize_t nxt_hpux_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b, 102 size_t limit); 103#endif 104 105ssize_t nxt_event_conn_io_sendbuf(nxt_conn_t *c, nxt_buf_t *b, 106 size_t limit); 107 108 109nxt_uint_t nxt_sendbuf_mem_coalesce0(nxt_task_t *task, nxt_sendbuf_t *sb, 110 struct iovec *iov, nxt_uint_t niov_max); 111nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_task_t *task, 112 nxt_sendbuf_coalesce_t *sb); 113size_t nxt_sendbuf_file_coalesce(nxt_sendbuf_coalesce_t *sb); 114 115/* 116 * Auxiliary nxt_sendbuf_copy_coalesce() interface copies small memory 117 * buffers into internal buffer before output. It is intended for 118 * SSL/TLS libraries which lack vector I/O interface yet add noticeable 119 * overhead to each SSL/TLS record. 120 */ 121ssize_t nxt_sendbuf_copy_coalesce(nxt_conn_t *c, nxt_buf_mem_t *bm, 122 nxt_buf_t *b, size_t limit); 123 124nxt_buf_t *nxt_sendbuf_update(nxt_buf_t *b, size_t sent); 125nxt_buf_t *nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq, 126 nxt_buf_t *b, size_t sent, nxt_bool_t mmap_mode);
|