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; 77*167Smax.romanov@nginx.com uint32_t app_req_id; 7814Sigor@sysoev.ru 7914Sigor@sysoev.ru nxt_port_handler_t handler; 80141Smax.romanov@nginx.com nxt_port_handler_t *data; 8114Sigor@sysoev.ru 8265Sigor@sysoev.ru nxt_mp_t *mem_pool; 83141Smax.romanov@nginx.com nxt_event_engine_t *engine; 84141Smax.romanov@nginx.com 8514Sigor@sysoev.ru nxt_buf_t *free_bufs; 8614Sigor@sysoev.ru nxt_socket_t pair[2]; 8714Sigor@sysoev.ru 8842Smax.romanov@nginx.com nxt_port_id_t id; 8914Sigor@sysoev.ru nxt_pid_t pid; 9042Smax.romanov@nginx.com 91141Smax.romanov@nginx.com nxt_process_type_t type; 92163Smax.romanov@nginx.com nxt_work_t work; 9314Sigor@sysoev.ru }; 9414Sigor@sysoev.ru 9514Sigor@sysoev.ru 9611Sigor@sysoev.ru typedef struct { 9742Smax.romanov@nginx.com nxt_port_id_t id; 9814Sigor@sysoev.ru nxt_pid_t pid; 9914Sigor@sysoev.ru size_t max_size; 10014Sigor@sysoev.ru size_t max_share; 10142Smax.romanov@nginx.com nxt_process_type_t type:8; 102124Smax.romanov@nginx.com } NXT_PACKED nxt_port_msg_new_port_t; 10311Sigor@sysoev.ru 10411Sigor@sysoev.ru 10511Sigor@sysoev.ru /* 10614Sigor@sysoev.ru * nxt_port_data_t size is allocation size 10714Sigor@sysoev.ru * which enables effective reuse of memory pool cache. 10811Sigor@sysoev.ru */ 10911Sigor@sysoev.ru typedef union { 11011Sigor@sysoev.ru nxt_buf_t buf; 11114Sigor@sysoev.ru nxt_port_msg_new_port_t new_port; 11214Sigor@sysoev.ru } nxt_port_data_t; 11311Sigor@sysoev.ru 11411Sigor@sysoev.ru 115163Smax.romanov@nginx.com nxt_port_t *nxt_port_new(nxt_port_id_t id, nxt_pid_t pid, 116163Smax.romanov@nginx.com nxt_process_type_t type); 117163Smax.romanov@nginx.com nxt_bool_t nxt_port_release(nxt_port_t *port); 118163Smax.romanov@nginx.com 119141Smax.romanov@nginx.com nxt_port_id_t nxt_port_get_next_id(void); 120141Smax.romanov@nginx.com void nxt_port_reset_next_id(void); 121141Smax.romanov@nginx.com 12214Sigor@sysoev.ru nxt_int_t nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, 12314Sigor@sysoev.ru size_t max_size); 12414Sigor@sysoev.ru void nxt_port_destroy(nxt_port_t *port); 12514Sigor@sysoev.ru void nxt_port_write_enable(nxt_task_t *task, nxt_port_t *port); 12614Sigor@sysoev.ru void nxt_port_write_close(nxt_port_t *port); 12714Sigor@sysoev.ru void nxt_port_read_enable(nxt_task_t *task, nxt_port_t *port); 12814Sigor@sysoev.ru void nxt_port_read_close(nxt_port_t *port); 12914Sigor@sysoev.ru nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, 13042Smax.romanov@nginx.com nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port, 13142Smax.romanov@nginx.com nxt_buf_t *b); 13214Sigor@sysoev.ru 133141Smax.romanov@nginx.com void nxt_port_enable(nxt_task_t *task, nxt_port_t *port, 13414Sigor@sysoev.ru nxt_port_handler_t *handlers); 13520Sigor@sysoev.ru void nxt_port_write(nxt_task_t *task, nxt_runtime_t *rt, nxt_uint_t type, 13614Sigor@sysoev.ru nxt_fd_t fd, uint32_t stream, nxt_buf_t *b); 13720Sigor@sysoev.ru void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, 138141Smax.romanov@nginx.com nxt_port_t *port, uint32_t stream); 13981Smax.romanov@nginx.com nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port, 140141Smax.romanov@nginx.com nxt_port_t *new_port, uint32_t stream); 14120Sigor@sysoev.ru void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt, 14211Sigor@sysoev.ru nxt_uint_t slot, nxt_fd_t fd); 14311Sigor@sysoev.ru 14414Sigor@sysoev.ru void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 14514Sigor@sysoev.ru void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 146141Smax.romanov@nginx.com void nxt_port_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 14714Sigor@sysoev.ru void nxt_port_change_log_file_handler(nxt_task_t *task, 14811Sigor@sysoev.ru nxt_port_recv_msg_t *msg); 14942Smax.romanov@nginx.com void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 15014Sigor@sysoev.ru void nxt_port_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 151125Smax.romanov@nginx.com void nxt_port_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 15214Sigor@sysoev.ru void nxt_port_empty_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 15311Sigor@sysoev.ru 15411Sigor@sysoev.ru 15511Sigor@sysoev.ru #endif /* _NXT_PORT_H_INCLUDED_ */ 156