Deduplicating code for closing fds in nxt_port_send_msg_t.

This commit is contained in:
Max Romanov
2021-07-01 16:23:56 +03:00
parent 2ac9c627aa
commit 54bf3e1912

View File

@@ -21,6 +21,7 @@ static nxt_int_t nxt_port_msg_chk_insert(nxt_task_t *task, nxt_port_t *port,
static nxt_port_send_msg_t *nxt_port_msg_alloc(nxt_port_send_msg_t *m);
static void nxt_port_write_handler(nxt_task_t *task, void *obj, void *data);
static nxt_port_send_msg_t *nxt_port_msg_first(nxt_port_t *port);
nxt_inline void nxt_port_msg_close_fd(nxt_port_send_msg_t *msg);
static nxt_buf_t *nxt_port_buf_completion(nxt_task_t *task,
nxt_work_queue_t *wq, nxt_buf_t *b, size_t sent, nxt_bool_t mmap_mode);
static nxt_port_send_msg_t *nxt_port_msg_insert_tail(nxt_port_t *port,
@@ -449,19 +450,7 @@ next_fragment:
goto fail;
}
if (msg->close_fd) {
if (msg->fd[0] != -1) {
nxt_fd_close(msg->fd[0]);
msg->fd[0] = -1;
}
if (msg->fd[1] != -1) {
nxt_fd_close(msg->fd[1]);
msg->fd[1] = -1;
}
}
nxt_port_msg_close_fd(msg);
msg->buf = nxt_port_buf_completion(task, wq, msg->buf, plain_size,
m == NXT_PORT_METHOD_MMAP);
@@ -525,19 +514,7 @@ next_fragment:
} else {
if (nxt_slow_path(n == NXT_ERROR)) {
if (msg->link.next == NULL) {
if (msg->close_fd) {
if (msg->fd[0] != -1) {
nxt_fd_close(msg->fd[0]);
msg->fd[0] = -1;
}
if (msg->fd[1] != -1) {
nxt_fd_close(msg->fd[1]);
msg->fd[1] = -1;
}
}
nxt_port_msg_close_fd(msg);
nxt_port_release_send_msg(msg);
}
@@ -609,6 +586,27 @@ nxt_port_msg_first(nxt_port_t *port)
}
nxt_inline void
nxt_port_msg_close_fd(nxt_port_send_msg_t *msg)
{
if (!msg->close_fd) {
return;
}
if (msg->fd[0] != -1) {
nxt_fd_close(msg->fd[0]);
msg->fd[0] = -1;
}
if (msg->fd[1] != -1) {
nxt_fd_close(msg->fd[1]);
msg->fd[1] = -1;
}
}
static nxt_buf_t *
nxt_port_buf_completion(nxt_task_t *task, nxt_work_queue_t *wq, nxt_buf_t *b,
size_t sent, nxt_bool_t mmap_mode)
@@ -1333,19 +1331,7 @@ nxt_port_error_handler(nxt_task_t *task, void *obj, void *data)
nxt_queue_each(msg, &port->messages, nxt_port_send_msg_t, link) {
if (msg->close_fd) {
if (msg->fd[0] != -1) {
nxt_fd_close(msg->fd[0]);
msg->fd[0] = -1;
}
if (msg->fd[1] != -1) {
nxt_fd_close(msg->fd[1]);
msg->fd[1] = -1;
}
}
nxt_port_msg_close_fd(msg);
for (b = msg->buf; b != NULL; b = next) {
next = b->next;