summaryrefslogtreecommitdiffhomepage
path: root/src/nxt_port_socket.c
diff options
context:
space:
mode:
authorAndrei Belov <defan@nginx.com>2021-08-19 18:17:12 +0300
committerAndrei Belov <defan@nginx.com>2021-08-19 18:17:12 +0300
commitdb442f1be7e713e6a219621ff97a51046590dbd6 (patch)
tree913734275bc890ec175e51fcb0f36b01a3c52c24 /src/nxt_port_socket.c
parenta1d2ced6fc2317d36bc917c5d0ac339bc647dc34 (diff)
parent13c0025dfa6e041563d0ad5dd81679b44522694c (diff)
downloadunit-1.25.0-1.tar.gz
unit-1.25.0-1.tar.bz2
Merged with the default branch.1.25.0-1
Diffstat (limited to '')
-rw-r--r--src/nxt_port_socket.c56
1 files changed, 30 insertions, 26 deletions
diff --git a/src/nxt_port_socket.c b/src/nxt_port_socket.c
index 3cf2e79a..ba1b7081 100644
--- a/src/nxt_port_socket.c
+++ b/src/nxt_port_socket.c
@@ -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);
@@ -524,6 +513,12 @@ next_fragment:
} else {
if (nxt_slow_path(n == NXT_ERROR)) {
+ if (msg->link.next == NULL) {
+ nxt_port_msg_close_fd(msg);
+
+ nxt_port_release_send_msg(msg);
+ }
+
goto fail;
}
@@ -591,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)
@@ -1315,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;