diff options
author | Max Romanov <max.romanov@nginx.com> | 2017-08-02 13:10:48 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2017-08-02 13:10:48 +0300 |
commit | 3812ffd336414904affc43d29229b04a2d6d8ae6 (patch) | |
tree | f12fca86a5e4280bd75234776cac80c9b9902d0b /src/nxt_port_socket.c | |
parent | a7ef8481fcda2f2dc5b0b84a93e66bce62c83918 (diff) | |
download | unit-3812ffd336414904affc43d29229b04a2d6d8ae6.tar.gz unit-3812ffd336414904affc43d29229b04a2d6d8ae6.tar.bz2 |
Added bit flags to type parameter of nxt_port_socket_write().
NXT_PORT_MSG_LAST - mark message as last;
NXT_PORT_MSG_CLOSE_FD - close fd right after send;
Type constants altered to include last flag for single buffer messages.
Last sign is critical for coming port RPC layer. Handlers unregistered on last
message. Create sync buffer is not convenient, extra parameter is better.
Diffstat (limited to 'src/nxt_port_socket.c')
-rw-r--r-- | src/nxt_port_socket.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/nxt_port_socket.c b/src/nxt_port_socket.c index 31572e54..bdb37483 100644 --- a/src/nxt_port_socket.c +++ b/src/nxt_port_socket.c @@ -166,12 +166,17 @@ nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, nxt_uint_t type, if (msg->port_msg.stream == stream && msg->port_msg.reply_port == reply_port) { + + nxt_assert(msg->port_msg.last == 0); + /* * An fd is ignored since a file descriptor * must be sent only in the first message of a stream. */ nxt_buf_chain_add(&msg->buf, b); + msg->port_msg.last |= (type & NXT_PORT_MSG_LAST) != 0; + return NXT_OK; } @@ -187,6 +192,7 @@ nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, nxt_uint_t type, msg->buf = b; msg->fd = fd; + msg->close_fd = (type & NXT_PORT_MSG_CLOSE_FD) != 0; msg->share = 0; msg->work.next = NULL; @@ -201,8 +207,8 @@ nxt_port_socket_write(nxt_task_t *task, nxt_port_t *port, nxt_uint_t type, msg->port_msg.stream = stream; msg->port_msg.pid = nxt_pid; msg->port_msg.reply_port = reply_port; - msg->port_msg.type = type; - msg->port_msg.last = 0; + msg->port_msg.type = type & NXT_PORT_MSG_MASK; + msg->port_msg.last = (type & NXT_PORT_MSG_LAST) != 0; msg->port_msg.mmap = 0; nxt_queue_insert_tail(&port->messages, &msg->link); @@ -276,7 +282,7 @@ nxt_port_write_handler(nxt_task_t *task, void *obj, void *data) m = NXT_PORT_METHOD_PLAIN; } - msg->port_msg.last = sb.last; + msg->port_msg.last |= sb.last; n = nxt_socketpair_send(&port->socket, msg->fd, iov, sb.niov + 1); @@ -288,6 +294,12 @@ nxt_port_write_handler(nxt_task_t *task, void *obj, void *data) goto fail; } + if (msg->fd != -1 && msg->close_fd != 0) { + nxt_fd_close(msg->fd); + + msg->fd = -1; + } + wq = &task->thread->engine->fast_work_queue; if (msg->buf != plain_buf) { |