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 { 1242Smax.romanov@nginx.com NXT_PORT_MSG_QUIT = 0, 1342Smax.romanov@nginx.com NXT_PORT_MSG_NEW_PORT, 1442Smax.romanov@nginx.com NXT_PORT_MSG_CHANGE_FILE, 1542Smax.romanov@nginx.com NXT_PORT_MSG_MMAP, 1642Smax.romanov@nginx.com NXT_PORT_MSG_DATA, 17125Smax.romanov@nginx.com NXT_PORT_MSG_REMOVE_PID, 18141Smax.romanov@nginx.com NXT_PORT_MSG_READY, 1942Smax.romanov@nginx.com 20125Smax.romanov@nginx.com NXT_PORT_MSG_MAX, 21125Smax.romanov@nginx.com } nxt_port_msg_type_t; 2242Smax.romanov@nginx.com 2314Sigor@sysoev.ru 2442Smax.romanov@nginx.com /* Passed as a first iov chunk. */ 2542Smax.romanov@nginx.com typedef struct { 2642Smax.romanov@nginx.com uint32_t stream; 2742Smax.romanov@nginx.com nxt_pid_t pid; 2842Smax.romanov@nginx.com nxt_port_id_t reply_port; 2942Smax.romanov@nginx.com 3042Smax.romanov@nginx.com nxt_port_msg_type_t type:8; 3142Smax.romanov@nginx.com uint8_t last; /* 1 bit */ 3242Smax.romanov@nginx.com 3342Smax.romanov@nginx.com /* Message data send using mmap, next chunk is a nxt_port_mmap_msg_t. */ 3442Smax.romanov@nginx.com uint8_t mmap; /* 1 bit */ 35124Smax.romanov@nginx.com } NXT_PACKED nxt_port_msg_t; 3614Sigor@sysoev.ru 3714Sigor@sysoev.ru 3814Sigor@sysoev.ru typedef struct { 3914Sigor@sysoev.ru nxt_queue_link_t link; 4014Sigor@sysoev.ru nxt_buf_t *buf; 4114Sigor@sysoev.ru size_t share; 4214Sigor@sysoev.ru nxt_fd_t fd; 4314Sigor@sysoev.ru nxt_port_msg_t port_msg; 44122Smax.romanov@nginx.com 45122Smax.romanov@nginx.com nxt_work_t work; 46122Smax.romanov@nginx.com nxt_event_engine_t *engine; 47122Smax.romanov@nginx.com nxt_mp_t *mem_pool; 4814Sigor@sysoev.ru } nxt_port_send_msg_t; 4914Sigor@sysoev.ru 5014Sigor@sysoev.ru 5120Sigor@sysoev.ru struct nxt_port_recv_msg_s { 5214Sigor@sysoev.ru nxt_fd_t fd; 5314Sigor@sysoev.ru nxt_buf_t *buf; 5414Sigor@sysoev.ru nxt_port_t *port; 5542Smax.romanov@nginx.com nxt_port_msg_t port_msg; 5682Smax.romanov@nginx.com size_t size; 57141Smax.romanov@nginx.com nxt_port_t *new_port; 5820Sigor@sysoev.ru }; 5914Sigor@sysoev.ru 60141Smax.romanov@nginx.com typedef struct nxt_app_s nxt_app_t; 6114Sigor@sysoev.ru 6214Sigor@sysoev.ru struct nxt_port_s { 6314Sigor@sysoev.ru nxt_fd_event_t socket; 6414Sigor@sysoev.ru 65125Smax.romanov@nginx.com nxt_queue_link_t link; /* for nxt_process_t.ports */ 66141Smax.romanov@nginx.com nxt_process_t *process; 67141Smax.romanov@nginx.com 68141Smax.romanov@nginx.com nxt_queue_link_t app_link; /* for nxt_app_t.ports */ 69141Smax.romanov@nginx.com nxt_app_t *app; 7042Smax.romanov@nginx.com 7114Sigor@sysoev.ru nxt_queue_t messages; /* of nxt_port_send_msg_t */ 7214Sigor@sysoev.ru 7314Sigor@sysoev.ru /* Maximum size of message part. */ 7414Sigor@sysoev.ru uint32_t max_size; 7514Sigor@sysoev.ru /* Maximum interleave of message parts. */ 7614Sigor@sysoev.ru uint32_t max_share; 7714Sigor@sysoev.ru 7814Sigor@sysoev.ru nxt_port_handler_t handler; 79141Smax.romanov@nginx.com nxt_port_handler_t *data; 8014Sigor@sysoev.ru 8165Sigor@sysoev.ru nxt_mp_t *mem_pool; 82141Smax.romanov@nginx.com nxt_event_engine_t *engine; 83141Smax.romanov@nginx.com 8414Sigor@sysoev.ru nxt_buf_t *free_bufs; 8514Sigor@sysoev.ru nxt_socket_t pair[2]; 8614Sigor@sysoev.ru 8742Smax.romanov@nginx.com nxt_port_id_t id; 8814Sigor@sysoev.ru nxt_pid_t pid; 8942Smax.romanov@nginx.com 90141Smax.romanov@nginx.com nxt_process_type_t type; 91*163Smax.romanov@nginx.com nxt_work_t work; 9214Sigor@sysoev.ru }; 9314Sigor@sysoev.ru 9414Sigor@sysoev.ru 9511Sigor@sysoev.ru typedef struct { 9642Smax.romanov@nginx.com nxt_port_id_t id; 9714Sigor@sysoev.ru nxt_pid_t pid; 9814Sigor@sysoev.ru size_t max_size; 9914Sigor@sysoev.ru size_t max_share; 10042Smax.romanov@nginx.com nxt_process_type_t type:8; 101124Smax.romanov@nginx.com } NXT_PACKED nxt_port_msg_new_port_t; 10211Sigor@sysoev.ru 10311Sigor@sysoev.ru 10411Sigor@sysoev.ru /* 10514Sigor@sysoev.ru * nxt_port_data_t size is allocation size 10614Sigor@sysoev.ru * which enables effective reuse of memory pool cache. 10711Sigor@sysoev.ru */ 10811Sigor@sysoev.ru typedef union { 10911Sigor@sysoev.ru nxt_buf_t buf; 11014Sigor@sysoev.ru nxt_port_msg_new_port_t new_port; 11114Sigor@sysoev.ru } nxt_port_data_t; 11211Sigor@sysoev.ru 11311Sigor@sysoev.ru 114*163Smax.romanov@nginx.com nxt_port_t *nxt_port_new(nxt_port_id_t id, nxt_pid_t pid, 115*163Smax.romanov@nginx.com nxt_process_type_t type); 116*163Smax.romanov@nginx.com nxt_bool_t nxt_port_release(nxt_port_t *port); 117*163Smax.romanov@nginx.com 118141Smax.romanov@nginx.com nxt_port_id_t nxt_port_get_next_id(void); 119141Smax.romanov@nginx.com void nxt_port_reset_next_id(void); 120141Smax.romanov@nginx.com 12114Sigor@sysoev.ru nxt_int_t nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, 12214Sigor@sysoev.ru size_t max_size); 12314Sigor@sysoev.ru void nxt_port_destroy(nxt_port_t *port); 12414Sigor@sysoev.ru void nxt_port_write_enable(nxt_task_t *task, nxt_port_t *port); 12514Sigor@sysoev.ru void nxt_port_write_close(nxt_port_t *port); 12614Sigor@sysoev.ru void nxt_port_read_enable(nxt_task_t *task, nxt_port_t *port); 12714Sigor@sysoev.ru void nxt_port_read_close(nxt_port_t *port); 12814Sigor@sysoev.ru nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, 12942Smax.romanov@nginx.com nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port, 13042Smax.romanov@nginx.com nxt_buf_t *b); 13114Sigor@sysoev.ru 132141Smax.romanov@nginx.com void nxt_port_enable(nxt_task_t *task, nxt_port_t *port, 13314Sigor@sysoev.ru nxt_port_handler_t *handlers); 13420Sigor@sysoev.ru void nxt_port_write(nxt_task_t *task, nxt_runtime_t *rt, nxt_uint_t type, 13514Sigor@sysoev.ru nxt_fd_t fd, uint32_t stream, nxt_buf_t *b); 13620Sigor@sysoev.ru void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, 137141Smax.romanov@nginx.com nxt_port_t *port, uint32_t stream); 13881Smax.romanov@nginx.com nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port, 139141Smax.romanov@nginx.com nxt_port_t *new_port, uint32_t stream); 14020Sigor@sysoev.ru void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt, 14111Sigor@sysoev.ru nxt_uint_t slot, nxt_fd_t fd); 14211Sigor@sysoev.ru 14314Sigor@sysoev.ru void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 14414Sigor@sysoev.ru void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 145141Smax.romanov@nginx.com void nxt_port_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 14614Sigor@sysoev.ru void nxt_port_change_log_file_handler(nxt_task_t *task, 14711Sigor@sysoev.ru nxt_port_recv_msg_t *msg); 14842Smax.romanov@nginx.com void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 14914Sigor@sysoev.ru void nxt_port_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 150125Smax.romanov@nginx.com void nxt_port_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 15114Sigor@sysoev.ru void nxt_port_empty_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 15211Sigor@sysoev.ru 15311Sigor@sysoev.ru 15411Sigor@sysoev.ru #endif /* _NXT_PORT_H_INCLUDED_ */ 155