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 { 390Sigor@sysoev.ru nxt_buf_t *buf; 400Sigor@sysoev.ru nxt_iobuf_t *iobuf; 410Sigor@sysoev.ru 420Sigor@sysoev.ru uint32_t nmax; 430Sigor@sysoev.ru uint8_t sync; /* 1 bit */ 440Sigor@sysoev.ru uint8_t last; /* 1 bit */ 450Sigor@sysoev.ru 460Sigor@sysoev.ru size_t size; 470Sigor@sysoev.ru size_t limit; 480Sigor@sysoev.ru } nxt_sendbuf_coalesce_t; 490Sigor@sysoev.ru 500Sigor@sysoev.ru 510Sigor@sysoev.ru #if (NXT_HAVE_LINUX_SENDFILE) 520Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 530Sigor@sysoev.ru ssize_t nxt_linux_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 540Sigor@sysoev.ru size_t limit); 550Sigor@sysoev.ru #endif 560Sigor@sysoev.ru 570Sigor@sysoev.ru #if (NXT_HAVE_FREEBSD_SENDFILE) 580Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 590Sigor@sysoev.ru ssize_t nxt_freebsd_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 600Sigor@sysoev.ru size_t limit); 610Sigor@sysoev.ru #endif 620Sigor@sysoev.ru 630Sigor@sysoev.ru #if (NXT_HAVE_SOLARIS_SENDFILEV) 640Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 650Sigor@sysoev.ru ssize_t nxt_solaris_event_conn_io_sendfilev(nxt_event_conn_t *c, nxt_buf_t *b, 660Sigor@sysoev.ru size_t limit); 670Sigor@sysoev.ru #endif 680Sigor@sysoev.ru 690Sigor@sysoev.ru #if (NXT_HAVE_MACOSX_SENDFILE) 700Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 710Sigor@sysoev.ru ssize_t nxt_macosx_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 720Sigor@sysoev.ru size_t limit); 730Sigor@sysoev.ru #endif 740Sigor@sysoev.ru 750Sigor@sysoev.ru #if (NXT_HAVE_AIX_SEND_FILE) 760Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 770Sigor@sysoev.ru ssize_t nxt_aix_event_conn_io_send_file(nxt_event_conn_t *c, nxt_buf_t *b, 780Sigor@sysoev.ru size_t limit); 790Sigor@sysoev.ru #endif 800Sigor@sysoev.ru 810Sigor@sysoev.ru #if (NXT_HAVE_HPUX_SENDFILE) 820Sigor@sysoev.ru #define NXT_HAVE_SENDFILE 1 830Sigor@sysoev.ru ssize_t nxt_hpux_event_conn_io_sendfile(nxt_event_conn_t *c, nxt_buf_t *b, 840Sigor@sysoev.ru size_t limit); 850Sigor@sysoev.ru #endif 860Sigor@sysoev.ru 870Sigor@sysoev.ru ssize_t nxt_event_conn_io_sendbuf(nxt_event_conn_t *c, nxt_buf_t *b, 880Sigor@sysoev.ru size_t limit); 890Sigor@sysoev.ru 900Sigor@sysoev.ru 91*1Sigor@sysoev.ru nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_task_t *task, 92*1Sigor@sysoev.ru nxt_sendbuf_coalesce_t *sb); 930Sigor@sysoev.ru size_t nxt_sendbuf_file_coalesce(nxt_sendbuf_coalesce_t *sb); 940Sigor@sysoev.ru 950Sigor@sysoev.ru /* 960Sigor@sysoev.ru * Auxiliary nxt_sendbuf_copy_coalesce() interface copies small memory 970Sigor@sysoev.ru * buffers into internal buffer before output. It is intended for 980Sigor@sysoev.ru * SSL/TLS libraries which lack vector I/O interface yet add noticeable 990Sigor@sysoev.ru * overhead to each SSL/TLS record. 1000Sigor@sysoev.ru */ 1010Sigor@sysoev.ru ssize_t nxt_sendbuf_copy_coalesce(nxt_event_conn_t *c, nxt_buf_mem_t *bm, 1020Sigor@sysoev.ru nxt_buf_t *b, size_t limit); 1030Sigor@sysoev.ru 1040Sigor@sysoev.ru nxt_buf_t *nxt_sendbuf_update(nxt_buf_t *b, size_t sent); 105*1Sigor@sysoev.ru nxt_buf_t *nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq, 1060Sigor@sysoev.ru nxt_buf_t *b, size_t sent); 1070Sigor@sysoev.ru 1080Sigor@sysoev.ru 1090Sigor@sysoev.ru #endif /* _NXT_SENDBUF_H_INCLUDED_ */ 110