Extruded nxt_port_send_port() to send port to one process.

This commit is contained in:
Max Romanov
2017-06-23 19:20:08 +03:00
parent 0cd9521687
commit 3e989a165c
2 changed files with 40 additions and 30 deletions

View File

@@ -81,13 +81,10 @@ void
nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt,
nxt_port_t *new_port) nxt_port_t *new_port)
{ {
nxt_buf_t *b;
nxt_port_t *port;
nxt_process_t *process; nxt_process_t *process;
nxt_port_msg_new_port_t *msg;
nxt_debug(task, "new port %d for process %PI engine %uD", nxt_debug(task, "new port %d for process %PI engine %uD",
new_port->socket.fd, new_port->pid, new_port->engine); new_port->pair[1], new_port->pid, new_port->engine);
nxt_runtime_process_each(rt, process) nxt_runtime_process_each(rt, process)
{ {
@@ -95,18 +92,31 @@ nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt,
continue; continue;
} }
port = nxt_process_port_first(process); (void) nxt_port_send_port(task, nxt_process_port_first(process),
new_port);
b = nxt_buf_mem_alloc(port->mem_pool, sizeof(nxt_port_data_t), 0); }
nxt_runtime_process_loop;
if (nxt_slow_path(b == NULL)) {
continue;
} }
nxt_debug(task, "send new port %FD to process %PI",
new_port->socket.fd, process->pid);
b->data = port->mem_pool; nxt_int_t
nxt_port_send_port(nxt_task_t *task, nxt_port_t *port, nxt_port_t *new_port)
{
nxt_mp_t *mp;
nxt_buf_t *b;
nxt_port_msg_new_port_t *msg;
mp = port->mem_pool;
b = nxt_buf_mem_alloc(mp, sizeof(nxt_port_data_t), 0);
if (nxt_slow_path(b == NULL)) {
return NXT_ERROR;
}
nxt_debug(task, "send port %FD to process %PI",
new_port->pair[1], port->pid);
b->data = mp;
b->completion_handler = nxt_port_new_port_buf_completion; b->completion_handler = nxt_port_new_port_buf_completion;
b->mem.free += sizeof(nxt_port_msg_new_port_t); b->mem.free += sizeof(nxt_port_msg_new_port_t);
msg = (nxt_port_msg_new_port_t *) b->mem.pos; msg = (nxt_port_msg_new_port_t *) b->mem.pos;
@@ -118,10 +128,8 @@ nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt,
msg->max_share = port->max_share; msg->max_share = port->max_share;
msg->type = new_port->type; msg->type = new_port->type;
(void) nxt_port_socket_write(task, port, NXT_PORT_MSG_NEW_PORT, return nxt_port_socket_write(task, port, NXT_PORT_MSG_NEW_PORT,
new_port->socket.fd, 0, 0, b); new_port->pair[1], 0, 0, b);
}
nxt_runtime_process_loop;
} }

View File

@@ -116,6 +116,8 @@ void nxt_port_write(nxt_task_t *task, nxt_runtime_t *rt, nxt_uint_t type,
nxt_fd_t fd, uint32_t stream, nxt_buf_t *b); nxt_fd_t fd, uint32_t stream, nxt_buf_t *b);
void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, void nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt,
nxt_port_t *port); nxt_port_t *port);
nxt_int_t nxt_port_send_port(nxt_task_t *task, nxt_port_t *port,
nxt_port_t *new_port);
void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt, void nxt_port_change_log_file(nxt_task_t *task, nxt_runtime_t *rt,
nxt_uint_t slot, nxt_fd_t fd); nxt_uint_t slot, nxt_fd_t fd);