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, 14*205Smax.romanov@nginx.com NXT_PORT_MSG_SYNC = 0x400, 15189Smax.romanov@nginx.com 16189Smax.romanov@nginx.com NXT_PORT_MSG_MASK = 0xFF, 17189Smax.romanov@nginx.com 18189Smax.romanov@nginx.com _NXT_PORT_MSG_QUIT = 0, 19189Smax.romanov@nginx.com _NXT_PORT_MSG_NEW_PORT, 20189Smax.romanov@nginx.com _NXT_PORT_MSG_CHANGE_FILE, 21189Smax.romanov@nginx.com _NXT_PORT_MSG_MMAP, 22189Smax.romanov@nginx.com _NXT_PORT_MSG_DATA, 23189Smax.romanov@nginx.com _NXT_PORT_MSG_REMOVE_PID, 24189Smax.romanov@nginx.com _NXT_PORT_MSG_READY, 25192Smax.romanov@nginx.com _NXT_PORT_MSG_START_WORKER, 26198Sigor@sysoev.ru _NXT_PORT_MSG_SOCKET, 27190Smax.romanov@nginx.com _NXT_PORT_MSG_RPC_READY, 28190Smax.romanov@nginx.com _NXT_PORT_MSG_RPC_ERROR, 2942Smax.romanov@nginx.com 30125Smax.romanov@nginx.com NXT_PORT_MSG_MAX, 31189Smax.romanov@nginx.com 32189Smax.romanov@nginx.com NXT_PORT_MSG_QUIT = _NXT_PORT_MSG_QUIT | NXT_PORT_MSG_LAST, 33189Smax.romanov@nginx.com NXT_PORT_MSG_NEW_PORT = _NXT_PORT_MSG_NEW_PORT | NXT_PORT_MSG_LAST, 34189Smax.romanov@nginx.com NXT_PORT_MSG_CHANGE_FILE = _NXT_PORT_MSG_CHANGE_FILE | NXT_PORT_MSG_LAST, 35189Smax.romanov@nginx.com NXT_PORT_MSG_MMAP = _NXT_PORT_MSG_MMAP | NXT_PORT_MSG_LAST | 36*205Smax.romanov@nginx.com NXT_PORT_MSG_CLOSE_FD | NXT_PORT_MSG_SYNC, 37189Smax.romanov@nginx.com NXT_PORT_MSG_DATA = _NXT_PORT_MSG_DATA, 38189Smax.romanov@nginx.com NXT_PORT_MSG_DATA_LAST = _NXT_PORT_MSG_DATA | NXT_PORT_MSG_LAST, 39189Smax.romanov@nginx.com NXT_PORT_MSG_REMOVE_PID = _NXT_PORT_MSG_REMOVE_PID | NXT_PORT_MSG_LAST, 40189Smax.romanov@nginx.com NXT_PORT_MSG_READY = _NXT_PORT_MSG_READY | NXT_PORT_MSG_LAST, 41192Smax.romanov@nginx.com NXT_PORT_MSG_START_WORKER = _NXT_PORT_MSG_START_WORKER | 42192Smax.romanov@nginx.com NXT_PORT_MSG_LAST, 43198Sigor@sysoev.ru NXT_PORT_MSG_SOCKET = _NXT_PORT_MSG_SOCKET | NXT_PORT_MSG_LAST, 44190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_READY = _NXT_PORT_MSG_RPC_READY, 45190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_READY_LAST = _NXT_PORT_MSG_RPC_READY | NXT_PORT_MSG_LAST, 46190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_ERROR = _NXT_PORT_MSG_RPC_ERROR | NXT_PORT_MSG_LAST, 47125Smax.romanov@nginx.com } nxt_port_msg_type_t; 4842Smax.romanov@nginx.com 4914Sigor@sysoev.ru 5042Smax.romanov@nginx.com /* Passed as a first iov chunk. */ 5142Smax.romanov@nginx.com typedef struct { 5242Smax.romanov@nginx.com uint32_t stream; 5342Smax.romanov@nginx.com nxt_pid_t pid; 5442Smax.romanov@nginx.com nxt_port_id_t reply_port; 5542Smax.romanov@nginx.com 56189Smax.romanov@nginx.com uint8_t type; 5742Smax.romanov@nginx.com uint8_t last; /* 1 bit */ 5842Smax.romanov@nginx.com 5942Smax.romanov@nginx.com /* Message data send using mmap, next chunk is a nxt_port_mmap_msg_t. */ 6042Smax.romanov@nginx.com uint8_t mmap; /* 1 bit */ 61168Svbart@nginx.com } nxt_port_msg_t; 6214Sigor@sysoev.ru 6314Sigor@sysoev.ru 6414Sigor@sysoev.ru typedef struct { 6514Sigor@sysoev.ru nxt_queue_link_t link; 6614Sigor@sysoev.ru nxt_buf_t *buf; 6714Sigor@sysoev.ru size_t share; 6814Sigor@sysoev.ru nxt_fd_t fd; 69189Smax.romanov@nginx.com nxt_bool_t close_fd; 70*205Smax.romanov@nginx.com nxt_bool_t opened; 7114Sigor@sysoev.ru nxt_port_msg_t port_msg; 72122Smax.romanov@nginx.com 73122Smax.romanov@nginx.com nxt_work_t work; 74122Smax.romanov@nginx.com nxt_event_engine_t *engine; 75122Smax.romanov@nginx.com nxt_mp_t *mem_pool; 7614Sigor@sysoev.ru } nxt_port_send_msg_t; 7714Sigor@sysoev.ru 7814Sigor@sysoev.ru 7920Sigor@sysoev.ru struct nxt_port_recv_msg_s { 8014Sigor@sysoev.ru nxt_fd_t fd; 8114Sigor@sysoev.ru nxt_buf_t *buf; 8214Sigor@sysoev.ru nxt_port_t *port; 8342Smax.romanov@nginx.com nxt_port_msg_t port_msg; 8482Smax.romanov@nginx.com size_t size; 85141Smax.romanov@nginx.com nxt_port_t *new_port; 8620Sigor@sysoev.ru }; 8714Sigor@sysoev.ru 88141Smax.romanov@nginx.com typedef struct nxt_app_s nxt_app_t; 8914Sigor@sysoev.ru 9014Sigor@sysoev.ru struct nxt_port_s { 9114Sigor@sysoev.ru nxt_fd_event_t socket; 9214Sigor@sysoev.ru 93125Smax.romanov@nginx.com nxt_queue_link_t link; /* for nxt_process_t.ports */ 94141Smax.romanov@nginx.com nxt_process_t *process; 95141Smax.romanov@nginx.com 96141Smax.romanov@nginx.com nxt_queue_link_t app_link; /* for nxt_app_t.ports */ 97141Smax.romanov@nginx.com nxt_app_t *app; 9842Smax.romanov@nginx.com 9914Sigor@sysoev.ru nxt_queue_t messages; /* of nxt_port_send_msg_t */ 10014Sigor@sysoev.ru 10114Sigor@sysoev.ru /* Maximum size of message part. */ 10214Sigor@sysoev.ru uint32_t max_size; 10314Sigor@sysoev.ru /* Maximum interleave of message parts. */ 10414Sigor@sysoev.ru uint32_t max_share; 105167Smax.romanov@nginx.com uint32_t app_req_id; 10614Sigor@sysoev.ru 10714Sigor@sysoev.ru nxt_port_handler_t handler; 108141Smax.romanov@nginx.com nxt_port_handler_t *data; 10914Sigor@sysoev.ru 11065Sigor@sysoev.ru nxt_mp_t *mem_pool; 111141Smax.romanov@nginx.com nxt_event_engine_t *engine; 112141Smax.romanov@nginx.com 11314Sigor@sysoev.ru nxt_buf_t *free_bufs; 11414Sigor@sysoev.ru nxt_socket_t pair[2]; 11514Sigor@sysoev.ru 11642Smax.romanov@nginx.com nxt_port_id_t id; 11714Sigor@sysoev.ru nxt_pid_t pid; 11842Smax.romanov@nginx.com 119190Smax.romanov@nginx.com nxt_lvlhsh_t rpc_streams; /* stream to nxt_port_rpc_reg_t */ 120190Smax.romanov@nginx.com nxt_lvlhsh_t rpc_peers; /* peer to queue of nxt_port_rpc_reg_t */ 121190Smax.romanov@nginx.com uint32_t next_stream; 122190Smax.romanov@nginx.com 123141Smax.romanov@nginx.com nxt_process_type_t type; 124163Smax.romanov@nginx.com nxt_work_t work; 125197Smax.romanov@nginx.com 126197Smax.romanov@nginx.com struct iovec *iov; 127197Smax.romanov@nginx.com void *mmsg_buf; 12814Sigor@sysoev.ru }; 12914Sigor@sysoev.ru 13014Sigor@sysoev.ru 13111Sigor@sysoev.ru typedef struct { 13242Smax.romanov@nginx.com nxt_port_id_t id; 13314Sigor@sysoev.ru nxt_pid_t pid; 13414Sigor@sysoev.ru size_t max_size; 13514Sigor@sysoev.ru size_t max_share; 13642Smax.romanov@nginx.com nxt_process_type_t type:8; 137168Svbart@nginx.com } nxt_port_msg_new_port_t; 13811Sigor@sysoev.ru 13911Sigor@sysoev.ru 14011Sigor@sysoev.ru /* 14114Sigor@sysoev.ru * nxt_port_data_t size is allocation size 14214Sigor@sysoev.ru * which enables effective reuse of memory pool cache. 14311Sigor@sysoev.ru */ 14411Sigor@sysoev.ru typedef union { 14511Sigor@sysoev.ru nxt_buf_t buf; 14614Sigor@sysoev.ru nxt_port_msg_new_port_t new_port; 14714Sigor@sysoev.ru } nxt_port_data_t; 14811Sigor@sysoev.ru 14911Sigor@sysoev.ru 150197Smax.romanov@nginx.com nxt_port_t *nxt_port_new(nxt_task_t *task, nxt_port_id_t id, nxt_pid_t pid, 151163Smax.romanov@nginx.com nxt_process_type_t type); 152163Smax.romanov@nginx.com nxt_bool_t nxt_port_release(nxt_port_t *port); 153163Smax.romanov@nginx.com 154141Smax.romanov@nginx.com nxt_port_id_t nxt_port_get_next_id(void); 155141Smax.romanov@nginx.com void nxt_port_reset_next_id(void); 156141Smax.romanov@nginx.com 15714Sigor@sysoev.ru nxt_int_t nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, 15814Sigor@sysoev.ru size_t max_size); 15914Sigor@sysoev.ru void nxt_port_destroy(nxt_port_t *port); 16014Sigor@sysoev.ru void nxt_port_write_enable(nxt_task_t *task, nxt_port_t *port); 16114Sigor@sysoev.ru void nxt_port_write_close(nxt_port_t *port); 16214Sigor@sysoev.ru void nxt_port_read_enable(nxt_task_t *task, nxt_port_t *port); 16314Sigor@sysoev.ru void nxt_port_read_close(nxt_port_t *port); 16414Sigor@sysoev.ru nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, 16542Smax.romanov@nginx.com nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port, 16642Smax.romanov@nginx.com nxt_buf_t *b); 16714Sigor@sysoev.ru 168141Smax.romanov@nginx.com void nxt_port_enable(nxt_task_t *task, nxt_port_t *port, 16914Sigor@sysoev.ru nxt_port_handler_t *handlers); 17020Sigor@sysoev.ru void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, 171141Smax.romanov@nginx.com nxt_port_t *port, uint32_t stream); 17281Smax.romanov@nginx.com nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port, 173141Smax.romanov@nginx.com nxt_port_t *new_port, uint32_t stream); 17420Sigor@sysoev.ru void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt, 17511Sigor@sysoev.ru nxt_uint_t slot, nxt_fd_t fd); 17611Sigor@sysoev.ru 17714Sigor@sysoev.ru void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17814Sigor@sysoev.ru void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 179141Smax.romanov@nginx.com void nxt_port_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 18014Sigor@sysoev.ru void nxt_port_change_log_file_handler(nxt_task_t *task, 18111Sigor@sysoev.ru nxt_port_recv_msg_t *msg); 18242Smax.romanov@nginx.com void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 18314Sigor@sysoev.ru void nxt_port_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 184125Smax.romanov@nginx.com void nxt_port_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 18514Sigor@sysoev.ru void nxt_port_empty_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 18611Sigor@sysoev.ru 18711Sigor@sysoev.ru 18811Sigor@sysoev.ru #endif /* _NXT_PORT_H_INCLUDED_ */ 189