xref: /unit/src/nxt_unit.h (revision 1403)
1743Smax.romanov@nginx.com 
2743Smax.romanov@nginx.com /*
3743Smax.romanov@nginx.com  * Copyright (C) NGINX, Inc.
4743Smax.romanov@nginx.com  */
5743Smax.romanov@nginx.com 
6743Smax.romanov@nginx.com #ifndef _NXT_UNIT_H_INCLUDED_
7743Smax.romanov@nginx.com #define _NXT_UNIT_H_INCLUDED_
8743Smax.romanov@nginx.com 
9743Smax.romanov@nginx.com 
10743Smax.romanov@nginx.com #include <inttypes.h>
11743Smax.romanov@nginx.com #include <sys/types.h>
121131Smax.romanov@nginx.com #include <sys/uio.h>
13743Smax.romanov@nginx.com #include <string.h>
14743Smax.romanov@nginx.com 
15953Salexander.borisov@nginx.com #include "nxt_version.h"
16743Smax.romanov@nginx.com #include "nxt_unit_typedefs.h"
17743Smax.romanov@nginx.com 
18877Salexander.borisov@nginx.com 
19743Smax.romanov@nginx.com enum {
20743Smax.romanov@nginx.com     NXT_UNIT_OK          = 0,
21743Smax.romanov@nginx.com     NXT_UNIT_ERROR       = 1,
22743Smax.romanov@nginx.com };
23743Smax.romanov@nginx.com 
24743Smax.romanov@nginx.com enum {
25743Smax.romanov@nginx.com     NXT_UNIT_LOG_ALERT   = 0,
26743Smax.romanov@nginx.com     NXT_UNIT_LOG_ERR     = 1,
27743Smax.romanov@nginx.com     NXT_UNIT_LOG_WARN    = 2,
28743Smax.romanov@nginx.com     NXT_UNIT_LOG_NOTICE  = 3,
29743Smax.romanov@nginx.com     NXT_UNIT_LOG_INFO    = 4,
30743Smax.romanov@nginx.com     NXT_UNIT_LOG_DEBUG   = 5,
31743Smax.romanov@nginx.com };
32743Smax.romanov@nginx.com 
33743Smax.romanov@nginx.com #define NXT_UNIT_INIT_ENV  "NXT_UNIT_INIT"
34743Smax.romanov@nginx.com 
35743Smax.romanov@nginx.com /*
36743Smax.romanov@nginx.com  * Mostly opaque structure with library state.
37743Smax.romanov@nginx.com  *
38743Smax.romanov@nginx.com  * Only user defined 'data' pointer exposed here.  The rest is unit
39743Smax.romanov@nginx.com  * implementation specific and hidden.
40743Smax.romanov@nginx.com  */
41743Smax.romanov@nginx.com struct nxt_unit_s {
42743Smax.romanov@nginx.com     void                  *data;  /* User defined data. */
43743Smax.romanov@nginx.com };
44743Smax.romanov@nginx.com 
45743Smax.romanov@nginx.com /*
46743Smax.romanov@nginx.com  * Thread context.
47743Smax.romanov@nginx.com  *
48743Smax.romanov@nginx.com  * First (main) context is provided 'for free'.  To receive and process
49743Smax.romanov@nginx.com  * requests in other thread, one need to allocate context and use it
50743Smax.romanov@nginx.com  * further in this thread.
51743Smax.romanov@nginx.com  */
52743Smax.romanov@nginx.com struct nxt_unit_ctx_s {
53743Smax.romanov@nginx.com     void                  *data;  /* User context-specific data. */
54743Smax.romanov@nginx.com     nxt_unit_t            *unit;
55743Smax.romanov@nginx.com };
56743Smax.romanov@nginx.com 
57743Smax.romanov@nginx.com /*
58743Smax.romanov@nginx.com  * Unit port identification structure.
59743Smax.romanov@nginx.com  *
60743Smax.romanov@nginx.com  * Each port can be uniquely identified by listen process id (pid) and port id.
61743Smax.romanov@nginx.com  * This identification is required to refer the port from different process.
62743Smax.romanov@nginx.com  */
63743Smax.romanov@nginx.com struct nxt_unit_port_id_s {
64743Smax.romanov@nginx.com     pid_t                 pid;
65743Smax.romanov@nginx.com     uint32_t              hash;
66743Smax.romanov@nginx.com     uint16_t              id;
67743Smax.romanov@nginx.com };
68743Smax.romanov@nginx.com 
69743Smax.romanov@nginx.com /*
70743Smax.romanov@nginx.com  * unit provides port storage which is able to store and find the following
71743Smax.romanov@nginx.com  * data structures.
72743Smax.romanov@nginx.com  */
73743Smax.romanov@nginx.com struct nxt_unit_port_s {
74743Smax.romanov@nginx.com     nxt_unit_port_id_t    id;
75743Smax.romanov@nginx.com 
76743Smax.romanov@nginx.com     int                   in_fd;
77743Smax.romanov@nginx.com     int                   out_fd;
78743Smax.romanov@nginx.com 
79743Smax.romanov@nginx.com     void                  *data;
80743Smax.romanov@nginx.com };
81743Smax.romanov@nginx.com 
82743Smax.romanov@nginx.com 
83743Smax.romanov@nginx.com struct nxt_unit_buf_s {
84743Smax.romanov@nginx.com     char                  *start;
85743Smax.romanov@nginx.com     char                  *free;
86743Smax.romanov@nginx.com     char                  *end;
87743Smax.romanov@nginx.com };
88743Smax.romanov@nginx.com 
89743Smax.romanov@nginx.com 
90743Smax.romanov@nginx.com struct nxt_unit_request_info_s {
91743Smax.romanov@nginx.com     nxt_unit_t            *unit;
92743Smax.romanov@nginx.com     nxt_unit_ctx_t        *ctx;
93743Smax.romanov@nginx.com 
94743Smax.romanov@nginx.com     nxt_unit_port_id_t    request_port;
95743Smax.romanov@nginx.com     nxt_unit_port_id_t    response_port;
96743Smax.romanov@nginx.com 
97743Smax.romanov@nginx.com     nxt_unit_request_t    *request;
98743Smax.romanov@nginx.com     nxt_unit_buf_t        *request_buf;
99743Smax.romanov@nginx.com 
100743Smax.romanov@nginx.com     nxt_unit_response_t   *response;
101743Smax.romanov@nginx.com     nxt_unit_buf_t        *response_buf;
102743Smax.romanov@nginx.com     uint32_t              response_max_fields;
103743Smax.romanov@nginx.com 
104743Smax.romanov@nginx.com     nxt_unit_buf_t        *content_buf;
105743Smax.romanov@nginx.com     uint64_t              content_length;
106*1403Smax.romanov@nginx.com     int                   content_fd;
107743Smax.romanov@nginx.com 
108743Smax.romanov@nginx.com     void                  *data;
109743Smax.romanov@nginx.com };
110743Smax.romanov@nginx.com 
1111131Smax.romanov@nginx.com 
112743Smax.romanov@nginx.com /*
113743Smax.romanov@nginx.com  * Set of application-specific callbacks. Application may leave all optional
114743Smax.romanov@nginx.com  * callbacks as NULL.
115743Smax.romanov@nginx.com  */
116743Smax.romanov@nginx.com struct nxt_unit_callbacks_s {
117743Smax.romanov@nginx.com     /*
1181131Smax.romanov@nginx.com      * Process request. Unlike all other callback, this callback
119743Smax.romanov@nginx.com      * need to be defined by application.
120743Smax.romanov@nginx.com      */
121743Smax.romanov@nginx.com     void     (*request_handler)(nxt_unit_request_info_t *req);
122743Smax.romanov@nginx.com 
1231131Smax.romanov@nginx.com     /* Process websocket frame. */
1241131Smax.romanov@nginx.com     void     (*websocket_handler)(nxt_unit_websocket_frame_t *ws);
1251131Smax.romanov@nginx.com 
1261131Smax.romanov@nginx.com     /* Connection closed. */
1271131Smax.romanov@nginx.com     void     (*close_handler)(nxt_unit_request_info_t *req);
1281131Smax.romanov@nginx.com 
129743Smax.romanov@nginx.com     /* Add new Unit port to communicate with process pid. Optional. */
130743Smax.romanov@nginx.com     int      (*add_port)(nxt_unit_ctx_t *, nxt_unit_port_t *port);
131743Smax.romanov@nginx.com 
132743Smax.romanov@nginx.com     /* Remove previously added port. Optional. */
133743Smax.romanov@nginx.com     void     (*remove_port)(nxt_unit_ctx_t *, nxt_unit_port_id_t *port_id);
134743Smax.romanov@nginx.com 
135743Smax.romanov@nginx.com     /* Remove all data associated with process pid including ports. Optional. */
136743Smax.romanov@nginx.com     void     (*remove_pid)(nxt_unit_ctx_t *, pid_t pid);
137743Smax.romanov@nginx.com 
138743Smax.romanov@nginx.com     /* Gracefully quit the application. Optional. */
139743Smax.romanov@nginx.com     void     (*quit)(nxt_unit_ctx_t *);
140743Smax.romanov@nginx.com 
1411321Smax.romanov@nginx.com     /* Shared memory release acknowledgement. */
1421321Smax.romanov@nginx.com     void     (*shm_ack_handler)(nxt_unit_ctx_t *);
1431321Smax.romanov@nginx.com 
144743Smax.romanov@nginx.com     /* Send data and control to process pid using port id. Optional. */
145743Smax.romanov@nginx.com     ssize_t  (*port_send)(nxt_unit_ctx_t *, nxt_unit_port_id_t *port_id,
146743Smax.romanov@nginx.com                  const void *buf, size_t buf_size,
147743Smax.romanov@nginx.com                  const void *oob, size_t oob_size);
148743Smax.romanov@nginx.com 
149743Smax.romanov@nginx.com     /* Receive data on port id. Optional. */
150743Smax.romanov@nginx.com     ssize_t  (*port_recv)(nxt_unit_ctx_t *, nxt_unit_port_id_t *port_id,
151743Smax.romanov@nginx.com                  void *buf, size_t buf_size, void *oob, size_t oob_size);
152743Smax.romanov@nginx.com 
153743Smax.romanov@nginx.com };
154743Smax.romanov@nginx.com 
155743Smax.romanov@nginx.com 
156743Smax.romanov@nginx.com struct nxt_unit_init_s {
157743Smax.romanov@nginx.com     void                  *data;     /* Opaque pointer to user-defined data. */
158743Smax.romanov@nginx.com     void                  *ctx_data; /* Opaque pointer to user-defined data. */
159743Smax.romanov@nginx.com     int                   max_pending_requests;
160743Smax.romanov@nginx.com 
161743Smax.romanov@nginx.com     uint32_t              request_data_size;
1621320Smax.romanov@nginx.com     uint32_t              shm_limit;
163743Smax.romanov@nginx.com 
164743Smax.romanov@nginx.com     nxt_unit_callbacks_t  callbacks;
165743Smax.romanov@nginx.com 
166743Smax.romanov@nginx.com     nxt_unit_port_t       ready_port;
167743Smax.romanov@nginx.com     uint32_t              ready_stream;
168743Smax.romanov@nginx.com     nxt_unit_port_t       read_port;
169743Smax.romanov@nginx.com     int                   log_fd;
170743Smax.romanov@nginx.com };
171743Smax.romanov@nginx.com 
172743Smax.romanov@nginx.com 
173743Smax.romanov@nginx.com typedef ssize_t (*nxt_unit_read_func_t)(nxt_unit_read_info_t *read_info,
174743Smax.romanov@nginx.com     void *dst, size_t size);
175743Smax.romanov@nginx.com 
176743Smax.romanov@nginx.com 
177743Smax.romanov@nginx.com struct nxt_unit_read_info_s {
178743Smax.romanov@nginx.com     nxt_unit_read_func_t  read;
179743Smax.romanov@nginx.com     int                   eof;
180743Smax.romanov@nginx.com     uint32_t              buf_size;
181743Smax.romanov@nginx.com     void                  *data;
182743Smax.romanov@nginx.com };
183743Smax.romanov@nginx.com 
184743Smax.romanov@nginx.com 
185743Smax.romanov@nginx.com /*
186743Smax.romanov@nginx.com  * Initialize Unit application library with necessary callbacks and
187743Smax.romanov@nginx.com  * ready/reply port parameters, send 'READY' response to master.
188743Smax.romanov@nginx.com  */
189743Smax.romanov@nginx.com nxt_unit_ctx_t *nxt_unit_init(nxt_unit_init_t *);
190743Smax.romanov@nginx.com 
191743Smax.romanov@nginx.com /*
192743Smax.romanov@nginx.com  * Process received message, invoke configured callbacks.
193743Smax.romanov@nginx.com  *
194743Smax.romanov@nginx.com  * If application implements it's own event loop, each datagram received
195743Smax.romanov@nginx.com  * from port socket should be initially processed by unit.  This function
196743Smax.romanov@nginx.com  * may invoke other application-defined callback for message processing.
197743Smax.romanov@nginx.com  */
198743Smax.romanov@nginx.com int nxt_unit_process_msg(nxt_unit_ctx_t *, nxt_unit_port_id_t *port_id,
199743Smax.romanov@nginx.com     void *buf, size_t buf_size, void *oob, size_t oob_size);
200743Smax.romanov@nginx.com 
201743Smax.romanov@nginx.com /*
202743Smax.romanov@nginx.com  * Main function useful in case when application does not have it's own
203743Smax.romanov@nginx.com  * event loop. nxt_unit_run() starts infinite message wait and process loop.
204743Smax.romanov@nginx.com  *
205743Smax.romanov@nginx.com  *  for (;;) {
206743Smax.romanov@nginx.com  *      app_lib->port_recv(...);
207743Smax.romanov@nginx.com  *      nxt_unit_process_msg(...);
208743Smax.romanov@nginx.com  *  }
209743Smax.romanov@nginx.com  *
210743Smax.romanov@nginx.com  * The normally function returns when QUIT message received from Unit.
211743Smax.romanov@nginx.com  */
212743Smax.romanov@nginx.com int nxt_unit_run(nxt_unit_ctx_t *);
213743Smax.romanov@nginx.com 
214828Salexander.borisov@nginx.com int nxt_unit_run_once(nxt_unit_ctx_t *ctx);
215828Salexander.borisov@nginx.com 
216743Smax.romanov@nginx.com /* Destroy application library object. */
217743Smax.romanov@nginx.com void nxt_unit_done(nxt_unit_ctx_t *);
218743Smax.romanov@nginx.com 
219743Smax.romanov@nginx.com /*
220743Smax.romanov@nginx.com  * Allocate and initialize new execution context with new listen port to
221743Smax.romanov@nginx.com  * process requests in other thread.
222743Smax.romanov@nginx.com  */
223743Smax.romanov@nginx.com nxt_unit_ctx_t *nxt_unit_ctx_alloc(nxt_unit_ctx_t *, void *);
224743Smax.romanov@nginx.com 
225743Smax.romanov@nginx.com /* Free unused context.  It is not required to free main context. */
226743Smax.romanov@nginx.com void nxt_unit_ctx_free(nxt_unit_ctx_t *);
227743Smax.romanov@nginx.com 
228743Smax.romanov@nginx.com /* Initialize port_id, calculate hash. */
229743Smax.romanov@nginx.com void nxt_unit_port_id_init(nxt_unit_port_id_t *port_id, pid_t pid, uint16_t id);
230743Smax.romanov@nginx.com 
231743Smax.romanov@nginx.com /*
232743Smax.romanov@nginx.com  * Create extra incoming port, perform all required actions to propogate
233743Smax.romanov@nginx.com  * the port to Unit server.  Fills structure referenced by port_id with
234743Smax.romanov@nginx.com  * current pid and new port id.
235743Smax.romanov@nginx.com  */
236743Smax.romanov@nginx.com int nxt_unit_create_send_port(nxt_unit_ctx_t *, nxt_unit_port_id_t *dst,
237743Smax.romanov@nginx.com     nxt_unit_port_id_t *port_id);
238743Smax.romanov@nginx.com 
239743Smax.romanov@nginx.com /* Default 'add_port' implementation. */
240743Smax.romanov@nginx.com int nxt_unit_add_port(nxt_unit_ctx_t *, nxt_unit_port_t *port);
241743Smax.romanov@nginx.com 
242743Smax.romanov@nginx.com /* Find previously added port. */
243743Smax.romanov@nginx.com nxt_unit_port_t *nxt_unit_find_port(nxt_unit_ctx_t *,
244743Smax.romanov@nginx.com     nxt_unit_port_id_t *port_id);
245743Smax.romanov@nginx.com 
246743Smax.romanov@nginx.com /* Find, fill output 'port' and remove port from storage.  */
247743Smax.romanov@nginx.com void nxt_unit_find_remove_port(nxt_unit_ctx_t *, nxt_unit_port_id_t *port_id,
248743Smax.romanov@nginx.com     nxt_unit_port_t *port);
249743Smax.romanov@nginx.com 
250743Smax.romanov@nginx.com /* Default 'remove_port' implementation. */
251743Smax.romanov@nginx.com void nxt_unit_remove_port(nxt_unit_ctx_t *, nxt_unit_port_id_t *port_id);
252743Smax.romanov@nginx.com 
253743Smax.romanov@nginx.com /* Default 'remove_pid' implementation. */
254743Smax.romanov@nginx.com void nxt_unit_remove_pid(nxt_unit_ctx_t *, pid_t pid);
255743Smax.romanov@nginx.com 
256743Smax.romanov@nginx.com /* Default 'quit' implementation. */
257743Smax.romanov@nginx.com void nxt_unit_quit(nxt_unit_ctx_t *);
258743Smax.romanov@nginx.com 
259743Smax.romanov@nginx.com /* Default 'port_send' implementation. */
260743Smax.romanov@nginx.com ssize_t nxt_unit_port_send(nxt_unit_ctx_t *, int fd,
261743Smax.romanov@nginx.com     const void *buf, size_t buf_size,
262743Smax.romanov@nginx.com     const void *oob, size_t oob_size);
263743Smax.romanov@nginx.com 
264743Smax.romanov@nginx.com /* Default 'port_recv' implementation. */
265743Smax.romanov@nginx.com ssize_t nxt_unit_port_recv(nxt_unit_ctx_t *, int fd, void *buf, size_t buf_size,
266743Smax.romanov@nginx.com     void *oob, size_t oob_size);
267743Smax.romanov@nginx.com 
268743Smax.romanov@nginx.com /* Calculates hash for given field name. */
269743Smax.romanov@nginx.com uint16_t nxt_unit_field_hash(const char* name, size_t name_length);
270743Smax.romanov@nginx.com 
271743Smax.romanov@nginx.com /* Split host for server name and port. */
272743Smax.romanov@nginx.com void nxt_unit_split_host(char *host_start, uint32_t host_length,
273743Smax.romanov@nginx.com     char **name, uint32_t *name_length, char **port, uint32_t *port_length);
274743Smax.romanov@nginx.com 
275743Smax.romanov@nginx.com /* Group duplicate fields for easy enumeration. */
276743Smax.romanov@nginx.com void nxt_unit_request_group_dup_fields(nxt_unit_request_info_t *req);
277743Smax.romanov@nginx.com 
278743Smax.romanov@nginx.com /*
279743Smax.romanov@nginx.com  * Allocate response structure capable to store limited numer of fields.
280743Smax.romanov@nginx.com  * The structure may be accessed directly via req->response pointer or
281743Smax.romanov@nginx.com  * filled step-by-step using functions add_field and add_content.
282743Smax.romanov@nginx.com  */
283743Smax.romanov@nginx.com int nxt_unit_response_init(nxt_unit_request_info_t *req,
284743Smax.romanov@nginx.com     uint16_t status, uint32_t max_fields_count, uint32_t max_fields_size);
285743Smax.romanov@nginx.com 
286743Smax.romanov@nginx.com int nxt_unit_response_realloc(nxt_unit_request_info_t *req,
287743Smax.romanov@nginx.com     uint32_t max_fields_count, uint32_t max_fields_size);
288743Smax.romanov@nginx.com 
289743Smax.romanov@nginx.com int nxt_unit_response_is_init(nxt_unit_request_info_t *req);
290743Smax.romanov@nginx.com 
291743Smax.romanov@nginx.com int nxt_unit_response_add_field(nxt_unit_request_info_t *req,
292743Smax.romanov@nginx.com     const char* name, uint8_t name_length,
293743Smax.romanov@nginx.com     const char* value, uint32_t value_length);
294743Smax.romanov@nginx.com 
295743Smax.romanov@nginx.com int nxt_unit_response_add_content(nxt_unit_request_info_t *req,
296743Smax.romanov@nginx.com     const void* src, uint32_t size);
297743Smax.romanov@nginx.com 
298743Smax.romanov@nginx.com /*
299743Smax.romanov@nginx.com  * Send prepared response to Unit server.  Response structure destroyed during
300743Smax.romanov@nginx.com  * this call.
301743Smax.romanov@nginx.com  */
302743Smax.romanov@nginx.com int nxt_unit_response_send(nxt_unit_request_info_t *req);
303743Smax.romanov@nginx.com 
304743Smax.romanov@nginx.com int nxt_unit_response_is_sent(nxt_unit_request_info_t *req);
305743Smax.romanov@nginx.com 
306743Smax.romanov@nginx.com nxt_unit_buf_t *nxt_unit_response_buf_alloc(nxt_unit_request_info_t *req,
307743Smax.romanov@nginx.com     uint32_t size);
308743Smax.romanov@nginx.com 
3091131Smax.romanov@nginx.com int nxt_unit_request_is_websocket_handshake(nxt_unit_request_info_t *req);
3101131Smax.romanov@nginx.com 
3111131Smax.romanov@nginx.com int nxt_unit_response_upgrade(nxt_unit_request_info_t *req);
3121131Smax.romanov@nginx.com 
3131131Smax.romanov@nginx.com int nxt_unit_response_is_websocket(nxt_unit_request_info_t *req);
3141131Smax.romanov@nginx.com 
3151131Smax.romanov@nginx.com nxt_unit_request_info_t *nxt_unit_get_request_info_from_data(void *data);
3161131Smax.romanov@nginx.com 
317743Smax.romanov@nginx.com int nxt_unit_buf_send(nxt_unit_buf_t *buf);
318743Smax.romanov@nginx.com 
319743Smax.romanov@nginx.com void nxt_unit_buf_free(nxt_unit_buf_t *buf);
320743Smax.romanov@nginx.com 
321743Smax.romanov@nginx.com nxt_unit_buf_t *nxt_unit_buf_next(nxt_unit_buf_t *buf);
322743Smax.romanov@nginx.com 
323743Smax.romanov@nginx.com uint32_t nxt_unit_buf_max(void);
324743Smax.romanov@nginx.com 
325743Smax.romanov@nginx.com uint32_t nxt_unit_buf_min(void);
326743Smax.romanov@nginx.com 
327743Smax.romanov@nginx.com int nxt_unit_response_write(nxt_unit_request_info_t *req, const void *start,
328743Smax.romanov@nginx.com     size_t size);
329743Smax.romanov@nginx.com 
3301321Smax.romanov@nginx.com ssize_t nxt_unit_response_write_nb(nxt_unit_request_info_t *req,
3311321Smax.romanov@nginx.com     const void *start, size_t size, size_t min_size);
3321321Smax.romanov@nginx.com 
333743Smax.romanov@nginx.com int nxt_unit_response_write_cb(nxt_unit_request_info_t *req,
334743Smax.romanov@nginx.com     nxt_unit_read_info_t *read_info);
335743Smax.romanov@nginx.com 
336743Smax.romanov@nginx.com ssize_t nxt_unit_request_read(nxt_unit_request_info_t *req, void *dst,
337743Smax.romanov@nginx.com     size_t size);
338743Smax.romanov@nginx.com 
3391398Smax.romanov@nginx.com ssize_t nxt_unit_request_readline_size(nxt_unit_request_info_t *req,
3401398Smax.romanov@nginx.com     size_t max_size);
3411398Smax.romanov@nginx.com 
342743Smax.romanov@nginx.com void nxt_unit_request_done(nxt_unit_request_info_t *req, int rc);
343743Smax.romanov@nginx.com 
344743Smax.romanov@nginx.com 
3451131Smax.romanov@nginx.com int nxt_unit_websocket_send(nxt_unit_request_info_t *req, uint8_t opcode,
3461131Smax.romanov@nginx.com     uint8_t last, const void *start, size_t size);
3471131Smax.romanov@nginx.com 
3481131Smax.romanov@nginx.com int nxt_unit_websocket_sendv(nxt_unit_request_info_t *req, uint8_t opcode,
3491131Smax.romanov@nginx.com     uint8_t last, const struct iovec *iov, int iovcnt);
3501131Smax.romanov@nginx.com 
3511131Smax.romanov@nginx.com ssize_t nxt_unit_websocket_read(nxt_unit_websocket_frame_t *ws, void *dst,
3521131Smax.romanov@nginx.com     size_t size);
3531131Smax.romanov@nginx.com 
3541131Smax.romanov@nginx.com int nxt_unit_websocket_retain(nxt_unit_websocket_frame_t *ws);
3551131Smax.romanov@nginx.com 
3561131Smax.romanov@nginx.com void nxt_unit_websocket_done(nxt_unit_websocket_frame_t *ws);
3571131Smax.romanov@nginx.com 
3581131Smax.romanov@nginx.com 
359743Smax.romanov@nginx.com void nxt_unit_log(nxt_unit_ctx_t *ctx, int level, const char* fmt, ...);
360743Smax.romanov@nginx.com 
361743Smax.romanov@nginx.com void nxt_unit_req_log(nxt_unit_request_info_t *req, int level,
362743Smax.romanov@nginx.com     const char* fmt, ...);
363743Smax.romanov@nginx.com 
364743Smax.romanov@nginx.com #if (NXT_DEBUG)
365743Smax.romanov@nginx.com 
366743Smax.romanov@nginx.com #define nxt_unit_debug(ctx, fmt, ARGS...) \
367743Smax.romanov@nginx.com     nxt_unit_log(ctx, NXT_UNIT_LOG_DEBUG, fmt, ##ARGS)
368743Smax.romanov@nginx.com 
369743Smax.romanov@nginx.com #define nxt_unit_req_debug(req, fmt, ARGS...) \
370743Smax.romanov@nginx.com     nxt_unit_req_log(req, NXT_UNIT_LOG_DEBUG, fmt, ##ARGS)
371743Smax.romanov@nginx.com 
372743Smax.romanov@nginx.com #else
373743Smax.romanov@nginx.com 
374743Smax.romanov@nginx.com #define nxt_unit_debug(ctx, fmt, ARGS...)
375743Smax.romanov@nginx.com 
376743Smax.romanov@nginx.com #define nxt_unit_req_debug(req, fmt, ARGS...)
377743Smax.romanov@nginx.com 
378743Smax.romanov@nginx.com #endif
379743Smax.romanov@nginx.com 
380743Smax.romanov@nginx.com 
381743Smax.romanov@nginx.com #define nxt_unit_warn(ctx, fmt, ARGS...) \
382743Smax.romanov@nginx.com     nxt_unit_log(ctx, NXT_UNIT_LOG_WARN, fmt, ##ARGS)
383743Smax.romanov@nginx.com 
384743Smax.romanov@nginx.com #define nxt_unit_req_warn(req, fmt, ARGS...) \
385743Smax.romanov@nginx.com     nxt_unit_req_log(req, NXT_UNIT_LOG_WARN, fmt, ##ARGS)
386743Smax.romanov@nginx.com 
387743Smax.romanov@nginx.com #define nxt_unit_error(ctx, fmt, ARGS...) \
388743Smax.romanov@nginx.com     nxt_unit_log(ctx, NXT_UNIT_LOG_ERR, fmt, ##ARGS)
389743Smax.romanov@nginx.com 
390743Smax.romanov@nginx.com #define nxt_unit_req_error(req, fmt, ARGS...) \
391743Smax.romanov@nginx.com     nxt_unit_req_log(req, NXT_UNIT_LOG_ERR, fmt, ##ARGS)
392743Smax.romanov@nginx.com 
393743Smax.romanov@nginx.com #define nxt_unit_alert(ctx, fmt, ARGS...) \
394743Smax.romanov@nginx.com     nxt_unit_log(ctx, NXT_UNIT_LOG_ALERT, fmt, ##ARGS)
395743Smax.romanov@nginx.com 
396743Smax.romanov@nginx.com #define nxt_unit_req_alert(req, fmt, ARGS...) \
397743Smax.romanov@nginx.com     nxt_unit_req_log(req, NXT_UNIT_LOG_ALERT, fmt, ##ARGS)
398743Smax.romanov@nginx.com 
399743Smax.romanov@nginx.com 
400743Smax.romanov@nginx.com #endif /* _NXT_UNIT_H_INCLUDED_ */
401