xref: /unit/src/nxt_sendbuf.h (revision 431)
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 {
3913Sigor@sysoev.ru     nxt_buf_t     *buf;
4013Sigor@sysoev.ru     nxt_socket_t  socket;
4113Sigor@sysoev.ru     nxt_err_t     error;
4213Sigor@sysoev.ru     nxt_off_t     sent;
4313Sigor@sysoev.ru     size_t        size;
4413Sigor@sysoev.ru     size_t        limit;
4513Sigor@sysoev.ru 
4613Sigor@sysoev.ru     uint8_t       ready;   /* 1 bit */
4713Sigor@sysoev.ru     uint8_t       once;    /* 1 bit */
4813Sigor@sysoev.ru     uint8_t       sync;    /* 1 bit */
4913Sigor@sysoev.ru     uint8_t       last;    /* 1 bit */
5013Sigor@sysoev.ru } nxt_sendbuf_t;
5113Sigor@sysoev.ru 
5213Sigor@sysoev.ru 
5313Sigor@sysoev.ru typedef struct {
540Sigor@sysoev.ru     nxt_buf_t    *buf;
550Sigor@sysoev.ru     nxt_iobuf_t  *iobuf;
5642Smax.romanov@nginx.com     nxt_uint_t   niov;
570Sigor@sysoev.ru 
580Sigor@sysoev.ru     uint32_t     nmax;
590Sigor@sysoev.ru     uint8_t      sync;   /* 1 bit */
600Sigor@sysoev.ru     uint8_t      last;   /* 1 bit */
61352Smax.romanov@nginx.com     uint8_t      limit_reached;
62352Smax.romanov@nginx.com     uint8_t      nmax_reached;
630Sigor@sysoev.ru 
640Sigor@sysoev.ru     size_t       size;
650Sigor@sysoev.ru     size_t       limit;
660Sigor@sysoev.ru } nxt_sendbuf_coalesce_t;
670Sigor@sysoev.ru 
680Sigor@sysoev.ru 
690Sigor@sysoev.ru #if (NXT_HAVE_LINUX_SENDFILE)
700Sigor@sysoev.ru #define NXT_HAVE_SENDFILE  1
7162Sigor@sysoev.ru ssize_t nxt_linux_event_conn_io_sendfile(nxt_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_FREEBSD_SENDFILE)
760Sigor@sysoev.ru #define NXT_HAVE_SENDFILE  1
7762Sigor@sysoev.ru ssize_t nxt_freebsd_event_conn_io_sendfile(nxt_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_SOLARIS_SENDFILEV)
820Sigor@sysoev.ru #define NXT_HAVE_SENDFILE  1
8362Sigor@sysoev.ru ssize_t nxt_solaris_event_conn_io_sendfilev(nxt_conn_t *c, nxt_buf_t *b,
840Sigor@sysoev.ru     size_t limit);
850Sigor@sysoev.ru #endif
860Sigor@sysoev.ru 
870Sigor@sysoev.ru #if (NXT_HAVE_MACOSX_SENDFILE)
880Sigor@sysoev.ru #define NXT_HAVE_SENDFILE  1
8962Sigor@sysoev.ru ssize_t nxt_macosx_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b,
900Sigor@sysoev.ru     size_t limit);
910Sigor@sysoev.ru #endif
920Sigor@sysoev.ru 
930Sigor@sysoev.ru #if (NXT_HAVE_AIX_SEND_FILE)
940Sigor@sysoev.ru #define NXT_HAVE_SENDFILE  1
9562Sigor@sysoev.ru ssize_t nxt_aix_event_conn_io_send_file(nxt_conn_t *c, nxt_buf_t *b,
960Sigor@sysoev.ru     size_t limit);
970Sigor@sysoev.ru #endif
980Sigor@sysoev.ru 
990Sigor@sysoev.ru #if (NXT_HAVE_HPUX_SENDFILE)
1000Sigor@sysoev.ru #define NXT_HAVE_SENDFILE  1
10162Sigor@sysoev.ru ssize_t nxt_hpux_event_conn_io_sendfile(nxt_conn_t *c, nxt_buf_t *b,
1020Sigor@sysoev.ru     size_t limit);
1030Sigor@sysoev.ru #endif
1040Sigor@sysoev.ru 
10562Sigor@sysoev.ru ssize_t nxt_event_conn_io_sendbuf(nxt_conn_t *c, nxt_buf_t *b,
1060Sigor@sysoev.ru     size_t limit);
1070Sigor@sysoev.ru 
1080Sigor@sysoev.ru 
10913Sigor@sysoev.ru nxt_uint_t nxt_sendbuf_mem_coalesce0(nxt_task_t *task, nxt_sendbuf_t *sb,
11013Sigor@sysoev.ru     struct iovec *iov, nxt_uint_t niov_max);
1111Sigor@sysoev.ru nxt_uint_t nxt_sendbuf_mem_coalesce(nxt_task_t *task,
1121Sigor@sysoev.ru     nxt_sendbuf_coalesce_t *sb);
1130Sigor@sysoev.ru size_t nxt_sendbuf_file_coalesce(nxt_sendbuf_coalesce_t *sb);
1140Sigor@sysoev.ru 
1150Sigor@sysoev.ru /*
1160Sigor@sysoev.ru  * Auxiliary nxt_sendbuf_copy_coalesce() interface copies small memory
1170Sigor@sysoev.ru  * buffers into internal buffer before output.  It is intended for
1180Sigor@sysoev.ru  * SSL/TLS libraries which lack vector I/O interface yet add noticeable
1190Sigor@sysoev.ru  * overhead to each SSL/TLS record.
1200Sigor@sysoev.ru  */
12162Sigor@sysoev.ru ssize_t nxt_sendbuf_copy_coalesce(nxt_conn_t *c, nxt_buf_mem_t *bm,
1220Sigor@sysoev.ru     nxt_buf_t *b, size_t limit);
1230Sigor@sysoev.ru 
1240Sigor@sysoev.ru nxt_buf_t *nxt_sendbuf_update(nxt_buf_t *b, size_t sent);
1251Sigor@sysoev.ru nxt_buf_t *nxt_sendbuf_completion(nxt_task_t *task, nxt_work_queue_t *wq,
126203Smax.romanov@nginx.com     nxt_buf_t *b, size_t sent, nxt_bool_t mmap_mode);
127*431Sigor@sysoev.ru nxt_buf_t *nxt_sendbuf_completion0(nxt_task_t *task, nxt_work_queue_t *wq,
128*431Sigor@sysoev.ru     nxt_buf_t *b);
1290Sigor@sysoev.ru 
1300Sigor@sysoev.ru 
1310Sigor@sysoev.ru #endif /* _NXT_SENDBUF_H_INCLUDED_ */
132