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, 25190Smax.romanov@nginx.com _NXT_PORT_MSG_RPC_READY, 26190Smax.romanov@nginx.com _NXT_PORT_MSG_RPC_ERROR, 2742Smax.romanov@nginx.com 28125Smax.romanov@nginx.com NXT_PORT_MSG_MAX, 29189Smax.romanov@nginx.com 30189Smax.romanov@nginx.com NXT_PORT_MSG_QUIT = _NXT_PORT_MSG_QUIT | NXT_PORT_MSG_LAST, 31189Smax.romanov@nginx.com NXT_PORT_MSG_NEW_PORT = _NXT_PORT_MSG_NEW_PORT | NXT_PORT_MSG_LAST, 32189Smax.romanov@nginx.com NXT_PORT_MSG_CHANGE_FILE = _NXT_PORT_MSG_CHANGE_FILE | NXT_PORT_MSG_LAST, 33189Smax.romanov@nginx.com NXT_PORT_MSG_MMAP = _NXT_PORT_MSG_MMAP | NXT_PORT_MSG_LAST | 34189Smax.romanov@nginx.com NXT_PORT_MSG_CLOSE_FD, 35189Smax.romanov@nginx.com NXT_PORT_MSG_DATA = _NXT_PORT_MSG_DATA, 36189Smax.romanov@nginx.com NXT_PORT_MSG_DATA_LAST = _NXT_PORT_MSG_DATA | NXT_PORT_MSG_LAST, 37189Smax.romanov@nginx.com NXT_PORT_MSG_REMOVE_PID = _NXT_PORT_MSG_REMOVE_PID | NXT_PORT_MSG_LAST, 38189Smax.romanov@nginx.com NXT_PORT_MSG_READY = _NXT_PORT_MSG_READY | NXT_PORT_MSG_LAST, 39192Smax.romanov@nginx.com NXT_PORT_MSG_START_WORKER = _NXT_PORT_MSG_START_WORKER | 40192Smax.romanov@nginx.com NXT_PORT_MSG_LAST, 41190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_READY = _NXT_PORT_MSG_RPC_READY, 42190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_READY_LAST = _NXT_PORT_MSG_RPC_READY | NXT_PORT_MSG_LAST, 43190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_ERROR = _NXT_PORT_MSG_RPC_ERROR | NXT_PORT_MSG_LAST, 44125Smax.romanov@nginx.com } nxt_port_msg_type_t; 4542Smax.romanov@nginx.com 4614Sigor@sysoev.ru 4742Smax.romanov@nginx.com /* Passed as a first iov chunk. */ 4842Smax.romanov@nginx.com typedef struct { 4942Smax.romanov@nginx.com uint32_t stream; 5042Smax.romanov@nginx.com nxt_pid_t pid; 5142Smax.romanov@nginx.com nxt_port_id_t reply_port; 5242Smax.romanov@nginx.com 53189Smax.romanov@nginx.com uint8_t type; 5442Smax.romanov@nginx.com uint8_t last; /* 1 bit */ 5542Smax.romanov@nginx.com 5642Smax.romanov@nginx.com /* Message data send using mmap, next chunk is a nxt_port_mmap_msg_t. */ 5742Smax.romanov@nginx.com uint8_t mmap; /* 1 bit */ 58168Svbart@nginx.com } nxt_port_msg_t; 5914Sigor@sysoev.ru 6014Sigor@sysoev.ru 6114Sigor@sysoev.ru typedef struct { 6214Sigor@sysoev.ru nxt_queue_link_t link; 6314Sigor@sysoev.ru nxt_buf_t *buf; 6414Sigor@sysoev.ru size_t share; 6514Sigor@sysoev.ru nxt_fd_t fd; 66189Smax.romanov@nginx.com nxt_bool_t close_fd; 6714Sigor@sysoev.ru nxt_port_msg_t port_msg; 68122Smax.romanov@nginx.com 69122Smax.romanov@nginx.com nxt_work_t work; 70122Smax.romanov@nginx.com nxt_event_engine_t *engine; 71122Smax.romanov@nginx.com nxt_mp_t *mem_pool; 7214Sigor@sysoev.ru } nxt_port_send_msg_t; 7314Sigor@sysoev.ru 7414Sigor@sysoev.ru 7520Sigor@sysoev.ru struct nxt_port_recv_msg_s { 7614Sigor@sysoev.ru nxt_fd_t fd; 7714Sigor@sysoev.ru nxt_buf_t *buf; 7814Sigor@sysoev.ru nxt_port_t *port; 7942Smax.romanov@nginx.com nxt_port_msg_t port_msg; 8082Smax.romanov@nginx.com size_t size; 81141Smax.romanov@nginx.com nxt_port_t *new_port; 8220Sigor@sysoev.ru }; 8314Sigor@sysoev.ru 84141Smax.romanov@nginx.com typedef struct nxt_app_s nxt_app_t; 8514Sigor@sysoev.ru 8614Sigor@sysoev.ru struct nxt_port_s { 8714Sigor@sysoev.ru nxt_fd_event_t socket; 8814Sigor@sysoev.ru 89125Smax.romanov@nginx.com nxt_queue_link_t link; /* for nxt_process_t.ports */ 90141Smax.romanov@nginx.com nxt_process_t *process; 91141Smax.romanov@nginx.com 92141Smax.romanov@nginx.com nxt_queue_link_t app_link; /* for nxt_app_t.ports */ 93141Smax.romanov@nginx.com nxt_app_t *app; 9442Smax.romanov@nginx.com 9514Sigor@sysoev.ru nxt_queue_t messages; /* of nxt_port_send_msg_t */ 9614Sigor@sysoev.ru 9714Sigor@sysoev.ru /* Maximum size of message part. */ 9814Sigor@sysoev.ru uint32_t max_size; 9914Sigor@sysoev.ru /* Maximum interleave of message parts. */ 10014Sigor@sysoev.ru uint32_t max_share; 101167Smax.romanov@nginx.com uint32_t app_req_id; 10214Sigor@sysoev.ru 10314Sigor@sysoev.ru nxt_port_handler_t handler; 104141Smax.romanov@nginx.com nxt_port_handler_t *data; 10514Sigor@sysoev.ru 10665Sigor@sysoev.ru nxt_mp_t *mem_pool; 107141Smax.romanov@nginx.com nxt_event_engine_t *engine; 108141Smax.romanov@nginx.com 10914Sigor@sysoev.ru nxt_buf_t *free_bufs; 11014Sigor@sysoev.ru nxt_socket_t pair[2]; 11114Sigor@sysoev.ru 11242Smax.romanov@nginx.com nxt_port_id_t id; 11314Sigor@sysoev.ru nxt_pid_t pid; 11442Smax.romanov@nginx.com 115190Smax.romanov@nginx.com nxt_lvlhsh_t rpc_streams; /* stream to nxt_port_rpc_reg_t */ 116190Smax.romanov@nginx.com nxt_lvlhsh_t rpc_peers; /* peer to queue of nxt_port_rpc_reg_t */ 117190Smax.romanov@nginx.com uint32_t next_stream; 118190Smax.romanov@nginx.com 119141Smax.romanov@nginx.com nxt_process_type_t type; 120163Smax.romanov@nginx.com nxt_work_t work; 121*197Smax.romanov@nginx.com 122*197Smax.romanov@nginx.com struct iovec *iov; 123*197Smax.romanov@nginx.com void *mmsg_buf; 12414Sigor@sysoev.ru }; 12514Sigor@sysoev.ru 12614Sigor@sysoev.ru 12711Sigor@sysoev.ru typedef struct { 12842Smax.romanov@nginx.com nxt_port_id_t id; 12914Sigor@sysoev.ru nxt_pid_t pid; 13014Sigor@sysoev.ru size_t max_size; 13114Sigor@sysoev.ru size_t max_share; 13242Smax.romanov@nginx.com nxt_process_type_t type:8; 133168Svbart@nginx.com } nxt_port_msg_new_port_t; 13411Sigor@sysoev.ru 13511Sigor@sysoev.ru 13611Sigor@sysoev.ru /* 13714Sigor@sysoev.ru * nxt_port_data_t size is allocation size 13814Sigor@sysoev.ru * which enables effective reuse of memory pool cache. 13911Sigor@sysoev.ru */ 14011Sigor@sysoev.ru typedef union { 14111Sigor@sysoev.ru nxt_buf_t buf; 14214Sigor@sysoev.ru nxt_port_msg_new_port_t new_port; 14314Sigor@sysoev.ru } nxt_port_data_t; 14411Sigor@sysoev.ru 14511Sigor@sysoev.ru 146*197Smax.romanov@nginx.com nxt_port_t *nxt_port_new(nxt_task_t *task, nxt_port_id_t id, nxt_pid_t pid, 147163Smax.romanov@nginx.com nxt_process_type_t type); 148163Smax.romanov@nginx.com nxt_bool_t nxt_port_release(nxt_port_t *port); 149163Smax.romanov@nginx.com 150141Smax.romanov@nginx.com nxt_port_id_t nxt_port_get_next_id(void); 151141Smax.romanov@nginx.com void nxt_port_reset_next_id(void); 152141Smax.romanov@nginx.com 15314Sigor@sysoev.ru nxt_int_t nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, 15414Sigor@sysoev.ru size_t max_size); 15514Sigor@sysoev.ru void nxt_port_destroy(nxt_port_t *port); 15614Sigor@sysoev.ru void nxt_port_write_enable(nxt_task_t *task, nxt_port_t *port); 15714Sigor@sysoev.ru void nxt_port_write_close(nxt_port_t *port); 15814Sigor@sysoev.ru void nxt_port_read_enable(nxt_task_t *task, nxt_port_t *port); 15914Sigor@sysoev.ru void nxt_port_read_close(nxt_port_t *port); 16014Sigor@sysoev.ru nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, 16142Smax.romanov@nginx.com nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port, 16242Smax.romanov@nginx.com nxt_buf_t *b); 16314Sigor@sysoev.ru 164141Smax.romanov@nginx.com void nxt_port_enable(nxt_task_t *task, nxt_port_t *port, 16514Sigor@sysoev.ru nxt_port_handler_t *handlers); 16620Sigor@sysoev.ru void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, 167141Smax.romanov@nginx.com nxt_port_t *port, uint32_t stream); 16881Smax.romanov@nginx.com nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port, 169141Smax.romanov@nginx.com nxt_port_t *new_port, uint32_t stream); 17020Sigor@sysoev.ru void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt, 17111Sigor@sysoev.ru nxt_uint_t slot, nxt_fd_t fd); 17211Sigor@sysoev.ru 17314Sigor@sysoev.ru void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17414Sigor@sysoev.ru void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 175141Smax.romanov@nginx.com void nxt_port_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17614Sigor@sysoev.ru void nxt_port_change_log_file_handler(nxt_task_t *task, 17711Sigor@sysoev.ru nxt_port_recv_msg_t *msg); 17842Smax.romanov@nginx.com void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17914Sigor@sysoev.ru void nxt_port_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 180125Smax.romanov@nginx.com void nxt_port_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 18114Sigor@sysoev.ru void nxt_port_empty_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 18211Sigor@sysoev.ru 18311Sigor@sysoev.ru 18411Sigor@sysoev.ru #endif /* _NXT_PORT_H_INCLUDED_ */ 185