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 1142Smax.romanov@nginx.com typedef enum { 12189Smax.romanov@nginx.com NXT_PORT_MSG_LAST = 0x100, 13189Smax.romanov@nginx.com NXT_PORT_MSG_CLOSE_FD = 0x200, 14189Smax.romanov@nginx.com 15189Smax.romanov@nginx.com NXT_PORT_MSG_MASK = 0xFF, 16189Smax.romanov@nginx.com 17189Smax.romanov@nginx.com _NXT_PORT_MSG_QUIT = 0, 18189Smax.romanov@nginx.com _NXT_PORT_MSG_NEW_PORT, 19189Smax.romanov@nginx.com _NXT_PORT_MSG_CHANGE_FILE, 20189Smax.romanov@nginx.com _NXT_PORT_MSG_MMAP, 21189Smax.romanov@nginx.com _NXT_PORT_MSG_DATA, 22189Smax.romanov@nginx.com _NXT_PORT_MSG_REMOVE_PID, 23189Smax.romanov@nginx.com _NXT_PORT_MSG_READY, 24192Smax.romanov@nginx.com _NXT_PORT_MSG_START_WORKER, 25*198Sigor@sysoev.ru _NXT_PORT_MSG_SOCKET, 26190Smax.romanov@nginx.com _NXT_PORT_MSG_RPC_READY, 27190Smax.romanov@nginx.com _NXT_PORT_MSG_RPC_ERROR, 2842Smax.romanov@nginx.com 29125Smax.romanov@nginx.com NXT_PORT_MSG_MAX, 30189Smax.romanov@nginx.com 31189Smax.romanov@nginx.com NXT_PORT_MSG_QUIT = _NXT_PORT_MSG_QUIT | NXT_PORT_MSG_LAST, 32189Smax.romanov@nginx.com NXT_PORT_MSG_NEW_PORT = _NXT_PORT_MSG_NEW_PORT | NXT_PORT_MSG_LAST, 33189Smax.romanov@nginx.com NXT_PORT_MSG_CHANGE_FILE = _NXT_PORT_MSG_CHANGE_FILE | NXT_PORT_MSG_LAST, 34189Smax.romanov@nginx.com NXT_PORT_MSG_MMAP = _NXT_PORT_MSG_MMAP | NXT_PORT_MSG_LAST | 35189Smax.romanov@nginx.com NXT_PORT_MSG_CLOSE_FD, 36189Smax.romanov@nginx.com NXT_PORT_MSG_DATA = _NXT_PORT_MSG_DATA, 37189Smax.romanov@nginx.com NXT_PORT_MSG_DATA_LAST = _NXT_PORT_MSG_DATA | NXT_PORT_MSG_LAST, 38189Smax.romanov@nginx.com NXT_PORT_MSG_REMOVE_PID = _NXT_PORT_MSG_REMOVE_PID | NXT_PORT_MSG_LAST, 39189Smax.romanov@nginx.com NXT_PORT_MSG_READY = _NXT_PORT_MSG_READY | NXT_PORT_MSG_LAST, 40192Smax.romanov@nginx.com NXT_PORT_MSG_START_WORKER = _NXT_PORT_MSG_START_WORKER | 41192Smax.romanov@nginx.com NXT_PORT_MSG_LAST, 42*198Sigor@sysoev.ru NXT_PORT_MSG_SOCKET = _NXT_PORT_MSG_SOCKET | NXT_PORT_MSG_LAST, 43190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_READY = _NXT_PORT_MSG_RPC_READY, 44190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_READY_LAST = _NXT_PORT_MSG_RPC_READY | NXT_PORT_MSG_LAST, 45190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_ERROR = _NXT_PORT_MSG_RPC_ERROR | NXT_PORT_MSG_LAST, 46125Smax.romanov@nginx.com } nxt_port_msg_type_t; 4742Smax.romanov@nginx.com 4814Sigor@sysoev.ru 4942Smax.romanov@nginx.com /* Passed as a first iov chunk. */ 5042Smax.romanov@nginx.com typedef struct { 5142Smax.romanov@nginx.com uint32_t stream; 5242Smax.romanov@nginx.com nxt_pid_t pid; 5342Smax.romanov@nginx.com nxt_port_id_t reply_port; 5442Smax.romanov@nginx.com 55189Smax.romanov@nginx.com uint8_t type; 5642Smax.romanov@nginx.com uint8_t last; /* 1 bit */ 5742Smax.romanov@nginx.com 5842Smax.romanov@nginx.com /* Message data send using mmap, next chunk is a nxt_port_mmap_msg_t. */ 5942Smax.romanov@nginx.com uint8_t mmap; /* 1 bit */ 60168Svbart@nginx.com } nxt_port_msg_t; 6114Sigor@sysoev.ru 6214Sigor@sysoev.ru 6314Sigor@sysoev.ru typedef struct { 6414Sigor@sysoev.ru nxt_queue_link_t link; 6514Sigor@sysoev.ru nxt_buf_t *buf; 6614Sigor@sysoev.ru size_t share; 6714Sigor@sysoev.ru nxt_fd_t fd; 68189Smax.romanov@nginx.com nxt_bool_t close_fd; 6914Sigor@sysoev.ru nxt_port_msg_t port_msg; 70122Smax.romanov@nginx.com 71122Smax.romanov@nginx.com nxt_work_t work; 72122Smax.romanov@nginx.com nxt_event_engine_t *engine; 73122Smax.romanov@nginx.com nxt_mp_t *mem_pool; 7414Sigor@sysoev.ru } nxt_port_send_msg_t; 7514Sigor@sysoev.ru 7614Sigor@sysoev.ru 7720Sigor@sysoev.ru struct nxt_port_recv_msg_s { 7814Sigor@sysoev.ru nxt_fd_t fd; 7914Sigor@sysoev.ru nxt_buf_t *buf; 8014Sigor@sysoev.ru nxt_port_t *port; 8142Smax.romanov@nginx.com nxt_port_msg_t port_msg; 8282Smax.romanov@nginx.com size_t size; 83141Smax.romanov@nginx.com nxt_port_t *new_port; 8420Sigor@sysoev.ru }; 8514Sigor@sysoev.ru 86141Smax.romanov@nginx.com typedef struct nxt_app_s nxt_app_t; 8714Sigor@sysoev.ru 8814Sigor@sysoev.ru struct nxt_port_s { 8914Sigor@sysoev.ru nxt_fd_event_t socket; 9014Sigor@sysoev.ru 91125Smax.romanov@nginx.com nxt_queue_link_t link; /* for nxt_process_t.ports */ 92141Smax.romanov@nginx.com nxt_process_t *process; 93141Smax.romanov@nginx.com 94141Smax.romanov@nginx.com nxt_queue_link_t app_link; /* for nxt_app_t.ports */ 95141Smax.romanov@nginx.com nxt_app_t *app; 9642Smax.romanov@nginx.com 9714Sigor@sysoev.ru nxt_queue_t messages; /* of nxt_port_send_msg_t */ 9814Sigor@sysoev.ru 9914Sigor@sysoev.ru /* Maximum size of message part. */ 10014Sigor@sysoev.ru uint32_t max_size; 10114Sigor@sysoev.ru /* Maximum interleave of message parts. */ 10214Sigor@sysoev.ru uint32_t max_share; 103167Smax.romanov@nginx.com uint32_t app_req_id; 10414Sigor@sysoev.ru 10514Sigor@sysoev.ru nxt_port_handler_t handler; 106141Smax.romanov@nginx.com nxt_port_handler_t *data; 10714Sigor@sysoev.ru 10865Sigor@sysoev.ru nxt_mp_t *mem_pool; 109141Smax.romanov@nginx.com nxt_event_engine_t *engine; 110141Smax.romanov@nginx.com 11114Sigor@sysoev.ru nxt_buf_t *free_bufs; 11214Sigor@sysoev.ru nxt_socket_t pair[2]; 11314Sigor@sysoev.ru 11442Smax.romanov@nginx.com nxt_port_id_t id; 11514Sigor@sysoev.ru nxt_pid_t pid; 11642Smax.romanov@nginx.com 117190Smax.romanov@nginx.com nxt_lvlhsh_t rpc_streams; /* stream to nxt_port_rpc_reg_t */ 118190Smax.romanov@nginx.com nxt_lvlhsh_t rpc_peers; /* peer to queue of nxt_port_rpc_reg_t */ 119190Smax.romanov@nginx.com uint32_t next_stream; 120190Smax.romanov@nginx.com 121141Smax.romanov@nginx.com nxt_process_type_t type; 122163Smax.romanov@nginx.com nxt_work_t work; 123197Smax.romanov@nginx.com 124197Smax.romanov@nginx.com struct iovec *iov; 125197Smax.romanov@nginx.com void *mmsg_buf; 12614Sigor@sysoev.ru }; 12714Sigor@sysoev.ru 12814Sigor@sysoev.ru 12911Sigor@sysoev.ru typedef struct { 13042Smax.romanov@nginx.com nxt_port_id_t id; 13114Sigor@sysoev.ru nxt_pid_t pid; 13214Sigor@sysoev.ru size_t max_size; 13314Sigor@sysoev.ru size_t max_share; 13442Smax.romanov@nginx.com nxt_process_type_t type:8; 135168Svbart@nginx.com } nxt_port_msg_new_port_t; 13611Sigor@sysoev.ru 13711Sigor@sysoev.ru 13811Sigor@sysoev.ru /* 13914Sigor@sysoev.ru * nxt_port_data_t size is allocation size 14014Sigor@sysoev.ru * which enables effective reuse of memory pool cache. 14111Sigor@sysoev.ru */ 14211Sigor@sysoev.ru typedef union { 14311Sigor@sysoev.ru nxt_buf_t buf; 14414Sigor@sysoev.ru nxt_port_msg_new_port_t new_port; 14514Sigor@sysoev.ru } nxt_port_data_t; 14611Sigor@sysoev.ru 14711Sigor@sysoev.ru 148197Smax.romanov@nginx.com nxt_port_t *nxt_port_new(nxt_task_t *task, nxt_port_id_t id, nxt_pid_t pid, 149163Smax.romanov@nginx.com nxt_process_type_t type); 150163Smax.romanov@nginx.com nxt_bool_t nxt_port_release(nxt_port_t *port); 151163Smax.romanov@nginx.com 152141Smax.romanov@nginx.com nxt_port_id_t nxt_port_get_next_id(void); 153141Smax.romanov@nginx.com void nxt_port_reset_next_id(void); 154141Smax.romanov@nginx.com 15514Sigor@sysoev.ru nxt_int_t nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, 15614Sigor@sysoev.ru size_t max_size); 15714Sigor@sysoev.ru void nxt_port_destroy(nxt_port_t *port); 15814Sigor@sysoev.ru void nxt_port_write_enable(nxt_task_t *task, nxt_port_t *port); 15914Sigor@sysoev.ru void nxt_port_write_close(nxt_port_t *port); 16014Sigor@sysoev.ru void nxt_port_read_enable(nxt_task_t *task, nxt_port_t *port); 16114Sigor@sysoev.ru void nxt_port_read_close(nxt_port_t *port); 16214Sigor@sysoev.ru nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, 16342Smax.romanov@nginx.com nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port, 16442Smax.romanov@nginx.com nxt_buf_t *b); 16514Sigor@sysoev.ru 166141Smax.romanov@nginx.com void nxt_port_enable(nxt_task_t *task, nxt_port_t *port, 16714Sigor@sysoev.ru nxt_port_handler_t *handlers); 16820Sigor@sysoev.ru void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, 169141Smax.romanov@nginx.com nxt_port_t *port, uint32_t stream); 17081Smax.romanov@nginx.com nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port, 171141Smax.romanov@nginx.com nxt_port_t *new_port, uint32_t stream); 17220Sigor@sysoev.ru void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt, 17311Sigor@sysoev.ru nxt_uint_t slot, nxt_fd_t fd); 17411Sigor@sysoev.ru 17514Sigor@sysoev.ru void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17614Sigor@sysoev.ru void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 177141Smax.romanov@nginx.com void nxt_port_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17814Sigor@sysoev.ru void nxt_port_change_log_file_handler(nxt_task_t *task, 17911Sigor@sysoev.ru nxt_port_recv_msg_t *msg); 18042Smax.romanov@nginx.com void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 18114Sigor@sysoev.ru void nxt_port_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 182125Smax.romanov@nginx.com void nxt_port_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 18314Sigor@sysoev.ru void nxt_port_empty_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 18411Sigor@sysoev.ru 18511Sigor@sysoev.ru 18611Sigor@sysoev.ru #endif /* _NXT_PORT_H_INCLUDED_ */ 187