xref: /unit/src/nxt_unit.h (revision 2596:7ea1758fb8d4)
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 
151710Smax.romanov@nginx.com #include "nxt_auto_config.h"
16953Salexander.borisov@nginx.com #include "nxt_version.h"
17743Smax.romanov@nginx.com #include "nxt_unit_typedefs.h"
18743Smax.romanov@nginx.com 
19877Salexander.borisov@nginx.com 
20743Smax.romanov@nginx.com enum {
21743Smax.romanov@nginx.com     NXT_UNIT_OK          = 0,
22743Smax.romanov@nginx.com     NXT_UNIT_ERROR       = 1,
231545Smax.romanov@nginx.com     NXT_UNIT_AGAIN       = 2,
241546Smax.romanov@nginx.com     NXT_UNIT_CANCELLED   = 3,
25743Smax.romanov@nginx.com };
26743Smax.romanov@nginx.com 
27743Smax.romanov@nginx.com enum {
28743Smax.romanov@nginx.com     NXT_UNIT_LOG_ALERT   = 0,
29743Smax.romanov@nginx.com     NXT_UNIT_LOG_ERR     = 1,
30743Smax.romanov@nginx.com     NXT_UNIT_LOG_WARN    = 2,
31743Smax.romanov@nginx.com     NXT_UNIT_LOG_NOTICE  = 3,
32743Smax.romanov@nginx.com     NXT_UNIT_LOG_INFO    = 4,
33743Smax.romanov@nginx.com     NXT_UNIT_LOG_DEBUG   = 5,
34743Smax.romanov@nginx.com };
35743Smax.romanov@nginx.com 
36743Smax.romanov@nginx.com #define NXT_UNIT_INIT_ENV  "NXT_UNIT_INIT"
37743Smax.romanov@nginx.com 
381663Smax.romanov@nginx.com #define NXT_UNIT_SHARED_PORT_ID  ((uint16_t) 0xFFFFu)
391663Smax.romanov@nginx.com 
40743Smax.romanov@nginx.com /*
41743Smax.romanov@nginx.com  * Mostly opaque structure with library state.
42743Smax.romanov@nginx.com  *
43*2596Swhyte.vuhuni@gmail.com  * Only the user defined 'data' pointer is exposed here.  The rest is unit
44743Smax.romanov@nginx.com  * implementation specific and hidden.
45743Smax.romanov@nginx.com  */
46743Smax.romanov@nginx.com struct nxt_unit_s {
47743Smax.romanov@nginx.com     void                  *data;  /* User defined data. */
48743Smax.romanov@nginx.com };
49743Smax.romanov@nginx.com 
50743Smax.romanov@nginx.com /*
51743Smax.romanov@nginx.com  * Thread context.
52743Smax.romanov@nginx.com  *
53743Smax.romanov@nginx.com  * First (main) context is provided 'for free'.  To receive and process
54*2596Swhyte.vuhuni@gmail.com  * requests in other threads, one needs to allocate a new context and use it
55*2596Swhyte.vuhuni@gmail.com  * further in that thread.
56743Smax.romanov@nginx.com  */
57743Smax.romanov@nginx.com struct nxt_unit_ctx_s {
58743Smax.romanov@nginx.com     void                  *data;  /* User context-specific data. */
59743Smax.romanov@nginx.com     nxt_unit_t            *unit;
60743Smax.romanov@nginx.com };
61743Smax.romanov@nginx.com 
62743Smax.romanov@nginx.com /*
63743Smax.romanov@nginx.com  * Unit port identification structure.
64743Smax.romanov@nginx.com  *
65743Smax.romanov@nginx.com  * Each port can be uniquely identified by listen process id (pid) and port id.
66743Smax.romanov@nginx.com  * This identification is required to refer the port from different process.
67743Smax.romanov@nginx.com  */
68743Smax.romanov@nginx.com struct nxt_unit_port_id_s {
69743Smax.romanov@nginx.com     pid_t                 pid;
70743Smax.romanov@nginx.com     uint32_t              hash;
71743Smax.romanov@nginx.com     uint16_t              id;
72743Smax.romanov@nginx.com };
73743Smax.romanov@nginx.com 
74743Smax.romanov@nginx.com /*
75*2596Swhyte.vuhuni@gmail.com  * Unit provides port storage which is able to store and find the following
76743Smax.romanov@nginx.com  * data structures.
77743Smax.romanov@nginx.com  */
78743Smax.romanov@nginx.com struct nxt_unit_port_s {
79743Smax.romanov@nginx.com     nxt_unit_port_id_t    id;
80743Smax.romanov@nginx.com 
81743Smax.romanov@nginx.com     int                   in_fd;
82743Smax.romanov@nginx.com     int                   out_fd;
83743Smax.romanov@nginx.com 
84743Smax.romanov@nginx.com     void                  *data;
85743Smax.romanov@nginx.com };
86743Smax.romanov@nginx.com 
87743Smax.romanov@nginx.com 
88743Smax.romanov@nginx.com struct nxt_unit_buf_s {
89743Smax.romanov@nginx.com     char                  *start;
90743Smax.romanov@nginx.com     char                  *free;
91743Smax.romanov@nginx.com     char                  *end;
92743Smax.romanov@nginx.com };
93743Smax.romanov@nginx.com 
94743Smax.romanov@nginx.com 
95743Smax.romanov@nginx.com struct nxt_unit_request_info_s {
96743Smax.romanov@nginx.com     nxt_unit_t            *unit;
97743Smax.romanov@nginx.com     nxt_unit_ctx_t        *ctx;
98743Smax.romanov@nginx.com 
991544Smax.romanov@nginx.com     nxt_unit_port_t       *response_port;
100743Smax.romanov@nginx.com 
101743Smax.romanov@nginx.com     nxt_unit_request_t    *request;
102743Smax.romanov@nginx.com     nxt_unit_buf_t        *request_buf;
103743Smax.romanov@nginx.com 
104743Smax.romanov@nginx.com     nxt_unit_response_t   *response;
105743Smax.romanov@nginx.com     nxt_unit_buf_t        *response_buf;
106743Smax.romanov@nginx.com     uint32_t              response_max_fields;
107743Smax.romanov@nginx.com 
108743Smax.romanov@nginx.com     nxt_unit_buf_t        *content_buf;
109743Smax.romanov@nginx.com     uint64_t              content_length;
1101403Smax.romanov@nginx.com     int                   content_fd;
111743Smax.romanov@nginx.com 
112743Smax.romanov@nginx.com     void                  *data;
113743Smax.romanov@nginx.com };
114743Smax.romanov@nginx.com 
1151131Smax.romanov@nginx.com 
116743Smax.romanov@nginx.com /*
117*2596Swhyte.vuhuni@gmail.com  * Set of application-specific callbacks.  The application may leave all
118*2596Swhyte.vuhuni@gmail.com  * optional callbacks as NULL.
119743Smax.romanov@nginx.com  */
120743Smax.romanov@nginx.com struct nxt_unit_callbacks_s {
121743Smax.romanov@nginx.com     /*
122*2596Swhyte.vuhuni@gmail.com      * Process request. Unlike all other callbacks, this callback is required
123*2596Swhyte.vuhuni@gmail.com      * and needs to be defined by the application.
124743Smax.romanov@nginx.com      */
125743Smax.romanov@nginx.com     void     (*request_handler)(nxt_unit_request_info_t *req);
126743Smax.romanov@nginx.com 
1271555Smax.romanov@nginx.com     void     (*data_handler)(nxt_unit_request_info_t *req);
1281555Smax.romanov@nginx.com 
1291131Smax.romanov@nginx.com     /* Process websocket frame. */
1301131Smax.romanov@nginx.com     void     (*websocket_handler)(nxt_unit_websocket_frame_t *ws);
1311131Smax.romanov@nginx.com 
1321131Smax.romanov@nginx.com     /* Connection closed. */
1331131Smax.romanov@nginx.com     void     (*close_handler)(nxt_unit_request_info_t *req);
1341131Smax.romanov@nginx.com 
135743Smax.romanov@nginx.com     /* Add new Unit port to communicate with process pid. Optional. */
136743Smax.romanov@nginx.com     int      (*add_port)(nxt_unit_ctx_t *, nxt_unit_port_t *port);
137743Smax.romanov@nginx.com 
138743Smax.romanov@nginx.com     /* Remove previously added port. Optional. */
1391980Smax.romanov@nginx.com     void     (*remove_port)(nxt_unit_t *, nxt_unit_ctx_t *,
1401980Smax.romanov@nginx.com                             nxt_unit_port_t *port);
141743Smax.romanov@nginx.com 
142743Smax.romanov@nginx.com     /* Remove all data associated with process pid including ports. Optional. */
1431543Smax.romanov@nginx.com     void     (*remove_pid)(nxt_unit_t *, pid_t pid);
144743Smax.romanov@nginx.com 
145743Smax.romanov@nginx.com     /* Gracefully quit the application. Optional. */
146743Smax.romanov@nginx.com     void     (*quit)(nxt_unit_ctx_t *);
147743Smax.romanov@nginx.com 
1481543Smax.romanov@nginx.com     /* Shared memory release acknowledgement. Optional. */
1491321Smax.romanov@nginx.com     void     (*shm_ack_handler)(nxt_unit_ctx_t *);
1501321Smax.romanov@nginx.com 
151743Smax.romanov@nginx.com     /* Send data and control to process pid using port id. Optional. */
1521544Smax.romanov@nginx.com     ssize_t  (*port_send)(nxt_unit_ctx_t *, nxt_unit_port_t *port,
153743Smax.romanov@nginx.com                  const void *buf, size_t buf_size,
154743Smax.romanov@nginx.com                  const void *oob, size_t oob_size);
155743Smax.romanov@nginx.com 
156743Smax.romanov@nginx.com     /* Receive data on port id. Optional. */
1571544Smax.romanov@nginx.com     ssize_t  (*port_recv)(nxt_unit_ctx_t *, nxt_unit_port_t *port,
1581996St.nateldemoura@f5.com                  void *buf, size_t buf_size, void *oob, size_t *oob_size);
1591666Smax.romanov@nginx.com 
1601666Smax.romanov@nginx.com     int      (*ready_handler)(nxt_unit_ctx_t *);
161743Smax.romanov@nginx.com };
162743Smax.romanov@nginx.com 
163743Smax.romanov@nginx.com 
164743Smax.romanov@nginx.com struct nxt_unit_init_s {
165743Smax.romanov@nginx.com     void                  *data;     /* Opaque pointer to user-defined data. */
166743Smax.romanov@nginx.com     void                  *ctx_data; /* Opaque pointer to user-defined data. */
167743Smax.romanov@nginx.com     int                   max_pending_requests;
168743Smax.romanov@nginx.com 
169743Smax.romanov@nginx.com     uint32_t              request_data_size;
1701320Smax.romanov@nginx.com     uint32_t              shm_limit;
1711980Smax.romanov@nginx.com     uint32_t              request_limit;
172743Smax.romanov@nginx.com 
173743Smax.romanov@nginx.com     nxt_unit_callbacks_t  callbacks;
174743Smax.romanov@nginx.com 
175743Smax.romanov@nginx.com     nxt_unit_port_t       ready_port;
176743Smax.romanov@nginx.com     uint32_t              ready_stream;
1771543Smax.romanov@nginx.com     nxt_unit_port_t       router_port;
178743Smax.romanov@nginx.com     nxt_unit_port_t       read_port;
1792014Smax.romanov@nginx.com     int                   shared_port_fd;
1802014Smax.romanov@nginx.com     int                   shared_queue_fd;
181743Smax.romanov@nginx.com     int                   log_fd;
182743Smax.romanov@nginx.com };
183743Smax.romanov@nginx.com 
184743Smax.romanov@nginx.com 
185743Smax.romanov@nginx.com typedef ssize_t (*nxt_unit_read_func_t)(nxt_unit_read_info_t *read_info,
186743Smax.romanov@nginx.com     void *dst, size_t size);
187743Smax.romanov@nginx.com 
188743Smax.romanov@nginx.com 
189743Smax.romanov@nginx.com struct nxt_unit_read_info_s {
190743Smax.romanov@nginx.com     nxt_unit_read_func_t  read;
191743Smax.romanov@nginx.com     int                   eof;
192743Smax.romanov@nginx.com     uint32_t              buf_size;
193743Smax.romanov@nginx.com     void                  *data;
194743Smax.romanov@nginx.com };
195743Smax.romanov@nginx.com 
196743Smax.romanov@nginx.com 
197743Smax.romanov@nginx.com /*
198743Smax.romanov@nginx.com  * Initialize Unit application library with necessary callbacks and
1991602Sartem.konev@nginx.com  * ready/reply port parameters, send 'READY' response to main.
200743Smax.romanov@nginx.com  */
201743Smax.romanov@nginx.com nxt_unit_ctx_t *nxt_unit_init(nxt_unit_init_t *);
202743Smax.romanov@nginx.com 
203743Smax.romanov@nginx.com /*
204*2596Swhyte.vuhuni@gmail.com  * Main function, useful in case the application does not have its own event
205*2596Swhyte.vuhuni@gmail.com  * loop. nxt_unit_run() starts an infinite message wait and process loop.
206743Smax.romanov@nginx.com  *
207743Smax.romanov@nginx.com  *  for (;;) {
208743Smax.romanov@nginx.com  *      app_lib->port_recv(...);
209743Smax.romanov@nginx.com  *      nxt_unit_process_msg(...);
210743Smax.romanov@nginx.com  *  }
211743Smax.romanov@nginx.com  *
212*2596Swhyte.vuhuni@gmail.com  * The function returns normally when a QUIT message is received from Unit.
213743Smax.romanov@nginx.com  */
214743Smax.romanov@nginx.com int nxt_unit_run(nxt_unit_ctx_t *);
215743Smax.romanov@nginx.com 
2161547Smax.romanov@nginx.com int nxt_unit_run_ctx(nxt_unit_ctx_t *ctx);
2171547Smax.romanov@nginx.com 
2181547Smax.romanov@nginx.com int nxt_unit_run_shared(nxt_unit_ctx_t *ctx);
2191547Smax.romanov@nginx.com 
2201713Smax.romanov@nginx.com nxt_unit_request_info_t *nxt_unit_dequeue_request(nxt_unit_ctx_t *ctx);
2211713Smax.romanov@nginx.com 
2221547Smax.romanov@nginx.com /*
223*2596Swhyte.vuhuni@gmail.com  * Receive and process one message, and invoke configured callbacks.
2241547Smax.romanov@nginx.com  *
225*2596Swhyte.vuhuni@gmail.com  * If the application implements its own event loop, each datagram received
226*2596Swhyte.vuhuni@gmail.com  * from the port socket should be initially processed by unit.  This function
2271547Smax.romanov@nginx.com  * may invoke other application-defined callback for message processing.
2281547Smax.romanov@nginx.com  */
229828Salexander.borisov@nginx.com int nxt_unit_run_once(nxt_unit_ctx_t *ctx);
230828Salexander.borisov@nginx.com 
2311547Smax.romanov@nginx.com int nxt_unit_process_port_msg(nxt_unit_ctx_t *ctx, nxt_unit_port_t *port);
2321547Smax.romanov@nginx.com 
233743Smax.romanov@nginx.com /* Destroy application library object. */
234743Smax.romanov@nginx.com void nxt_unit_done(nxt_unit_ctx_t *);
235743Smax.romanov@nginx.com 
236743Smax.romanov@nginx.com /*
237*2596Swhyte.vuhuni@gmail.com  * Allocate and initialize a new execution context with a new listen port to
238*2596Swhyte.vuhuni@gmail.com  * process requests in another thread.
239743Smax.romanov@nginx.com  */
240743Smax.romanov@nginx.com nxt_unit_ctx_t *nxt_unit_ctx_alloc(nxt_unit_ctx_t *, void *);
241743Smax.romanov@nginx.com 
242743Smax.romanov@nginx.com /* Initialize port_id, calculate hash. */
243743Smax.romanov@nginx.com void nxt_unit_port_id_init(nxt_unit_port_id_t *port_id, pid_t pid, uint16_t id);
244743Smax.romanov@nginx.com 
245743Smax.romanov@nginx.com /* Calculates hash for given field name. */
246743Smax.romanov@nginx.com uint16_t nxt_unit_field_hash(const char* name, size_t name_length);
247743Smax.romanov@nginx.com 
248743Smax.romanov@nginx.com /* Split host for server name and port. */
249743Smax.romanov@nginx.com void nxt_unit_split_host(char *host_start, uint32_t host_length,
250743Smax.romanov@nginx.com     char **name, uint32_t *name_length, char **port, uint32_t *port_length);
251743Smax.romanov@nginx.com 
252743Smax.romanov@nginx.com /* Group duplicate fields for easy enumeration. */
253743Smax.romanov@nginx.com void nxt_unit_request_group_dup_fields(nxt_unit_request_info_t *req);
254743Smax.romanov@nginx.com 
255743Smax.romanov@nginx.com /*
256*2596Swhyte.vuhuni@gmail.com  * Allocate response structure capable of storing a limited number of fields.
257743Smax.romanov@nginx.com  * The structure may be accessed directly via req->response pointer or
258743Smax.romanov@nginx.com  * filled step-by-step using functions add_field and add_content.
259743Smax.romanov@nginx.com  */
260743Smax.romanov@nginx.com int nxt_unit_response_init(nxt_unit_request_info_t *req,
261743Smax.romanov@nginx.com     uint16_t status, uint32_t max_fields_count, uint32_t max_fields_size);
262743Smax.romanov@nginx.com 
263743Smax.romanov@nginx.com int nxt_unit_response_realloc(nxt_unit_request_info_t *req,
264743Smax.romanov@nginx.com     uint32_t max_fields_count, uint32_t max_fields_size);
265743Smax.romanov@nginx.com 
266743Smax.romanov@nginx.com int nxt_unit_response_is_init(nxt_unit_request_info_t *req);
267743Smax.romanov@nginx.com 
268743Smax.romanov@nginx.com int nxt_unit_response_add_field(nxt_unit_request_info_t *req,
269743Smax.romanov@nginx.com     const char* name, uint8_t name_length,
270743Smax.romanov@nginx.com     const char* value, uint32_t value_length);
271743Smax.romanov@nginx.com 
272743Smax.romanov@nginx.com int nxt_unit_response_add_content(nxt_unit_request_info_t *req,
273743Smax.romanov@nginx.com     const void* src, uint32_t size);
274743Smax.romanov@nginx.com 
275743Smax.romanov@nginx.com /*
276*2596Swhyte.vuhuni@gmail.com  * Send the prepared response to the Unit server.  The Response structure is
277*2596Swhyte.vuhuni@gmail.com  * destroyed during this call.
278743Smax.romanov@nginx.com  */
279743Smax.romanov@nginx.com int nxt_unit_response_send(nxt_unit_request_info_t *req);
280743Smax.romanov@nginx.com 
281743Smax.romanov@nginx.com int nxt_unit_response_is_sent(nxt_unit_request_info_t *req);
282743Smax.romanov@nginx.com 
283743Smax.romanov@nginx.com nxt_unit_buf_t *nxt_unit_response_buf_alloc(nxt_unit_request_info_t *req,
284743Smax.romanov@nginx.com     uint32_t size);
285743Smax.romanov@nginx.com 
2861131Smax.romanov@nginx.com int nxt_unit_request_is_websocket_handshake(nxt_unit_request_info_t *req);
2871131Smax.romanov@nginx.com 
2881131Smax.romanov@nginx.com int nxt_unit_response_upgrade(nxt_unit_request_info_t *req);
2891131Smax.romanov@nginx.com 
2901131Smax.romanov@nginx.com int nxt_unit_response_is_websocket(nxt_unit_request_info_t *req);
2911131Smax.romanov@nginx.com 
2921131Smax.romanov@nginx.com nxt_unit_request_info_t *nxt_unit_get_request_info_from_data(void *data);
2931131Smax.romanov@nginx.com 
294743Smax.romanov@nginx.com int nxt_unit_buf_send(nxt_unit_buf_t *buf);
295743Smax.romanov@nginx.com 
296743Smax.romanov@nginx.com void nxt_unit_buf_free(nxt_unit_buf_t *buf);
297743Smax.romanov@nginx.com 
298743Smax.romanov@nginx.com nxt_unit_buf_t *nxt_unit_buf_next(nxt_unit_buf_t *buf);
299743Smax.romanov@nginx.com 
300743Smax.romanov@nginx.com uint32_t nxt_unit_buf_max(void);
301743Smax.romanov@nginx.com 
302743Smax.romanov@nginx.com uint32_t nxt_unit_buf_min(void);
303743Smax.romanov@nginx.com 
304743Smax.romanov@nginx.com int nxt_unit_response_write(nxt_unit_request_info_t *req, const void *start,
305743Smax.romanov@nginx.com     size_t size);
306743Smax.romanov@nginx.com 
3071321Smax.romanov@nginx.com ssize_t nxt_unit_response_write_nb(nxt_unit_request_info_t *req,
3081321Smax.romanov@nginx.com     const void *start, size_t size, size_t min_size);
3091321Smax.romanov@nginx.com 
310743Smax.romanov@nginx.com int nxt_unit_response_write_cb(nxt_unit_request_info_t *req,
311743Smax.romanov@nginx.com     nxt_unit_read_info_t *read_info);
312743Smax.romanov@nginx.com 
313743Smax.romanov@nginx.com ssize_t nxt_unit_request_read(nxt_unit_request_info_t *req, void *dst,
314743Smax.romanov@nginx.com     size_t size);
315743Smax.romanov@nginx.com 
3161398Smax.romanov@nginx.com ssize_t nxt_unit_request_readline_size(nxt_unit_request_info_t *req,
3171398Smax.romanov@nginx.com     size_t max_size);
3181398Smax.romanov@nginx.com 
319743Smax.romanov@nginx.com void nxt_unit_request_done(nxt_unit_request_info_t *req, int rc);
320743Smax.romanov@nginx.com 
321743Smax.romanov@nginx.com 
3221131Smax.romanov@nginx.com int nxt_unit_websocket_send(nxt_unit_request_info_t *req, uint8_t opcode,
3231131Smax.romanov@nginx.com     uint8_t last, const void *start, size_t size);
3241131Smax.romanov@nginx.com 
3251131Smax.romanov@nginx.com int nxt_unit_websocket_sendv(nxt_unit_request_info_t *req, uint8_t opcode,
3261131Smax.romanov@nginx.com     uint8_t last, const struct iovec *iov, int iovcnt);
3271131Smax.romanov@nginx.com 
3281131Smax.romanov@nginx.com ssize_t nxt_unit_websocket_read(nxt_unit_websocket_frame_t *ws, void *dst,
3291131Smax.romanov@nginx.com     size_t size);
3301131Smax.romanov@nginx.com 
3311131Smax.romanov@nginx.com int nxt_unit_websocket_retain(nxt_unit_websocket_frame_t *ws);
3321131Smax.romanov@nginx.com 
3331131Smax.romanov@nginx.com void nxt_unit_websocket_done(nxt_unit_websocket_frame_t *ws);
3341131Smax.romanov@nginx.com 
3351131Smax.romanov@nginx.com 
3361623Smax.romanov@nginx.com void *nxt_unit_malloc(nxt_unit_ctx_t *ctx, size_t size);
3371623Smax.romanov@nginx.com 
3381623Smax.romanov@nginx.com void nxt_unit_free(nxt_unit_ctx_t *ctx, void *p);
3391623Smax.romanov@nginx.com 
3401436Smax.romanov@nginx.com #if defined __has_attribute
3411436Smax.romanov@nginx.com 
3421436Smax.romanov@nginx.com #if __has_attribute(format)
3431436Smax.romanov@nginx.com 
3441436Smax.romanov@nginx.com #define NXT_ATTR_FORMAT  __attribute__((format(printf, 3, 4)))
3451436Smax.romanov@nginx.com 
3461436Smax.romanov@nginx.com #endif
3471436Smax.romanov@nginx.com 
3481436Smax.romanov@nginx.com #endif
3491436Smax.romanov@nginx.com 
3501436Smax.romanov@nginx.com 
3511436Smax.romanov@nginx.com #if !defined(NXT_ATTR_FORMAT)
3521436Smax.romanov@nginx.com 
3531436Smax.romanov@nginx.com #define NXT_ATTR_FORMAT
3541436Smax.romanov@nginx.com 
3551436Smax.romanov@nginx.com #endif
3561436Smax.romanov@nginx.com 
3571436Smax.romanov@nginx.com 
3581436Smax.romanov@nginx.com void nxt_unit_log(nxt_unit_ctx_t *ctx, int level, const char* fmt, ...)
3591436Smax.romanov@nginx.com     NXT_ATTR_FORMAT;
360743Smax.romanov@nginx.com 
361743Smax.romanov@nginx.com void nxt_unit_req_log(nxt_unit_request_info_t *req, int level,
3621436Smax.romanov@nginx.com     const char* fmt, ...) NXT_ATTR_FORMAT;
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