summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMax Romanov <max.romanov@nginx.com>2017-10-04 15:02:00 +0300
committerMax Romanov <max.romanov@nginx.com>2017-10-04 15:02:00 +0300
commitf869bf1b020ed41d5a64b106ba48ec45412b912c (patch)
treeff4e48ce4288a6ace271031154f43adda509f324
parent85e485776b9c52e1762e6cc53406e956c604d9de (diff)
downloadunit-f869bf1b020ed41d5a64b106ba48ec45412b912c.tar.gz
unit-f869bf1b020ed41d5a64b106ba48ec45412b912c.tar.bz2
Return error codes for port_hash operations.
-rw-r--r--src/nxt_port_hash.c20
-rw-r--r--src/nxt_port_hash.h4
-rw-r--r--src/nxt_runtime.c14
3 files changed, 30 insertions, 8 deletions
diff --git a/src/nxt_port_hash.c b/src/nxt_port_hash.c
index c23bcbc6..6361f220 100644
--- a/src/nxt_port_hash.c
+++ b/src/nxt_port_hash.c
@@ -63,9 +63,10 @@ nxt_port_hash_lhq(nxt_lvlhsh_query_t *lhq, nxt_pid_port_id_t *pid_port)
}
-void
+nxt_int_t
nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_port_t *port)
{
+ nxt_int_t res;
nxt_pid_port_id_t pid_port;
nxt_lvlhsh_query_t lhq;
@@ -76,7 +77,9 @@ nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_port_t *port)
lhq.replace = 0;
lhq.value = port;
- switch (nxt_lvlhsh_insert(port_hash, &lhq)) {
+ res = nxt_lvlhsh_insert(port_hash, &lhq);
+
+ switch (res) {
case NXT_OK:
break;
@@ -86,12 +89,15 @@ nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_port_t *port)
port->id, port->pid);
break;
}
+
+ return res;
}
-void
+nxt_int_t
nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_port_t *port)
{
+ nxt_int_t res;
nxt_pid_port_id_t pid_port;
nxt_lvlhsh_query_t lhq;
@@ -100,14 +106,20 @@ nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_port_t *port)
nxt_port_hash_lhq(&lhq, &pid_port);
- switch (nxt_lvlhsh_delete(port_hash, &lhq)) {
+ res = nxt_lvlhsh_delete(port_hash, &lhq);
+
+ switch (res) {
case NXT_OK:
break;
default:
+ nxt_thread_log_error(NXT_LOG_WARN, "port #%d for pid %PI remove failed",
+ port->id, port->pid);
break;
}
+
+ return res;
}
diff --git a/src/nxt_port_hash.h b/src/nxt_port_hash.h
index 68389f30..69a1a8e3 100644
--- a/src/nxt_port_hash.h
+++ b/src/nxt_port_hash.h
@@ -11,9 +11,9 @@
#include <nxt_main.h>
-void nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_port_t *port);
+nxt_int_t nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_port_t *port);
-void nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_port_t *port);
+nxt_int_t nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_port_t *port);
nxt_port_t *nxt_port_hash_find(nxt_lvlhsh_t *port_hash, nxt_pid_t pid,
nxt_port_id_t port_id);
diff --git a/src/nxt_runtime.c b/src/nxt_runtime.c
index a96f4cea..be88fc30 100644
--- a/src/nxt_runtime.c
+++ b/src/nxt_runtime.c
@@ -1859,11 +1859,16 @@ nxt_runtime_port_first(nxt_runtime_t *rt, nxt_lvlhsh_each_t *lhe)
void
nxt_runtime_port_add(nxt_task_t *task, nxt_port_t *port)
{
+ nxt_int_t res;
nxt_runtime_t *rt;
rt = task->thread->runtime;
- nxt_port_hash_add(&rt->ports, port);
+ res = nxt_port_hash_add(&rt->ports, port);
+
+ if (res != NXT_OK) {
+ return;
+ }
rt->port_by_type[port->type] = port;
@@ -1874,11 +1879,16 @@ nxt_runtime_port_add(nxt_task_t *task, nxt_port_t *port)
void
nxt_runtime_port_remove(nxt_task_t *task, nxt_port_t *port)
{
+ nxt_int_t res;
nxt_runtime_t *rt;
rt = task->thread->runtime;
- nxt_port_hash_remove(&rt->ports, port);
+ res = nxt_port_hash_remove(&rt->ports, port);
+
+ if (res != NXT_OK) {
+ return;
+ }
if (rt->port_by_type[port->type] == port) {
rt->port_by_type[port->type] = NULL;