Skip to content

Commit 1413b24

Browse files
committed
fixes #1389 PAIRv1 can remove a few bits
1 parent 4048c91 commit 1413b24

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

src/protocol/pair1/pair.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ struct pair1_sock {
3636
nni_msgq * urq;
3737
nni_sock * sock;
3838
bool raw;
39+
pair1_pipe * p;
3940
nni_atomic_int ttl;
4041
nni_mtx mtx;
41-
nni_id_map pipes;
42-
nni_list plist;
43-
bool started;
4442
#ifdef NNG_ENABLE_STATS
4543
nni_stat_item stat_poly;
4644
nni_stat_item stat_raw;
@@ -58,21 +56,19 @@ struct pair1_sock {
5856

5957
// pair1_pipe is our per-pipe protocol private structure.
6058
struct pair1_pipe {
61-
nni_pipe * pipe;
62-
pair1_sock * pair;
63-
nni_aio aio_send;
64-
nni_aio aio_recv;
65-
nni_aio aio_get;
66-
nni_aio aio_put;
67-
nni_list_node node;
59+
nni_pipe * pipe;
60+
pair1_sock *pair;
61+
nni_aio aio_send;
62+
nni_aio aio_recv;
63+
nni_aio aio_get;
64+
nni_aio aio_put;
6865
};
6966

7067
static void
7168
pair1_sock_fini(void *arg)
7269
{
7370
pair1_sock *s = arg;
7471

75-
nni_id_map_fini(&s->pipes);
7672
nni_mtx_fini(&s->mtx);
7773
}
7874

@@ -91,9 +87,6 @@ pair1_sock_init_impl(void *arg, nni_sock *sock, bool raw)
9187
{
9288
pair1_sock *s = arg;
9389

94-
nni_id_map_init(&s->pipes, 0, 0, false);
95-
NNI_LIST_INIT(&s->plist, pair1_pipe, node);
96-
9790
// Raw mode uses this.
9891
nni_mtx_init(&s->mtx);
9992
s->sock = sock;
@@ -193,7 +186,13 @@ static void
193186
pair1_pipe_stop(void *arg)
194187
{
195188
pair1_pipe *p = arg;
189+
pair1_sock *s = p->pair;
196190

191+
nni_mtx_lock(&s->mtx);
192+
if (s->p == p) {
193+
s->p = NULL;
194+
}
195+
nni_mtx_unlock(&s->mtx);
197196
nni_aio_stop(&p->aio_send);
198197
nni_aio_stop(&p->aio_recv);
199198
nni_aio_stop(&p->aio_put);
@@ -232,30 +231,20 @@ pair1_pipe_start(void *arg)
232231
{
233232
pair1_pipe *p = arg;
234233
pair1_sock *s = p->pair;
235-
uint32_t id;
236-
int rv;
237234

238-
nni_mtx_lock(&s->mtx);
239235
if (nni_pipe_peer(p->pipe) != NNG_PAIR1_PEER) {
240-
nni_mtx_unlock(&s->mtx);
241236
BUMP_STAT(&s->stat_reject_mismatch);
242237
// Peer protocol mismatch.
243238
return (NNG_EPROTO);
244239
}
245240

246-
id = nni_pipe_id(p->pipe);
247-
if ((rv = nni_id_set(&s->pipes, id, p)) != 0) {
248-
nni_mtx_unlock(&s->mtx);
249-
return (rv);
250-
}
251-
if (!nni_list_empty(&s->plist)) {
252-
nni_id_remove(&s->pipes, id);
241+
nni_mtx_lock(&s->mtx);
242+
if (s->p != NULL) {
253243
nni_mtx_unlock(&s->mtx);
254244
BUMP_STAT(&s->stat_reject_already);
255245
return (NNG_EBUSY);
256246
}
257-
nni_list_append(&s->plist, p);
258-
s->started = true;
247+
s->p = p;
259248
nni_mtx_unlock(&s->mtx);
260249

261250
// Schedule a get.
@@ -271,17 +260,11 @@ static void
271260
pair1_pipe_close(void *arg)
272261
{
273262
pair1_pipe *p = arg;
274-
pair1_sock *s = p->pair;
275263

276264
nni_aio_close(&p->aio_send);
277265
nni_aio_close(&p->aio_recv);
278266
nni_aio_close(&p->aio_put);
279267
nni_aio_close(&p->aio_get);
280-
281-
nni_mtx_lock(&s->mtx);
282-
nni_id_remove(&s->pipes, nni_pipe_id(p->pipe));
283-
nni_list_node_remove(&p->node);
284-
nni_mtx_unlock(&s->mtx);
285268
}
286269

287270
static void

0 commit comments

Comments
 (0)