summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_port.h
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2017-09-15 20:30:34 +0300
committerMax Romanov <max.romanov@nginx.com>2017-09-15 20:30:34 +0300
commit838d9946ac2d9c9a9ba41d5b88209bfc5f2325d0 (patch)
treecd6458cb2362ef2550fc5629407f5f623c11945f /src/nxt_port.h
parent1449e27cb42a5b3ca2d2106a39fee3f1d54a340e (diff)
downloadunit-838d9946ac2d9c9a9ba41d5b88209bfc5f2325d0.tar.gz
unit-838d9946ac2d9c9a9ba41d5b88209bfc5f2325d0.tar.bz2
Introducing named port message handlers to avoid misprints.
Diffstat (limited to 'src/nxt_port.h')
-rw-r--r--src/nxt_port.h102
1 files changed, 73 insertions, 29 deletions
diff --git a/src/nxt_port.h b/src/nxt_port.h
index 1e501390..c5b2b40e 100644
--- a/src/nxt_port.h
+++ b/src/nxt_port.h
@@ -8,6 +8,40 @@
#define _NXT_PORT_H_INCLUDED_
+struct nxt_port_handlers_s {
+ /* RPC responses. */
+ nxt_port_handler_t rpc_ready;
+ nxt_port_handler_t rpc_error;
+
+ /* Main process RPC requests. */
+ nxt_port_handler_t start_worker;
+ nxt_port_handler_t socket;
+ nxt_port_handler_t modules;
+ nxt_port_handler_t conf_store;
+
+ /* File descriptor exchange. */
+ nxt_port_handler_t change_file;
+ nxt_port_handler_t new_port;
+ nxt_port_handler_t mmap;
+
+ /* New process ready. */
+ nxt_port_handler_t process_ready;
+
+ /* Process exit/crash notification. */
+ nxt_port_handler_t remove_pid;
+
+ /* Stop process command. */
+ nxt_port_handler_t quit;
+
+ /* Various data. */
+ nxt_port_handler_t data;
+};
+
+
+#define nxt_port_handler_idx(name) \
+ ( &((nxt_port_handlers_t *) 0)->name - (nxt_port_handler_t *) 0)
+
+
typedef enum {
NXT_PORT_MSG_LAST = 0x100,
NXT_PORT_MSG_CLOSE_FD = 0x200,
@@ -15,39 +49,49 @@ typedef enum {
NXT_PORT_MSG_MASK = 0xFF,
- _NXT_PORT_MSG_QUIT = 0,
- _NXT_PORT_MSG_NEW_PORT,
- _NXT_PORT_MSG_CHANGE_FILE,
- _NXT_PORT_MSG_MMAP,
- _NXT_PORT_MSG_DATA,
- _NXT_PORT_MSG_REMOVE_PID,
- _NXT_PORT_MSG_READY,
- _NXT_PORT_MSG_START_WORKER,
- _NXT_PORT_MSG_SOCKET,
- _NXT_PORT_MSG_MODULES,
- _NXT_PORT_MSG_CONF_STORE,
- _NXT_PORT_MSG_RPC_READY,
- _NXT_PORT_MSG_RPC_ERROR,
-
- NXT_PORT_MSG_MAX,
+ _NXT_PORT_MSG_RPC_READY = nxt_port_handler_idx(rpc_ready),
+ _NXT_PORT_MSG_RPC_ERROR = nxt_port_handler_idx(rpc_error),
+
+ _NXT_PORT_MSG_START_WORKER = nxt_port_handler_idx(start_worker),
+ _NXT_PORT_MSG_SOCKET = nxt_port_handler_idx(socket),
+ _NXT_PORT_MSG_MODULES = nxt_port_handler_idx(modules),
+ _NXT_PORT_MSG_CONF_STORE = nxt_port_handler_idx(conf_store),
+
+ _NXT_PORT_MSG_CHANGE_FILE = nxt_port_handler_idx(change_file),
+ _NXT_PORT_MSG_NEW_PORT = nxt_port_handler_idx(new_port),
+ _NXT_PORT_MSG_MMAP = nxt_port_handler_idx(mmap),
+
+ _NXT_PORT_MSG_PROCESS_READY = nxt_port_handler_idx(process_ready),
+ _NXT_PORT_MSG_REMOVE_PID = nxt_port_handler_idx(remove_pid),
+ _NXT_PORT_MSG_QUIT = nxt_port_handler_idx(quit),
+
+ _NXT_PORT_MSG_DATA = nxt_port_handler_idx(data),
+
+ NXT_PORT_MSG_MAX = sizeof(nxt_port_handlers_t) /
+ sizeof(nxt_port_handler_t),
+
+ NXT_PORT_MSG_RPC_READY = _NXT_PORT_MSG_RPC_READY,
+ NXT_PORT_MSG_RPC_READY_LAST = _NXT_PORT_MSG_RPC_READY | NXT_PORT_MSG_LAST,
+ NXT_PORT_MSG_RPC_ERROR = _NXT_PORT_MSG_RPC_ERROR | NXT_PORT_MSG_LAST,
- NXT_PORT_MSG_QUIT = _NXT_PORT_MSG_QUIT | NXT_PORT_MSG_LAST,
- NXT_PORT_MSG_NEW_PORT = _NXT_PORT_MSG_NEW_PORT | NXT_PORT_MSG_LAST,
- NXT_PORT_MSG_CHANGE_FILE = _NXT_PORT_MSG_CHANGE_FILE | NXT_PORT_MSG_LAST,
- NXT_PORT_MSG_MMAP = _NXT_PORT_MSG_MMAP | NXT_PORT_MSG_LAST |
- NXT_PORT_MSG_CLOSE_FD | NXT_PORT_MSG_SYNC,
- NXT_PORT_MSG_DATA = _NXT_PORT_MSG_DATA,
- NXT_PORT_MSG_DATA_LAST = _NXT_PORT_MSG_DATA | NXT_PORT_MSG_LAST,
- NXT_PORT_MSG_REMOVE_PID = _NXT_PORT_MSG_REMOVE_PID | NXT_PORT_MSG_LAST,
- NXT_PORT_MSG_READY = _NXT_PORT_MSG_READY | NXT_PORT_MSG_LAST,
NXT_PORT_MSG_START_WORKER = _NXT_PORT_MSG_START_WORKER |
NXT_PORT_MSG_LAST,
NXT_PORT_MSG_SOCKET = _NXT_PORT_MSG_SOCKET | NXT_PORT_MSG_LAST,
NXT_PORT_MSG_MODULES = _NXT_PORT_MSG_MODULES | NXT_PORT_MSG_LAST,
NXT_PORT_MSG_CONF_STORE = _NXT_PORT_MSG_CONF_STORE | NXT_PORT_MSG_LAST,
- NXT_PORT_MSG_RPC_READY = _NXT_PORT_MSG_RPC_READY,
- NXT_PORT_MSG_RPC_READY_LAST = _NXT_PORT_MSG_RPC_READY | NXT_PORT_MSG_LAST,
- NXT_PORT_MSG_RPC_ERROR = _NXT_PORT_MSG_RPC_ERROR | NXT_PORT_MSG_LAST,
+
+ NXT_PORT_MSG_CHANGE_FILE = _NXT_PORT_MSG_CHANGE_FILE | NXT_PORT_MSG_LAST,
+ NXT_PORT_MSG_NEW_PORT = _NXT_PORT_MSG_NEW_PORT | NXT_PORT_MSG_LAST,
+ NXT_PORT_MSG_MMAP = _NXT_PORT_MSG_MMAP | NXT_PORT_MSG_LAST |
+ NXT_PORT_MSG_CLOSE_FD | NXT_PORT_MSG_SYNC,
+
+ NXT_PORT_MSG_PROCESS_READY = _NXT_PORT_MSG_PROCESS_READY |
+ NXT_PORT_MSG_LAST,
+ NXT_PORT_MSG_QUIT = _NXT_PORT_MSG_QUIT | NXT_PORT_MSG_LAST,
+ NXT_PORT_MSG_REMOVE_PID = _NXT_PORT_MSG_REMOVE_PID | NXT_PORT_MSG_LAST,
+
+ NXT_PORT_MSG_DATA = _NXT_PORT_MSG_DATA,
+ NXT_PORT_MSG_DATA_LAST = _NXT_PORT_MSG_DATA | NXT_PORT_MSG_LAST,
} nxt_port_msg_type_t;
@@ -169,7 +213,7 @@ nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port,
nxt_buf_t *b);
void nxt_port_enable(nxt_task_t *task, nxt_port_t *port,
- nxt_port_handler_t *handlers);
+ nxt_port_handlers_t *handlers);
void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt,
nxt_port_t *port, uint32_t stream);
nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port,
@@ -179,7 +223,7 @@ void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt,
void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
-void nxt_port_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
+void nxt_port_process_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);
void nxt_port_change_log_file_handler(nxt_task_t *task,
nxt_port_recv_msg_t *msg);
void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg);