nxt_port_hash.c (277:6baa1731cc6f) nxt_port_hash.c (341:5e1a9c009968)
1
2/*
3 * Copyright (C) Max Romanov
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_port_hash.h>
8

--- 38 unchanged lines hidden (view full) ---

47 nxt_memzero(lhe, sizeof(nxt_lvlhsh_each_t));
48
49 lhe->proto = &lvlhsh_ports_proto;
50
51 return nxt_port_hash_next(port_hash, lhe);
52}
53
54
1
2/*
3 * Copyright (C) Max Romanov
4 * Copyright (C) NGINX, Inc.
5 */
6
7#include <nxt_port_hash.h>
8

--- 38 unchanged lines hidden (view full) ---

47 nxt_memzero(lhe, sizeof(nxt_lvlhsh_each_t));
48
49 lhe->proto = &lvlhsh_ports_proto;
50
51 return nxt_port_hash_next(port_hash, lhe);
52}
53
54
55nxt_inline void
56nxt_port_hash_lhq(nxt_lvlhsh_query_t *lhq, nxt_pid_port_id_t *pid_port)
57{
58 lhq->key_hash = nxt_murmur_hash2(pid_port, sizeof(nxt_pid_port_id_t));
59 lhq->key.length = sizeof(nxt_pid_port_id_t);
60 lhq->key.start = (u_char *) pid_port;
61 lhq->proto = &lvlhsh_ports_proto;
62 lhq->pool = NULL;
63}
64
65
55void
66void
56nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_mp_t *mem_pool,
57 nxt_port_t *port)
67nxt_port_hash_add(nxt_lvlhsh_t *port_hash, nxt_port_t *port)
58{
59 nxt_pid_port_id_t pid_port;
60 nxt_lvlhsh_query_t lhq;
61
62 pid_port.pid = port->pid;
63 pid_port.port_id = port->id;
64
68{
69 nxt_pid_port_id_t pid_port;
70 nxt_lvlhsh_query_t lhq;
71
72 pid_port.pid = port->pid;
73 pid_port.port_id = port->id;
74
65 lhq.key_hash = nxt_murmur_hash2(&pid_port, sizeof(pid_port));
66 lhq.key.length = sizeof(pid_port);
67 lhq.key.start = (u_char *) &pid_port;
68 lhq.proto = &lvlhsh_ports_proto;
75 nxt_port_hash_lhq(&lhq, &pid_port);
69 lhq.replace = 0;
70 lhq.value = port;
76 lhq.replace = 0;
77 lhq.value = port;
71 lhq.pool = mem_pool;
72
73 switch (nxt_lvlhsh_insert(port_hash, &lhq)) {
74
75 case NXT_OK:
76 break;
77
78 default:
79 nxt_thread_log_error(NXT_LOG_WARN, "port #%d for pid %PI add failed",
80 port->id, port->pid);
81 break;
82 }
83}
84
85
86void
78
79 switch (nxt_lvlhsh_insert(port_hash, &lhq)) {
80
81 case NXT_OK:
82 break;
83
84 default:
85 nxt_thread_log_error(NXT_LOG_WARN, "port #%d for pid %PI add failed",
86 port->id, port->pid);
87 break;
88 }
89}
90
91
92void
87nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_mp_t *mem_pool,
88 nxt_port_t *port)
93nxt_port_hash_remove(nxt_lvlhsh_t *port_hash, nxt_port_t *port)
89{
90 nxt_pid_port_id_t pid_port;
91 nxt_lvlhsh_query_t lhq;
92
93 pid_port.pid = port->pid;
94 pid_port.port_id = port->id;
95
94{
95 nxt_pid_port_id_t pid_port;
96 nxt_lvlhsh_query_t lhq;
97
98 pid_port.pid = port->pid;
99 pid_port.port_id = port->id;
100
96 lhq.key_hash = nxt_murmur_hash2(&pid_port, sizeof(pid_port));
97 lhq.key.length = sizeof(pid_port);
98 lhq.key.start = (u_char *) &pid_port;
99 lhq.proto = &lvlhsh_ports_proto;
100 lhq.replace = 0;
101 lhq.value = port;
102 lhq.pool = mem_pool;
101 nxt_port_hash_lhq(&lhq, &pid_port);
103
104 switch (nxt_lvlhsh_delete(port_hash, &lhq)) {
105
106 case NXT_OK:
107 break;
108
109 default:
110 break;

--- 6 unchanged lines hidden (view full) ---

117 nxt_port_id_t port_id)
118{
119 nxt_pid_port_id_t pid_port;
120 nxt_lvlhsh_query_t lhq;
121
122 pid_port.pid = pid;
123 pid_port.port_id = port_id;
124
102
103 switch (nxt_lvlhsh_delete(port_hash, &lhq)) {
104
105 case NXT_OK:
106 break;
107
108 default:
109 break;

--- 6 unchanged lines hidden (view full) ---

116 nxt_port_id_t port_id)
117{
118 nxt_pid_port_id_t pid_port;
119 nxt_lvlhsh_query_t lhq;
120
121 pid_port.pid = pid;
122 pid_port.port_id = port_id;
123
125 lhq.key_hash = nxt_murmur_hash2(&pid_port, sizeof(pid_port));
126 lhq.key.length = sizeof(pid_port);
127 lhq.key.start = (u_char *) &pid_port;
128 lhq.proto = &lvlhsh_ports_proto;
124 nxt_port_hash_lhq(&lhq, &pid_port);
129
125
130 /* TODO lock ports */
131
132 if (nxt_lvlhsh_find(port_hash, &lhq) == NXT_OK) {
133 nxt_thread_log_debug("process port (%PI, %d) found", pid, port_id);
134 return lhq.value;
135 }
136
137 nxt_thread_log_debug("process port (%PI, %d) not found", pid, port_id);
138
139 return NULL;
140}
126 if (nxt_lvlhsh_find(port_hash, &lhq) == NXT_OK) {
127 nxt_thread_log_debug("process port (%PI, %d) found", pid, port_id);
128 return lhq.value;
129 }
130
131 nxt_thread_log_debug("process port (%PI, %d) not found", pid, port_id);
132
133 return NULL;
134}