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, 24*190Smax.romanov@nginx.com _NXT_PORT_MSG_RPC_READY, 25*190Smax.romanov@nginx.com _NXT_PORT_MSG_RPC_ERROR, 2642Smax.romanov@nginx.com 27125Smax.romanov@nginx.com NXT_PORT_MSG_MAX, 28189Smax.romanov@nginx.com 29189Smax.romanov@nginx.com NXT_PORT_MSG_QUIT = _NXT_PORT_MSG_QUIT | NXT_PORT_MSG_LAST, 30189Smax.romanov@nginx.com NXT_PORT_MSG_NEW_PORT = _NXT_PORT_MSG_NEW_PORT | NXT_PORT_MSG_LAST, 31189Smax.romanov@nginx.com NXT_PORT_MSG_CHANGE_FILE = _NXT_PORT_MSG_CHANGE_FILE | NXT_PORT_MSG_LAST, 32189Smax.romanov@nginx.com NXT_PORT_MSG_MMAP = _NXT_PORT_MSG_MMAP | NXT_PORT_MSG_LAST | 33189Smax.romanov@nginx.com NXT_PORT_MSG_CLOSE_FD, 34189Smax.romanov@nginx.com NXT_PORT_MSG_DATA = _NXT_PORT_MSG_DATA, 35189Smax.romanov@nginx.com NXT_PORT_MSG_DATA_LAST = _NXT_PORT_MSG_DATA | NXT_PORT_MSG_LAST, 36189Smax.romanov@nginx.com NXT_PORT_MSG_REMOVE_PID = _NXT_PORT_MSG_REMOVE_PID | NXT_PORT_MSG_LAST, 37189Smax.romanov@nginx.com NXT_PORT_MSG_READY = _NXT_PORT_MSG_READY | NXT_PORT_MSG_LAST, 38*190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_READY = _NXT_PORT_MSG_RPC_READY, 39*190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_READY_LAST = _NXT_PORT_MSG_RPC_READY | NXT_PORT_MSG_LAST, 40*190Smax.romanov@nginx.com NXT_PORT_MSG_RPC_ERROR = _NXT_PORT_MSG_RPC_ERROR | NXT_PORT_MSG_LAST, 41125Smax.romanov@nginx.com } nxt_port_msg_type_t; 4242Smax.romanov@nginx.com 4314Sigor@sysoev.ru 4442Smax.romanov@nginx.com /* Passed as a first iov chunk. */ 4542Smax.romanov@nginx.com typedef struct { 4642Smax.romanov@nginx.com uint32_t stream; 4742Smax.romanov@nginx.com nxt_pid_t pid; 4842Smax.romanov@nginx.com nxt_port_id_t reply_port; 4942Smax.romanov@nginx.com 50189Smax.romanov@nginx.com uint8_t type; 5142Smax.romanov@nginx.com uint8_t last; /* 1 bit */ 5242Smax.romanov@nginx.com 5342Smax.romanov@nginx.com /* Message data send using mmap, next chunk is a nxt_port_mmap_msg_t. */ 5442Smax.romanov@nginx.com uint8_t mmap; /* 1 bit */ 55168Svbart@nginx.com } nxt_port_msg_t; 5614Sigor@sysoev.ru 5714Sigor@sysoev.ru 5814Sigor@sysoev.ru typedef struct { 5914Sigor@sysoev.ru nxt_queue_link_t link; 6014Sigor@sysoev.ru nxt_buf_t *buf; 6114Sigor@sysoev.ru size_t share; 6214Sigor@sysoev.ru nxt_fd_t fd; 63189Smax.romanov@nginx.com nxt_bool_t close_fd; 6414Sigor@sysoev.ru nxt_port_msg_t port_msg; 65122Smax.romanov@nginx.com 66122Smax.romanov@nginx.com nxt_work_t work; 67122Smax.romanov@nginx.com nxt_event_engine_t *engine; 68122Smax.romanov@nginx.com nxt_mp_t *mem_pool; 6914Sigor@sysoev.ru } nxt_port_send_msg_t; 7014Sigor@sysoev.ru 7114Sigor@sysoev.ru 7220Sigor@sysoev.ru struct nxt_port_recv_msg_s { 7314Sigor@sysoev.ru nxt_fd_t fd; 7414Sigor@sysoev.ru nxt_buf_t *buf; 7514Sigor@sysoev.ru nxt_port_t *port; 7642Smax.romanov@nginx.com nxt_port_msg_t port_msg; 7782Smax.romanov@nginx.com size_t size; 78141Smax.romanov@nginx.com nxt_port_t *new_port; 7920Sigor@sysoev.ru }; 8014Sigor@sysoev.ru 81141Smax.romanov@nginx.com typedef struct nxt_app_s nxt_app_t; 8214Sigor@sysoev.ru 8314Sigor@sysoev.ru struct nxt_port_s { 8414Sigor@sysoev.ru nxt_fd_event_t socket; 8514Sigor@sysoev.ru 86125Smax.romanov@nginx.com nxt_queue_link_t link; /* for nxt_process_t.ports */ 87141Smax.romanov@nginx.com nxt_process_t *process; 88141Smax.romanov@nginx.com 89141Smax.romanov@nginx.com nxt_queue_link_t app_link; /* for nxt_app_t.ports */ 90141Smax.romanov@nginx.com nxt_app_t *app; 9142Smax.romanov@nginx.com 9214Sigor@sysoev.ru nxt_queue_t messages; /* of nxt_port_send_msg_t */ 9314Sigor@sysoev.ru 9414Sigor@sysoev.ru /* Maximum size of message part. */ 9514Sigor@sysoev.ru uint32_t max_size; 9614Sigor@sysoev.ru /* Maximum interleave of message parts. */ 9714Sigor@sysoev.ru uint32_t max_share; 98167Smax.romanov@nginx.com uint32_t app_req_id; 9914Sigor@sysoev.ru 10014Sigor@sysoev.ru nxt_port_handler_t handler; 101141Smax.romanov@nginx.com nxt_port_handler_t *data; 10214Sigor@sysoev.ru 10365Sigor@sysoev.ru nxt_mp_t *mem_pool; 104141Smax.romanov@nginx.com nxt_event_engine_t *engine; 105141Smax.romanov@nginx.com 10614Sigor@sysoev.ru nxt_buf_t *free_bufs; 10714Sigor@sysoev.ru nxt_socket_t pair[2]; 10814Sigor@sysoev.ru 10942Smax.romanov@nginx.com nxt_port_id_t id; 11014Sigor@sysoev.ru nxt_pid_t pid; 11142Smax.romanov@nginx.com 112*190Smax.romanov@nginx.com nxt_lvlhsh_t rpc_streams; /* stream to nxt_port_rpc_reg_t */ 113*190Smax.romanov@nginx.com nxt_lvlhsh_t rpc_peers; /* peer to queue of nxt_port_rpc_reg_t */ 114*190Smax.romanov@nginx.com uint32_t next_stream; 115*190Smax.romanov@nginx.com 116141Smax.romanov@nginx.com nxt_process_type_t type; 117163Smax.romanov@nginx.com nxt_work_t work; 11814Sigor@sysoev.ru }; 11914Sigor@sysoev.ru 12014Sigor@sysoev.ru 12111Sigor@sysoev.ru typedef struct { 12242Smax.romanov@nginx.com nxt_port_id_t id; 12314Sigor@sysoev.ru nxt_pid_t pid; 12414Sigor@sysoev.ru size_t max_size; 12514Sigor@sysoev.ru size_t max_share; 12642Smax.romanov@nginx.com nxt_process_type_t type:8; 127168Svbart@nginx.com } nxt_port_msg_new_port_t; 12811Sigor@sysoev.ru 12911Sigor@sysoev.ru 13011Sigor@sysoev.ru /* 13114Sigor@sysoev.ru * nxt_port_data_t size is allocation size 13214Sigor@sysoev.ru * which enables effective reuse of memory pool cache. 13311Sigor@sysoev.ru */ 13411Sigor@sysoev.ru typedef union { 13511Sigor@sysoev.ru nxt_buf_t buf; 13614Sigor@sysoev.ru nxt_port_msg_new_port_t new_port; 13714Sigor@sysoev.ru } nxt_port_data_t; 13811Sigor@sysoev.ru 13911Sigor@sysoev.ru 140163Smax.romanov@nginx.com nxt_port_t *nxt_port_new(nxt_port_id_t id, nxt_pid_t pid, 141163Smax.romanov@nginx.com nxt_process_type_t type); 142163Smax.romanov@nginx.com nxt_bool_t nxt_port_release(nxt_port_t *port); 143163Smax.romanov@nginx.com 144141Smax.romanov@nginx.com nxt_port_id_t nxt_port_get_next_id(void); 145141Smax.romanov@nginx.com void nxt_port_reset_next_id(void); 146141Smax.romanov@nginx.com 14714Sigor@sysoev.ru nxt_int_t nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, 14814Sigor@sysoev.ru size_t max_size); 14914Sigor@sysoev.ru void nxt_port_destroy(nxt_port_t *port); 15014Sigor@sysoev.ru void nxt_port_write_enable(nxt_task_t *task, nxt_port_t *port); 15114Sigor@sysoev.ru void nxt_port_write_close(nxt_port_t *port); 15214Sigor@sysoev.ru void nxt_port_read_enable(nxt_task_t *task, nxt_port_t *port); 15314Sigor@sysoev.ru void nxt_port_read_close(nxt_port_t *port); 15414Sigor@sysoev.ru nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, 15542Smax.romanov@nginx.com nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port, 15642Smax.romanov@nginx.com nxt_buf_t *b); 15714Sigor@sysoev.ru 158141Smax.romanov@nginx.com void nxt_port_enable(nxt_task_t *task, nxt_port_t *port, 15914Sigor@sysoev.ru nxt_port_handler_t *handlers); 16020Sigor@sysoev.ru void nxt_port_write(nxt_task_t *task, nxt_runtime_t *rt, nxt_uint_t type, 16114Sigor@sysoev.ru nxt_fd_t fd, uint32_t stream, nxt_buf_t *b); 16220Sigor@sysoev.ru void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, 163141Smax.romanov@nginx.com nxt_port_t *port, uint32_t stream); 16481Smax.romanov@nginx.com nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port, 165141Smax.romanov@nginx.com nxt_port_t *new_port, uint32_t stream); 16620Sigor@sysoev.ru void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt, 16711Sigor@sysoev.ru nxt_uint_t slot, nxt_fd_t fd); 16811Sigor@sysoev.ru 16914Sigor@sysoev.ru void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17014Sigor@sysoev.ru void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 171141Smax.romanov@nginx.com void nxt_port_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17214Sigor@sysoev.ru void nxt_port_change_log_file_handler(nxt_task_t *task, 17311Sigor@sysoev.ru nxt_port_recv_msg_t *msg); 17442Smax.romanov@nginx.com void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17514Sigor@sysoev.ru void nxt_port_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 176125Smax.romanov@nginx.com void nxt_port_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17714Sigor@sysoev.ru void nxt_port_empty_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 17811Sigor@sysoev.ru 17911Sigor@sysoev.ru 18011Sigor@sysoev.ru #endif /* _NXT_PORT_H_INCLUDED_ */ 181