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, 18*141Smax.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; 57*141Smax.romanov@nginx.com nxt_port_t *new_port; 5820Sigor@sysoev.ru }; 5914Sigor@sysoev.ru 60*141Smax.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 */ 66*141Smax.romanov@nginx.com nxt_process_t *process; 67*141Smax.romanov@nginx.com 68*141Smax.romanov@nginx.com nxt_queue_link_t app_link; /* for nxt_app_t.ports */ 69*141Smax.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; 79*141Smax.romanov@nginx.com nxt_port_handler_t *data; 8014Sigor@sysoev.ru 8165Sigor@sysoev.ru nxt_mp_t *mem_pool; 82*141Smax.romanov@nginx.com nxt_event_engine_t *engine; 83*141Smax.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 90*141Smax.romanov@nginx.com nxt_process_type_t type; 9114Sigor@sysoev.ru }; 9214Sigor@sysoev.ru 9314Sigor@sysoev.ru 9411Sigor@sysoev.ru typedef struct { 9542Smax.romanov@nginx.com nxt_port_id_t id; 9614Sigor@sysoev.ru nxt_pid_t pid; 9714Sigor@sysoev.ru size_t max_size; 9814Sigor@sysoev.ru size_t max_share; 9942Smax.romanov@nginx.com nxt_process_type_t type:8; 100124Smax.romanov@nginx.com } NXT_PACKED nxt_port_msg_new_port_t; 10111Sigor@sysoev.ru 10211Sigor@sysoev.ru 10311Sigor@sysoev.ru /* 10414Sigor@sysoev.ru * nxt_port_data_t size is allocation size 10514Sigor@sysoev.ru * which enables effective reuse of memory pool cache. 10611Sigor@sysoev.ru */ 10711Sigor@sysoev.ru typedef union { 10811Sigor@sysoev.ru nxt_buf_t buf; 10914Sigor@sysoev.ru nxt_port_msg_new_port_t new_port; 11014Sigor@sysoev.ru } nxt_port_data_t; 11111Sigor@sysoev.ru 11211Sigor@sysoev.ru 113*141Smax.romanov@nginx.com nxt_port_id_t nxt_port_get_next_id(void); 114*141Smax.romanov@nginx.com void nxt_port_reset_next_id(void); 115*141Smax.romanov@nginx.com 11614Sigor@sysoev.ru nxt_int_t nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, 11714Sigor@sysoev.ru size_t max_size); 11814Sigor@sysoev.ru void nxt_port_destroy(nxt_port_t *port); 11914Sigor@sysoev.ru void nxt_port_write_enable(nxt_task_t *task, nxt_port_t *port); 12014Sigor@sysoev.ru void nxt_port_write_close(nxt_port_t *port); 12114Sigor@sysoev.ru void nxt_port_read_enable(nxt_task_t *task, nxt_port_t *port); 12214Sigor@sysoev.ru void nxt_port_read_close(nxt_port_t *port); 12314Sigor@sysoev.ru nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, 12442Smax.romanov@nginx.com nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port, 12542Smax.romanov@nginx.com nxt_buf_t *b); 12614Sigor@sysoev.ru 127*141Smax.romanov@nginx.com void nxt_port_enable(nxt_task_t *task, nxt_port_t *port, 12814Sigor@sysoev.ru nxt_port_handler_t *handlers); 12920Sigor@sysoev.ru void nxt_port_write(nxt_task_t *task, nxt_runtime_t *rt, nxt_uint_t type, 13014Sigor@sysoev.ru nxt_fd_t fd, uint32_t stream, nxt_buf_t *b); 13120Sigor@sysoev.ru void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, 132*141Smax.romanov@nginx.com nxt_port_t *port, uint32_t stream); 13381Smax.romanov@nginx.com nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port, 134*141Smax.romanov@nginx.com nxt_port_t *new_port, uint32_t stream); 13520Sigor@sysoev.ru void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt, 13611Sigor@sysoev.ru nxt_uint_t slot, nxt_fd_t fd); 13711Sigor@sysoev.ru 13814Sigor@sysoev.ru void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 13914Sigor@sysoev.ru void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 140*141Smax.romanov@nginx.com void nxt_port_ready_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 14114Sigor@sysoev.ru void nxt_port_change_log_file_handler(nxt_task_t *task, 14211Sigor@sysoev.ru nxt_port_recv_msg_t *msg); 14342Smax.romanov@nginx.com void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 14414Sigor@sysoev.ru void nxt_port_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 145125Smax.romanov@nginx.com void nxt_port_remove_pid_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 14614Sigor@sysoev.ru void nxt_port_empty_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 14711Sigor@sysoev.ru 14811Sigor@sysoev.ru 14911Sigor@sysoev.ru #endif /* _NXT_PORT_H_INCLUDED_ */ 150