xref: /unit/src/nxt_port.h (revision 1997)
111Sigor@sysoev.ru 
211Sigor@sysoev.ru /*
311Sigor@sysoev.ru  * Copyright (C) Igor Sysoev
411Sigor@sysoev.ru  * Copyright (C) NGINX, Inc.
511Sigor@sysoev.ru  */
611Sigor@sysoev.ru 
711Sigor@sysoev.ru #ifndef _NXT_PORT_H_INCLUDED_
811Sigor@sysoev.ru #define _NXT_PORT_H_INCLUDED_
911Sigor@sysoev.ru 
1011Sigor@sysoev.ru 
11320Smax.romanov@nginx.com struct nxt_port_handlers_s {
12320Smax.romanov@nginx.com     /* RPC responses. */
13320Smax.romanov@nginx.com     nxt_port_handler_t  rpc_ready;
14320Smax.romanov@nginx.com     nxt_port_handler_t  rpc_error;
15320Smax.romanov@nginx.com 
16320Smax.romanov@nginx.com     /* Main process RPC requests. */
171488St.nateldemoura@f5.com     nxt_port_handler_t  start_process;
18320Smax.romanov@nginx.com     nxt_port_handler_t  socket;
19320Smax.romanov@nginx.com     nxt_port_handler_t  modules;
20320Smax.romanov@nginx.com     nxt_port_handler_t  conf_store;
21774Svbart@nginx.com     nxt_port_handler_t  cert_get;
22774Svbart@nginx.com     nxt_port_handler_t  cert_delete;
23630Svbart@nginx.com     nxt_port_handler_t  access_log;
24320Smax.romanov@nginx.com 
25320Smax.romanov@nginx.com     /* File descriptor exchange. */
26320Smax.romanov@nginx.com     nxt_port_handler_t  change_file;
27320Smax.romanov@nginx.com     nxt_port_handler_t  new_port;
281545Smax.romanov@nginx.com     nxt_port_handler_t  get_port;
291666Smax.romanov@nginx.com     nxt_port_handler_t  port_ack;
30320Smax.romanov@nginx.com     nxt_port_handler_t  mmap;
311546Smax.romanov@nginx.com     nxt_port_handler_t  get_mmap;
32320Smax.romanov@nginx.com 
331488St.nateldemoura@f5.com     /* New process */
341488St.nateldemoura@f5.com     nxt_port_handler_t  process_created;
35320Smax.romanov@nginx.com     nxt_port_handler_t  process_ready;
36320Smax.romanov@nginx.com 
37320Smax.romanov@nginx.com     /* Process exit/crash notification. */
38320Smax.romanov@nginx.com     nxt_port_handler_t  remove_pid;
39320Smax.romanov@nginx.com 
40320Smax.romanov@nginx.com     /* Stop process command. */
41320Smax.romanov@nginx.com     nxt_port_handler_t  quit;
42320Smax.romanov@nginx.com 
431131Smax.romanov@nginx.com     /* Request headers. */
441131Smax.romanov@nginx.com     nxt_port_handler_t  req_headers;
451547Smax.romanov@nginx.com     nxt_port_handler_t  req_headers_ack;
461555Smax.romanov@nginx.com     nxt_port_handler_t  req_body;
471131Smax.romanov@nginx.com 
481131Smax.romanov@nginx.com     /* Websocket frame. */
491131Smax.romanov@nginx.com     nxt_port_handler_t  websocket_frame;
501131Smax.romanov@nginx.com 
51320Smax.romanov@nginx.com     /* Various data. */
52320Smax.romanov@nginx.com     nxt_port_handler_t  data;
531926Smax.romanov@nginx.com     nxt_port_handler_t  app_restart;
541321Smax.romanov@nginx.com 
551321Smax.romanov@nginx.com     nxt_port_handler_t  oosm;
561321Smax.romanov@nginx.com     nxt_port_handler_t  shm_ack;
571555Smax.romanov@nginx.com     nxt_port_handler_t  read_queue;
581555Smax.romanov@nginx.com     nxt_port_handler_t  read_socket;
59320Smax.romanov@nginx.com };
60320Smax.romanov@nginx.com 
61320Smax.romanov@nginx.com 
62320Smax.romanov@nginx.com #define nxt_port_handler_idx(name)                                            \
63389Smax.romanov@nginx.com     ( offsetof(nxt_port_handlers_t, name) / sizeof(nxt_port_handler_t) )
64320Smax.romanov@nginx.com 
651488St.nateldemoura@f5.com #define nxt_msg_last(handler)                                                 \
661488St.nateldemoura@f5.com     (handler | NXT_PORT_MSG_LAST)
67320Smax.romanov@nginx.com 
6842Smax.romanov@nginx.com typedef enum {
691488St.nateldemoura@f5.com     NXT_PORT_MSG_LAST             = 0x100,
701488St.nateldemoura@f5.com     NXT_PORT_MSG_CLOSE_FD         = 0x200,
711488St.nateldemoura@f5.com     NXT_PORT_MSG_SYNC             = 0x400,
72189Smax.romanov@nginx.com 
731488St.nateldemoura@f5.com     NXT_PORT_MSG_MASK             = 0xFF,
74189Smax.romanov@nginx.com 
751488St.nateldemoura@f5.com     _NXT_PORT_MSG_RPC_READY       = nxt_port_handler_idx(rpc_ready),
761488St.nateldemoura@f5.com     _NXT_PORT_MSG_RPC_ERROR       = nxt_port_handler_idx(rpc_error),
77320Smax.romanov@nginx.com 
781488St.nateldemoura@f5.com     _NXT_PORT_MSG_START_PROCESS   = nxt_port_handler_idx(start_process),
791488St.nateldemoura@f5.com     _NXT_PORT_MSG_SOCKET          = nxt_port_handler_idx(socket),
801488St.nateldemoura@f5.com     _NXT_PORT_MSG_MODULES         = nxt_port_handler_idx(modules),
811488St.nateldemoura@f5.com     _NXT_PORT_MSG_CONF_STORE      = nxt_port_handler_idx(conf_store),
821488St.nateldemoura@f5.com     _NXT_PORT_MSG_CERT_GET        = nxt_port_handler_idx(cert_get),
831488St.nateldemoura@f5.com     _NXT_PORT_MSG_CERT_DELETE     = nxt_port_handler_idx(cert_delete),
841488St.nateldemoura@f5.com     _NXT_PORT_MSG_ACCESS_LOG      = nxt_port_handler_idx(access_log),
8542Smax.romanov@nginx.com 
861488St.nateldemoura@f5.com     _NXT_PORT_MSG_CHANGE_FILE     = nxt_port_handler_idx(change_file),
871488St.nateldemoura@f5.com     _NXT_PORT_MSG_NEW_PORT        = nxt_port_handler_idx(new_port),
881545Smax.romanov@nginx.com     _NXT_PORT_MSG_GET_PORT        = nxt_port_handler_idx(get_port),
891666Smax.romanov@nginx.com     _NXT_PORT_MSG_PORT_ACK        = nxt_port_handler_idx(port_ack),
901488St.nateldemoura@f5.com     _NXT_PORT_MSG_MMAP            = nxt_port_handler_idx(mmap),
911546Smax.romanov@nginx.com     _NXT_PORT_MSG_GET_MMAP        = nxt_port_handler_idx(get_mmap),
92320Smax.romanov@nginx.com 
931488St.nateldemoura@f5.com     _NXT_PORT_MSG_PROCESS_CREATED = nxt_port_handler_idx(process_created),
941488St.nateldemoura@f5.com     _NXT_PORT_MSG_PROCESS_READY   = nxt_port_handler_idx(process_ready),
951488St.nateldemoura@f5.com     _NXT_PORT_MSG_REMOVE_PID      = nxt_port_handler_idx(remove_pid),
961488St.nateldemoura@f5.com     _NXT_PORT_MSG_QUIT            = nxt_port_handler_idx(quit),
971131Smax.romanov@nginx.com 
981488St.nateldemoura@f5.com     _NXT_PORT_MSG_REQ_HEADERS     = nxt_port_handler_idx(req_headers),
991547Smax.romanov@nginx.com     _NXT_PORT_MSG_REQ_HEADERS_ACK = nxt_port_handler_idx(req_headers_ack),
1001555Smax.romanov@nginx.com     _NXT_PORT_MSG_REQ_BODY        = nxt_port_handler_idx(req_body),
1011488St.nateldemoura@f5.com     _NXT_PORT_MSG_WEBSOCKET       = nxt_port_handler_idx(websocket_frame),
102189Smax.romanov@nginx.com 
1031488St.nateldemoura@f5.com     _NXT_PORT_MSG_DATA            = nxt_port_handler_idx(data),
1041926Smax.romanov@nginx.com     _NXT_PORT_MSG_APP_RESTART     = nxt_port_handler_idx(app_restart),
1051321Smax.romanov@nginx.com 
1061488St.nateldemoura@f5.com     _NXT_PORT_MSG_OOSM            = nxt_port_handler_idx(oosm),
1071488St.nateldemoura@f5.com     _NXT_PORT_MSG_SHM_ACK         = nxt_port_handler_idx(shm_ack),
1081555Smax.romanov@nginx.com     _NXT_PORT_MSG_READ_QUEUE      = nxt_port_handler_idx(read_queue),
1091555Smax.romanov@nginx.com     _NXT_PORT_MSG_READ_SOCKET     = nxt_port_handler_idx(read_socket),
110320Smax.romanov@nginx.com 
1111488St.nateldemoura@f5.com     NXT_PORT_MSG_MAX              = sizeof(nxt_port_handlers_t)
1121488St.nateldemoura@f5.com                                     / sizeof(nxt_port_handler_t),
113320Smax.romanov@nginx.com 
1141488St.nateldemoura@f5.com     NXT_PORT_MSG_RPC_READY        = _NXT_PORT_MSG_RPC_READY,
1151488St.nateldemoura@f5.com     NXT_PORT_MSG_RPC_READY_LAST   = nxt_msg_last(_NXT_PORT_MSG_RPC_READY),
1161488St.nateldemoura@f5.com     NXT_PORT_MSG_RPC_ERROR        = nxt_msg_last(_NXT_PORT_MSG_RPC_ERROR),
1171488St.nateldemoura@f5.com     NXT_PORT_MSG_START_PROCESS    = nxt_msg_last(_NXT_PORT_MSG_START_PROCESS),
1181488St.nateldemoura@f5.com     NXT_PORT_MSG_SOCKET           = nxt_msg_last(_NXT_PORT_MSG_SOCKET),
1191488St.nateldemoura@f5.com     NXT_PORT_MSG_MODULES          = nxt_msg_last(_NXT_PORT_MSG_MODULES),
1201488St.nateldemoura@f5.com     NXT_PORT_MSG_CONF_STORE       = nxt_msg_last(_NXT_PORT_MSG_CONF_STORE),
1211488St.nateldemoura@f5.com     NXT_PORT_MSG_CERT_GET         = nxt_msg_last(_NXT_PORT_MSG_CERT_GET),
1221488St.nateldemoura@f5.com     NXT_PORT_MSG_CERT_DELETE      = nxt_msg_last(_NXT_PORT_MSG_CERT_DELETE),
1231488St.nateldemoura@f5.com     NXT_PORT_MSG_ACCESS_LOG       = nxt_msg_last(_NXT_PORT_MSG_ACCESS_LOG),
1241488St.nateldemoura@f5.com     NXT_PORT_MSG_CHANGE_FILE      = nxt_msg_last(_NXT_PORT_MSG_CHANGE_FILE),
1251488St.nateldemoura@f5.com     NXT_PORT_MSG_NEW_PORT         = nxt_msg_last(_NXT_PORT_MSG_NEW_PORT),
1261545Smax.romanov@nginx.com     NXT_PORT_MSG_GET_PORT         = nxt_msg_last(_NXT_PORT_MSG_GET_PORT),
1271666Smax.romanov@nginx.com     NXT_PORT_MSG_PORT_ACK         = nxt_msg_last(_NXT_PORT_MSG_PORT_ACK),
1281488St.nateldemoura@f5.com     NXT_PORT_MSG_MMAP             = nxt_msg_last(_NXT_PORT_MSG_MMAP)
1291547Smax.romanov@nginx.com                                     | NXT_PORT_MSG_SYNC,
1301547Smax.romanov@nginx.com     NXT_PORT_MSG_GET_MMAP         = nxt_msg_last(_NXT_PORT_MSG_GET_MMAP),
131320Smax.romanov@nginx.com 
1321488St.nateldemoura@f5.com     NXT_PORT_MSG_PROCESS_CREATED  = nxt_msg_last(_NXT_PORT_MSG_PROCESS_CREATED),
1331488St.nateldemoura@f5.com     NXT_PORT_MSG_PROCESS_READY    = nxt_msg_last(_NXT_PORT_MSG_PROCESS_READY),
1341488St.nateldemoura@f5.com     NXT_PORT_MSG_QUIT             = nxt_msg_last(_NXT_PORT_MSG_QUIT),
1351488St.nateldemoura@f5.com     NXT_PORT_MSG_REMOVE_PID       = nxt_msg_last(_NXT_PORT_MSG_REMOVE_PID),
1361131Smax.romanov@nginx.com 
1371488St.nateldemoura@f5.com     NXT_PORT_MSG_REQ_HEADERS      = _NXT_PORT_MSG_REQ_HEADERS,
1381555Smax.romanov@nginx.com     NXT_PORT_MSG_REQ_BODY         = _NXT_PORT_MSG_REQ_BODY,
1391488St.nateldemoura@f5.com     NXT_PORT_MSG_WEBSOCKET        = _NXT_PORT_MSG_WEBSOCKET,
1401488St.nateldemoura@f5.com     NXT_PORT_MSG_WEBSOCKET_LAST   = nxt_msg_last(_NXT_PORT_MSG_WEBSOCKET),
1411321Smax.romanov@nginx.com 
1421488St.nateldemoura@f5.com     NXT_PORT_MSG_DATA             = _NXT_PORT_MSG_DATA,
1431488St.nateldemoura@f5.com     NXT_PORT_MSG_DATA_LAST        = nxt_msg_last(_NXT_PORT_MSG_DATA),
1441926Smax.romanov@nginx.com     NXT_PORT_MSG_APP_RESTART      = nxt_msg_last(_NXT_PORT_MSG_APP_RESTART),
1451488St.nateldemoura@f5.com 
1461488St.nateldemoura@f5.com     NXT_PORT_MSG_OOSM             = nxt_msg_last(_NXT_PORT_MSG_OOSM),
1471488St.nateldemoura@f5.com     NXT_PORT_MSG_SHM_ACK          = nxt_msg_last(_NXT_PORT_MSG_SHM_ACK),
1481555Smax.romanov@nginx.com     NXT_PORT_MSG_READ_QUEUE       = _NXT_PORT_MSG_READ_QUEUE,
1491555Smax.romanov@nginx.com     NXT_PORT_MSG_READ_SOCKET      = _NXT_PORT_MSG_READ_SOCKET,
150125Smax.romanov@nginx.com } nxt_port_msg_type_t;
15142Smax.romanov@nginx.com 
15214Sigor@sysoev.ru 
15342Smax.romanov@nginx.com /* Passed as a first iov chunk. */
15442Smax.romanov@nginx.com typedef struct {
15542Smax.romanov@nginx.com     uint32_t             stream;
1561996St.nateldemoura@f5.com 
1571996St.nateldemoura@f5.com     nxt_pid_t            pid;       /* not used on Linux and FreeBSD */
1581996St.nateldemoura@f5.com 
15942Smax.romanov@nginx.com     nxt_port_id_t        reply_port;
16042Smax.romanov@nginx.com 
161189Smax.romanov@nginx.com     uint8_t              type;
162423Smax.romanov@nginx.com 
163423Smax.romanov@nginx.com     /* Last message for this stream. */
16442Smax.romanov@nginx.com     uint8_t              last;      /* 1 bit */
16542Smax.romanov@nginx.com 
16642Smax.romanov@nginx.com     /* Message data send using mmap, next chunk is a nxt_port_mmap_msg_t. */
16742Smax.romanov@nginx.com     uint8_t              mmap;      /* 1 bit */
168352Smax.romanov@nginx.com 
169423Smax.romanov@nginx.com     /* Non-First fragment in fragmented message sequence. */
170423Smax.romanov@nginx.com     uint8_t              nf;        /* 1 bit */
171423Smax.romanov@nginx.com 
172423Smax.romanov@nginx.com     /* More Fragments followed. */
173423Smax.romanov@nginx.com     uint8_t              mf;        /* 1 bit */
174423Smax.romanov@nginx.com 
175423Smax.romanov@nginx.com     /* Message delivery tracking enabled, next chunk is tracking msg. */
176423Smax.romanov@nginx.com     uint8_t              tracking;  /* 1 bit */
177168Svbart@nginx.com } nxt_port_msg_t;
17814Sigor@sysoev.ru 
17914Sigor@sysoev.ru 
18014Sigor@sysoev.ru typedef struct {
18114Sigor@sysoev.ru     nxt_queue_link_t    link;
18214Sigor@sysoev.ru     nxt_buf_t           *buf;
18314Sigor@sysoev.ru     size_t              share;
1841558Smax.romanov@nginx.com     nxt_fd_t            fd[2];
18514Sigor@sysoev.ru     nxt_port_msg_t      port_msg;
186423Smax.romanov@nginx.com     uint32_t            tracking_msg[2];
1871125Smax.romanov@nginx.com     uint8_t             close_fd;   /* 1 bit */
1881125Smax.romanov@nginx.com     uint8_t             allocated;  /* 1 bit */
18914Sigor@sysoev.ru } nxt_port_send_msg_t;
19014Sigor@sysoev.ru 
1911996St.nateldemoura@f5.com #if (NXT_HAVE_UCRED) || (NXT_HAVE_MSGHDR_CMSGCRED)
1921996St.nateldemoura@f5.com #define NXT_USE_CMSG_PID    1
1931996St.nateldemoura@f5.com #endif
19414Sigor@sysoev.ru 
19520Sigor@sysoev.ru struct nxt_port_recv_msg_s {
1961558Smax.romanov@nginx.com     nxt_fd_t            fd[2];
19714Sigor@sysoev.ru     nxt_buf_t           *buf;
19814Sigor@sysoev.ru     nxt_port_t          *port;
19942Smax.romanov@nginx.com     nxt_port_msg_t      port_msg;
20082Smax.romanov@nginx.com     size_t              size;
2011996St.nateldemoura@f5.com #if (NXT_USE_CMSG_PID)
2021996St.nateldemoura@f5.com     nxt_pid_t           cmsg_pid;
2031996St.nateldemoura@f5.com #endif
204423Smax.romanov@nginx.com     nxt_bool_t          cancelled;
205347Smax.romanov@nginx.com     union {
206347Smax.romanov@nginx.com         nxt_port_t      *new_port;
207347Smax.romanov@nginx.com         nxt_pid_t       removed_pid;
208347Smax.romanov@nginx.com         void            *data;
209347Smax.romanov@nginx.com     } u;
21020Sigor@sysoev.ru };
21114Sigor@sysoev.ru 
2121996St.nateldemoura@f5.com 
2131996St.nateldemoura@f5.com #if (NXT_USE_CMSG_PID)
2141996St.nateldemoura@f5.com #define nxt_recv_msg_cmsg_pid(msg)      ((msg)->cmsg_pid)
2151996St.nateldemoura@f5.com #define nxt_recv_msg_cmsg_pid_ref(msg)  (&(msg)->cmsg_pid)
2161996St.nateldemoura@f5.com #else
2171996St.nateldemoura@f5.com #define nxt_recv_msg_cmsg_pid(msg)      ((msg)->port_msg.pid)
2181996St.nateldemoura@f5.com #define nxt_recv_msg_cmsg_pid_ref(msg)  (NULL)
2191996St.nateldemoura@f5.com #endif
2201996St.nateldemoura@f5.com 
221141Smax.romanov@nginx.com typedef struct nxt_app_s  nxt_app_t;
22214Sigor@sysoev.ru 
22314Sigor@sysoev.ru struct nxt_port_s {
22414Sigor@sysoev.ru     nxt_fd_event_t      socket;
22514Sigor@sysoev.ru 
226125Smax.romanov@nginx.com     nxt_queue_link_t    link;       /* for nxt_process_t.ports */
227141Smax.romanov@nginx.com     nxt_process_t       *process;
228141Smax.romanov@nginx.com 
229141Smax.romanov@nginx.com     nxt_queue_link_t    app_link;   /* for nxt_app_t.ports */
230141Smax.romanov@nginx.com     nxt_app_t           *app;
2311547Smax.romanov@nginx.com     nxt_port_t          *main_app_port;
23242Smax.romanov@nginx.com 
233507Smax.romanov@nginx.com     nxt_queue_link_t    idle_link;  /* for nxt_app_t.idle_ports */
234507Smax.romanov@nginx.com     nxt_msec_t          idle_start;
235507Smax.romanov@nginx.com 
23614Sigor@sysoev.ru     nxt_queue_t         messages;   /* of nxt_port_send_msg_t */
237343Smax.romanov@nginx.com     nxt_thread_mutex_t  write_mutex;
23814Sigor@sysoev.ru 
23914Sigor@sysoev.ru     /* Maximum size of message part. */
24014Sigor@sysoev.ru     uint32_t            max_size;
24114Sigor@sysoev.ru     /* Maximum interleave of message parts. */
24214Sigor@sysoev.ru     uint32_t            max_share;
243343Smax.romanov@nginx.com 
2441547Smax.romanov@nginx.com     uint32_t            active_websockets;
2451547Smax.romanov@nginx.com     uint32_t            active_requests;
2461131Smax.romanov@nginx.com 
24714Sigor@sysoev.ru     nxt_port_handler_t  handler;
248141Smax.romanov@nginx.com     nxt_port_handler_t  *data;
24914Sigor@sysoev.ru 
25065Sigor@sysoev.ru     nxt_mp_t            *mem_pool;
251141Smax.romanov@nginx.com     nxt_event_engine_t  *engine;
252141Smax.romanov@nginx.com 
25314Sigor@sysoev.ru     nxt_buf_t           *free_bufs;
25414Sigor@sysoev.ru     nxt_socket_t        pair[2];
25514Sigor@sysoev.ru 
25642Smax.romanov@nginx.com     nxt_port_id_t       id;
25714Sigor@sysoev.ru     nxt_pid_t           pid;
25842Smax.romanov@nginx.com 
259190Smax.romanov@nginx.com     nxt_lvlhsh_t        rpc_streams; /* stream to nxt_port_rpc_reg_t */
260190Smax.romanov@nginx.com     nxt_lvlhsh_t        rpc_peers;   /* peer to queue of nxt_port_rpc_reg_t */
261190Smax.romanov@nginx.com 
262352Smax.romanov@nginx.com     nxt_lvlhsh_t        frags;
263352Smax.romanov@nginx.com 
264343Smax.romanov@nginx.com     nxt_atomic_t        use_count;
265343Smax.romanov@nginx.com 
266141Smax.romanov@nginx.com     nxt_process_type_t  type;
2671555Smax.romanov@nginx.com 
2681555Smax.romanov@nginx.com     nxt_fd_t            queue_fd;
2691555Smax.romanov@nginx.com     void                *queue;
2701555Smax.romanov@nginx.com 
2711555Smax.romanov@nginx.com     void                *socket_msg;
2721555Smax.romanov@nginx.com     int                 from_socket;
27314Sigor@sysoev.ru };
27414Sigor@sysoev.ru 
27514Sigor@sysoev.ru 
27611Sigor@sysoev.ru typedef struct {
27742Smax.romanov@nginx.com     nxt_port_id_t       id;
27814Sigor@sysoev.ru     nxt_pid_t           pid;
27914Sigor@sysoev.ru     size_t              max_size;
28014Sigor@sysoev.ru     size_t              max_share;
28142Smax.romanov@nginx.com     nxt_process_type_t  type:8;
282168Svbart@nginx.com } nxt_port_msg_new_port_t;
28311Sigor@sysoev.ru 
28411Sigor@sysoev.ru 
2851545Smax.romanov@nginx.com typedef struct {
2861545Smax.romanov@nginx.com     nxt_port_id_t       id;
2871545Smax.romanov@nginx.com     nxt_pid_t           pid;
2881545Smax.romanov@nginx.com } nxt_port_msg_get_port_t;
2891545Smax.romanov@nginx.com 
2901545Smax.romanov@nginx.com 
2911546Smax.romanov@nginx.com typedef struct {
2921546Smax.romanov@nginx.com     uint32_t            id;
2931546Smax.romanov@nginx.com } nxt_port_msg_get_mmap_t;
2941546Smax.romanov@nginx.com 
2951546Smax.romanov@nginx.com 
29611Sigor@sysoev.ru /*
29714Sigor@sysoev.ru  * nxt_port_data_t size is allocation size
29814Sigor@sysoev.ru  * which enables effective reuse of memory pool cache.
29911Sigor@sysoev.ru  */
30011Sigor@sysoev.ru typedef union {
30111Sigor@sysoev.ru     nxt_buf_t                buf;
30214Sigor@sysoev.ru     nxt_port_msg_new_port_t  new_port;
30314Sigor@sysoev.ru } nxt_port_data_t;
30411Sigor@sysoev.ru 
30511Sigor@sysoev.ru 
306343Smax.romanov@nginx.com typedef void (*nxt_port_post_handler_t)(nxt_task_t *task, nxt_port_t *port,
307343Smax.romanov@nginx.com     void *data);
308343Smax.romanov@nginx.com 
309197Smax.romanov@nginx.com nxt_port_t *nxt_port_new(nxt_task_t *task, nxt_port_id_t id, nxt_pid_t pid,
310163Smax.romanov@nginx.com     nxt_process_type_t type);
311163Smax.romanov@nginx.com 
312141Smax.romanov@nginx.com nxt_port_id_t nxt_port_get_next_id(void);
313141Smax.romanov@nginx.com void nxt_port_reset_next_id(void);
314141Smax.romanov@nginx.com 
31514Sigor@sysoev.ru nxt_int_t nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port,
31614Sigor@sysoev.ru     size_t max_size);
31714Sigor@sysoev.ru void nxt_port_destroy(nxt_port_t *port);
318343Smax.romanov@nginx.com void nxt_port_close(nxt_task_t *task, nxt_port_t *port);
31914Sigor@sysoev.ru void nxt_port_write_enable(nxt_task_t *task, nxt_port_t *port);
32014Sigor@sysoev.ru void nxt_port_write_close(nxt_port_t *port);
32114Sigor@sysoev.ru void nxt_port_read_enable(nxt_task_t *task, nxt_port_t *port);
32214Sigor@sysoev.ru void nxt_port_read_close(nxt_port_t *port);
3231555Smax.romanov@nginx.com nxt_int_t nxt_port_socket_write2(nxt_task_t *task, nxt_port_t *port,
3241555Smax.romanov@nginx.com     nxt_uint_t type, nxt_fd_t fd, nxt_fd_t fd2, uint32_t stream,
3251555Smax.romanov@nginx.com     nxt_port_id_t reply_port, nxt_buf_t *b);
326423Smax.romanov@nginx.com 
327423Smax.romanov@nginx.com nxt_inline nxt_int_t
328423Smax.romanov@nginx.com nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port,
329423Smax.romanov@nginx.com     nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port,
330423Smax.romanov@nginx.com     nxt_buf_t *b)
331423Smax.romanov@nginx.com {
3321555Smax.romanov@nginx.com     return nxt_port_socket_write2(task, port, type, fd, -1, stream, reply_port,
3331555Smax.romanov@nginx.com                                   b);
334423Smax.romanov@nginx.com }
33514Sigor@sysoev.ru 
336141Smax.romanov@nginx.com void nxt_port_enable(nxt_task_t *task, nxt_port_t *port,
3371302St.nateldemoura@f5.com     const nxt_port_handlers_t *handlers);
33881Smax.romanov@nginx.com nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port,
339141Smax.romanov@nginx.com     nxt_port_t *new_port, uint32_t stream);
34020Sigor@sysoev.ru void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt,
34111Sigor@sysoev.ru     nxt_uint_t slot, nxt_fd_t fd);
342*1997St.nateldemoura@f5.com void nxt_port_remove_notify_others(nxt_task_t *task, nxt_process_t *process);
34311Sigor@sysoev.ru 
34414Sigor@sysoev.ru void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
34514Sigor@sysoev.ru void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
346320Smax.romanov@nginx.com void nxt_port_process_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
34714Sigor@sysoev.ru void nxt_port_change_log_file_handler(nxt_task_t *task,
34811Sigor@sysoev.ru     nxt_port_recv_msg_t *msg);
34942Smax.romanov@nginx.com void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
35014Sigor@sysoev.ru void nxt_port_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
351125Smax.romanov@nginx.com void nxt_port_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
35214Sigor@sysoev.ru void nxt_port_empty_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
35311Sigor@sysoev.ru 
354343Smax.romanov@nginx.com nxt_int_t nxt_port_post(nxt_task_t *task, nxt_port_t *port,
355343Smax.romanov@nginx.com     nxt_port_post_handler_t handler, void *data);
356343Smax.romanov@nginx.com void nxt_port_use(nxt_task_t *task, nxt_port_t *port, int i);
35711Sigor@sysoev.ru 
358425Smax.romanov@nginx.com nxt_inline void nxt_port_inc_use(nxt_port_t *port)
359425Smax.romanov@nginx.com {
360425Smax.romanov@nginx.com     nxt_atomic_fetch_add(&port->use_count, 1);
361425Smax.romanov@nginx.com }
362425Smax.romanov@nginx.com 
36311Sigor@sysoev.ru #endif /* _NXT_PORT_H_INCLUDED_ */
364