diff options
author | Max Romanov <max.romanov@nginx.com> | 2017-06-23 19:19:41 +0300 |
---|---|---|
committer | Max Romanov <max.romanov@nginx.com> | 2017-06-23 19:19:41 +0300 |
commit | b13cdb0faae250e6aa8c9e46be03e3162f7de27d (patch) | |
tree | 81d9f6d98b07e8a806b0fe2fa42402d32190ae24 /src | |
parent | ac43bfcc72b3a92abc8d935dce8306b05b8c8185 (diff) | |
download | unit-b13cdb0faae250e6aa8c9e46be03e3162f7de27d.tar.gz unit-b13cdb0faae250e6aa8c9e46be03e3162f7de27d.tar.bz2 |
Store mem_pool in buf->data instead of port for consistency.
Diffstat (limited to '')
-rw-r--r-- | src/nxt_port.c | 10 | ||||
-rw-r--r-- | src/nxt_port_memory.c | 46 |
2 files changed, 38 insertions, 18 deletions
diff --git a/src/nxt_port.c b/src/nxt_port.c index fb4d65a6..e9553bd6 100644 --- a/src/nxt_port.c +++ b/src/nxt_port.c @@ -106,7 +106,7 @@ nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, nxt_debug(task, "send new port %FD to process %PI", new_port->socket.fd, process->pid); - b->data = port; + b->data = port->mem_pool; b->completion_handler = nxt_port_new_port_buf_completion; b->mem.free += sizeof(nxt_port_msg_new_port_t); msg = (nxt_port_msg_new_port_t *) b->mem.pos; @@ -128,15 +128,15 @@ nxt_port_send_new_port(nxt_task_t *task, nxt_runtime_t *rt, static void nxt_port_new_port_buf_completion(nxt_task_t *task, void *obj, void *data) { - nxt_buf_t *b; - nxt_port_t *port; + nxt_mp_t *mp; + nxt_buf_t *b; b = obj; - port = b->data; + mp = b->data; /* TODO: b->mem.pos */ - nxt_buf_free(port->mem_pool, b); + nxt_buf_free(mp, b); } diff --git a/src/nxt_port_memory.c b/src/nxt_port_memory.c index 50a6dd5a..2af03f67 100644 --- a/src/nxt_port_memory.c +++ b/src/nxt_port_memory.c @@ -90,7 +90,7 @@ nxt_port_mmap_destroy(nxt_port_mmap_t *port_mmap) } if (port_mmap->fd != -1) { - close(port_mmap->fd); + nxt_fd_close(port_mmap->fd); port_mmap->fd = -1; } } @@ -112,7 +112,15 @@ nxt_port_mmap_buf_completion(nxt_task_t *task, void *obj, void *data) mp = b->data; - port_mmap = (nxt_port_mmap_t *) b->parent; +#if (NXT_DEBUG) + if (nxt_slow_path(data != b->parent)) { + nxt_log_alert(task->log, "completion data (%p) != b->parent (%p)", + data, b->parent); + nxt_abort(); + } +#endif + + port_mmap = data; hdr = port_mmap->u.hdr; if (b->is_port_mmap_sent && b->mem.pos > b->mem.start) { @@ -240,19 +248,27 @@ static void nxt_port_mmap_send_fd_buf_completion(nxt_task_t *task, void *obj, void *data) { nxt_buf_t *b; - nxt_port_t *port; + nxt_mp_t *mp; nxt_port_mmap_t *port_mmap; b = obj; - port = b->data; - port_mmap = (nxt_port_mmap_t *) b->parent; + mp = b->data; + port_mmap = data; - nxt_debug(task, "mmap fd %FD sent to %PI", port_mmap->fd, port->pid); +#if (NXT_DEBUG) + if (nxt_slow_path(data != b->parent)) { + nxt_log_alert(task->log, "completion data (%p) != b->parent (%p)", + data, b->parent); + nxt_abort(); + } +#endif - close(port_mmap->fd); + nxt_debug(task, "mmap fd %FD has been sent", port_mmap->fd); + + nxt_fd_close(port_mmap->fd); port_mmap->fd = -1; - nxt_buf_free(port->mem_pool, b); + nxt_buf_free(mp, b); } @@ -337,6 +353,15 @@ nxt_port_new_port_mmap(nxt_task_t *task, nxt_process_t *process, goto remove_fail; } + b = nxt_buf_mem_alloc(port->mem_pool, 0, 0); + if (nxt_slow_path(b == NULL)) { + goto remove_fail; + } + + b->completion_handler = nxt_port_mmap_send_fd_buf_completion; + b->data = port->mem_pool; + b->parent = port_mmap; + /* Init segment header. */ hdr = port_mmap->u.hdr; @@ -348,11 +373,6 @@ nxt_port_new_port_mmap(nxt_task_t *task, nxt_process_t *process, nxt_debug(task, "send mmap fd %FD to process %PI", port_mmap->fd, port->pid); - b = nxt_buf_mem_alloc(port->mem_pool, 0, 0); - b->completion_handler = nxt_port_mmap_send_fd_buf_completion; - b->data = port; - b->parent = port_mmap; - /* TODO handle error */ (void) nxt_port_socket_write(task, port, NXT_PORT_MSG_MMAP, port_mmap->fd, 0, 0, b); |