10Sigor@sysoev.ru 20Sigor@sysoev.ru /* 30Sigor@sysoev.ru * Copyright (C) Igor Sysoev 40Sigor@sysoev.ru * Copyright (C) NGINX, Inc. 50Sigor@sysoev.ru */ 60Sigor@sysoev.ru 70Sigor@sysoev.ru #ifndef _NXT_SENDBUF_H_INCLUDED_ 80Sigor@sysoev.ru #define _NXT_SENDBUF_H_INCLUDED_ 90Sigor@sysoev.ru 100Sigor@sysoev.ru 110Sigor@sysoev.ru /* 120Sigor@sysoev.ru * The sendbuf interface is intended to send a buffer chain to a connection. 130Sigor@sysoev.ru * It uses sendfile interface if available. Otherwise it can send only 140Sigor@sysoev.ru * memory buffers, so file buffers must be read in memory in advance. 150Sigor@sysoev.ru * 160Sigor@sysoev.ru * The sendbuf interface sets c->socket.write_ready to appropriate state 170Sigor@sysoev.ru * and returns: 180Sigor@sysoev.ru * 190Sigor@sysoev.ru * N > 0 if sendbuf sent N bytes. 200Sigor@sysoev.ru * 210Sigor@sysoev.ru * 0 if sendbuf was interrupted (EINTR and so on), 220Sigor@sysoev.ru * or sendbuf sent previously buffered data, 230Sigor@sysoev.ru * or single sync buffer has been encountered. 240Sigor@sysoev.ru * In all these cases sendbuf is ready to continue 250Sigor@sysoev.ru * operation, unless c->socket.write_ready is cleared. 260Sigor@sysoev.ru * 270Sigor@sysoev.ru * NXT_AGAIN if sendbuf did not send any bytes. 280Sigor@sysoev.ru * 290Sigor@sysoev.ru * NXT_ERROR if there was erorr. 300Sigor@sysoev.ru * 310Sigor@sysoev.ru * The sendbuf limit is size_t type since size_t is large enough and many 320Sigor@sysoev.ru * sendfile implementations do not support anyway sending more than size_t 330Sigor@sysoev.ru * at once. The limit support is located at the sendbuf level otherwise 340Sigor@sysoev.ru * an additional limited chain must be created on each sendbuf call. 350Sigor@sysoev.ru */ 360Sigor@sysoev.ru 370Sigor@sysoev.ru 380Sigor@sysoev.ru typedef struct { 39*13Sigor@sysoev.ru nxt_buf_t *buf; 40*13Sigor@sysoev.ru nxt_socket_t socket; 41*13Sigor@sysoev.ru nxt_err_t error; 42*13Sigor@sysoev.ru nxt_off_t sent; 43*13Sigor@sysoev.ru size_t size; 44*13Sigor@sysoev.ru size_t limit; 45*13Sigor@sysoev.ru 46*13Sigor@sysoev.ru uint8_t ready; /* 1 bit */ 47*13Sigor@sysoev.ru uint8_t once; /* 1 bit */ 48*13Sigor@sysoev.ru uint8_t sync; /* 1 bit */ 49*13Sigor@sysoev.ru uint8_t last; /* 1 bit */ 50*13Sigor@sysoev.ru } nxt_sendbuf_t; 51*13Sigor@sysoev.ru 52*13Sigor@sysoev.ru 53*13Sigor@sysoev.ru typedef struct { 540Sigor@sysoev.ru nxt_buf_t *buf; 550Sigor@sysoev.ru nxt_iobuf_t *iobuf; 560Sigor@sysoev.ru 570Sigor@sysoev.ru uint32_t nmax; 580Sigor@sysoev.ru uint8_t sync; /* 1 bit */ 590Sigor@sysoev.ru uint8_t last; /* 1 bit */ 600Sigor@sysoev.ru 610Sigor@sysoev.ru size_t size; 620Sigor@sysoev.ru size_t limit; 630Sigor@sysoev.ru } nxt_sendbuf_coalesce_t; 640Sigor@sysoev.ru 650Sigor@sysoev.ru 660Sigor@sysoev.ru #if (NXT_HAVE_LINUX_SENDFILE) 670Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 680Sigor@sysoev.ru ssize_t nxt_linux_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 690Sigor@sysoev.ru size_t limit); 700Sigor@sysoev.ru #endif 710Sigor@sysoev.ru 720Sigor@sysoev.ru #if (NXT_HAVE_FREEBSD_SENDFILE) 730Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 740Sigor@sysoev.ru ssize_t nxt_freebsd_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 750Sigor@sysoev.ru size_t limit); 760Sigor@sysoev.ru #endif 770Sigor@sysoev.ru 780Sigor@sysoev.ru #if (NXT_HAVE_SOLARIS_SENDFILEV) 790Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 800Sigor@sysoev.ru ssize_t nxt_solaris_event_conn_io_sendfilev(nxt_event_conn_t *c, nxt_buf_t *b, 810Sigor@sysoev.ru size_t limit); 820Sigor@sysoev.ru #endif 830Sigor@sysoev.ru 840Sigor@sysoev.ru #if (NXT_HAVE_MACOSX_SENDFILE) 850Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 860Sigor@sysoev.ru ssize_t nxt_macosx_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 870Sigor@sysoev.ru size_t limit); 880Sigor@sysoev.ru #endif 890Sigor@sysoev.ru 900Sigor@sysoev.ru #if (NXT_HAVE_AIX_SEND_FILE) 910Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 920Sigor@sysoev.ru ssize_t nxt_aix_event_conn_io_send_file(nxt_event_conn_t *c, nxt_buf_t *b, 930Sigor@sysoev.ru size_t limit); 940Sigor@sysoev.ru #endif 950Sigor@sysoev.ru 960Sigor@sysoev.ru #if (NXT_HAVE_HPUX_SENDFILE) 970Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 980Sigor@sysoev.ru ssize_t nxt_hpux_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 990Sigor@sysoev.ru size_t limit); 1000Sigor@sysoev.ru #endif 1010Sigor@sysoev.ru 1020Sigor@sysoev.ru ssize_t nxt_event_conn_io_sendbuf(nxt_event_conn_t *c, nxt_buf_t *b, 1030Sigor@sysoev.ru size_t limit); 1040Sigor@sysoev.ru 1050Sigor@sysoev.ru 106*13Sigor@sysoev.ru nxt_uint_t nxt_sendbuf_mem_coalesce0(nxt_task_t *task, nxt_sendbuf_t *sb, 107*13Sigor@sysoev.ru struct iovec *iov, nxt_uint_t niov_max); 1081Sigor@sysoev.ru nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_task_t *task, 1091Sigor@sysoev.ru nxt_sendbuf_coalesce_t *sb); 1100Sigor@sysoev.ru size_t nxt_sendbuf_file_coalesce(nxt_sendbuf_coalesce_t *sb); 1110Sigor@sysoev.ru 1120Sigor@sysoev.ru /* 1130Sigor@sysoev.ru * Auxiliary nxt_sendbuf_copy_coalesce() interface copies small memory 1140Sigor@sysoev.ru * buffers into internal buffer before output. It is intended for 1150Sigor@sysoev.ru * SSL/TLS libraries which lack vector I/O interface yet add noticeable 1160Sigor@sysoev.ru * overhead to each SSL/TLS record. 1170Sigor@sysoev.ru */ 1180Sigor@sysoev.ru ssize_t nxt_sendbuf_copy_coalesce(nxt_event_conn_t *c, nxt_buf_mem_t *bm, 1190Sigor@sysoev.ru nxt_buf_t *b, size_t limit); 1200Sigor@sysoev.ru 1210Sigor@sysoev.ru nxt_buf_t *nxt_sendbuf_update(nxt_buf_t *b, size_t sent); 1221Sigor@sysoev.ru nxt_buf_t *nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq, 1230Sigor@sysoev.ru nxt_buf_t *b, size_t sent); 1240Sigor@sysoev.ru 1250Sigor@sysoev.ru 1260Sigor@sysoev.ru #endif /* _NXT_SENDBUF_H_INCLUDED_ */ 127