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, 1742Smax.romanov@nginx.com } nxt_port_msg_type_t; 1842Smax.romanov@nginx.com 1942Smax.romanov@nginx.com #define NXT_PORT_MSG_MAX NXT_PORT_MSG_DATA 2042Smax.romanov@nginx.com 2114Sigor@sysoev.ru 2242Smax.romanov@nginx.com /* Passed as a first iov chunk. */ 2342Smax.romanov@nginx.com typedef struct { 2442Smax.romanov@nginx.com uint32_t stream; 2542Smax.romanov@nginx.com nxt_pid_t pid; 2642Smax.romanov@nginx.com nxt_port_id_t reply_port; 2742Smax.romanov@nginx.com 2842Smax.romanov@nginx.com nxt_port_msg_type_t type:8; 2942Smax.romanov@nginx.com uint8_t last; /* 1 bit */ 3042Smax.romanov@nginx.com 3142Smax.romanov@nginx.com /* Message data send using mmap, next chunk is a nxt_port_mmap_msg_t. */ 3242Smax.romanov@nginx.com uint8_t mmap; /* 1 bit */ 3314Sigor@sysoev.ru } nxt_port_msg_t; 3414Sigor@sysoev.ru 3514Sigor@sysoev.ru 3614Sigor@sysoev.ru typedef struct { 3714Sigor@sysoev.ru nxt_queue_link_t link; 3814Sigor@sysoev.ru nxt_buf_t *buf; 3914Sigor@sysoev.ru size_t share; 4014Sigor@sysoev.ru nxt_fd_t fd; 4114Sigor@sysoev.ru nxt_port_msg_t port_msg; 4214Sigor@sysoev.ru } nxt_port_send_msg_t; 4314Sigor@sysoev.ru 4414Sigor@sysoev.ru 4520Sigor@sysoev.ru struct nxt_port_recv_msg_s { 4614Sigor@sysoev.ru nxt_fd_t fd; 4714Sigor@sysoev.ru nxt_buf_t *buf; 4814Sigor@sysoev.ru nxt_port_t *port; 4942Smax.romanov@nginx.com nxt_port_msg_t port_msg; 50*82Smax.romanov@nginx.com size_t size; 5120Sigor@sysoev.ru }; 5214Sigor@sysoev.ru 5314Sigor@sysoev.ru 5414Sigor@sysoev.ru struct nxt_port_s { 5514Sigor@sysoev.ru /* Must be the first field. */ 5614Sigor@sysoev.ru nxt_fd_event_t socket; 5714Sigor@sysoev.ru 5842Smax.romanov@nginx.com nxt_queue_link_t link; 5942Smax.romanov@nginx.com 6014Sigor@sysoev.ru nxt_queue_t messages; /* of nxt_port_send_msg_t */ 6114Sigor@sysoev.ru 6214Sigor@sysoev.ru /* Maximum size of message part. */ 6314Sigor@sysoev.ru uint32_t max_size; 6414Sigor@sysoev.ru /* Maximum interleave of message parts. */ 6514Sigor@sysoev.ru uint32_t max_share; 6614Sigor@sysoev.ru 6714Sigor@sysoev.ru nxt_port_handler_t handler; 6814Sigor@sysoev.ru void *data; 6914Sigor@sysoev.ru 7065Sigor@sysoev.ru nxt_mp_t *mem_pool; 7114Sigor@sysoev.ru nxt_buf_t *free_bufs; 7214Sigor@sysoev.ru nxt_socket_t pair[2]; 7314Sigor@sysoev.ru 7442Smax.romanov@nginx.com nxt_port_id_t id; 7514Sigor@sysoev.ru nxt_pid_t pid; 7614Sigor@sysoev.ru uint32_t engine; 7742Smax.romanov@nginx.com 7842Smax.romanov@nginx.com nxt_process_type_t type:8; 7942Smax.romanov@nginx.com nxt_process_t *process; 8014Sigor@sysoev.ru }; 8114Sigor@sysoev.ru 8214Sigor@sysoev.ru 8311Sigor@sysoev.ru typedef struct { 8442Smax.romanov@nginx.com nxt_port_id_t id; 8514Sigor@sysoev.ru nxt_pid_t pid; 8614Sigor@sysoev.ru uint32_t engine; 8714Sigor@sysoev.ru size_t max_size; 8814Sigor@sysoev.ru size_t max_share; 8942Smax.romanov@nginx.com nxt_process_type_t type:8; 9014Sigor@sysoev.ru } nxt_port_msg_new_port_t; 9111Sigor@sysoev.ru 9211Sigor@sysoev.ru 9311Sigor@sysoev.ru /* 9414Sigor@sysoev.ru * nxt_port_data_t size is allocation size 9514Sigor@sysoev.ru * which enables effective reuse of memory pool cache. 9611Sigor@sysoev.ru */ 9711Sigor@sysoev.ru typedef union { 9811Sigor@sysoev.ru nxt_buf_t buf; 9914Sigor@sysoev.ru nxt_port_msg_new_port_t new_port; 10014Sigor@sysoev.ru } nxt_port_data_t; 10111Sigor@sysoev.ru 10211Sigor@sysoev.ru 10314Sigor@sysoev.ru nxt_int_t nxt_port_socket_init(nxt_task_t *task, nxt_port_t *port, 10414Sigor@sysoev.ru size_t max_size); 10514Sigor@sysoev.ru void nxt_port_destroy(nxt_port_t *port); 10614Sigor@sysoev.ru void nxt_port_write_enable(nxt_task_t *task, nxt_port_t *port); 10714Sigor@sysoev.ru void nxt_port_write_close(nxt_port_t *port); 10814Sigor@sysoev.ru void nxt_port_read_enable(nxt_task_t *task, nxt_port_t *port); 10914Sigor@sysoev.ru void nxt_port_read_close(nxt_port_t *port); 11014Sigor@sysoev.ru nxt_int_t nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, 11142Smax.romanov@nginx.com nxt_uint_t type, nxt_fd_t fd, uint32_t stream, nxt_port_id_t reply_port, 11242Smax.romanov@nginx.com nxt_buf_t *b); 11314Sigor@sysoev.ru 11477Smax.romanov@nginx.com void nxt_port_create(nxt_task_t *task, nxt_port_t *port, 11514Sigor@sysoev.ru nxt_port_handler_t *handlers); 11620Sigor@sysoev.ru void nxt_port_write(nxt_task_t *task, nxt_runtime_t *rt, nxt_uint_t type, 11714Sigor@sysoev.ru nxt_fd_t fd, uint32_t stream, nxt_buf_t *b); 11820Sigor@sysoev.ru void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, 11914Sigor@sysoev.ru nxt_port_t *port); 12081Smax.romanov@nginx.com nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port, 12181Smax.romanov@nginx.com nxt_port_t *new_port); 12220Sigor@sysoev.ru void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt, 12311Sigor@sysoev.ru nxt_uint_t slot, nxt_fd_t fd); 12411Sigor@sysoev.ru 12514Sigor@sysoev.ru void nxt_port_quit_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 12614Sigor@sysoev.ru void nxt_port_new_port_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 12714Sigor@sysoev.ru void nxt_port_change_log_file_handler(nxt_task_t *task, 12811Sigor@sysoev.ru nxt_port_recv_msg_t *msg); 12942Smax.romanov@nginx.com void nxt_port_mmap_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 13014Sigor@sysoev.ru void nxt_port_data_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 13114Sigor@sysoev.ru void nxt_port_empty_handler(nxt_task_t *task, nxt_port_recv_msg_t *msg); 13211Sigor@sysoev.ru 13311Sigor@sysoev.ru 13411Sigor@sysoev.ru #endif /* _NXT_PORT_H_INCLUDED_ */ 135