Skip to content

Commit 3dfa962

Browse files
committed
ctx: Simplify handling for closed contexts.
Once a context has started the process of close, further attempts to close it will return NNG_ECLOSED. What was I thinking to ever do anything else?
1 parent 4f940ce commit 3dfa962

File tree

4 files changed

+13
-16
lines changed

4 files changed

+13
-16
lines changed

src/core/socket.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,7 @@ nni_sock_set_pipe_cb(nni_sock *s, int ev, nng_pipe_cb cb, void *arg)
10301030
}
10311031

10321032
int
1033-
nni_ctx_find(nni_ctx **cp, uint32_t id, bool closing)
1033+
nni_ctx_find(nni_ctx **cp, uint32_t id)
10341034
{
10351035
int rv = 0;
10361036
nni_ctx *ctx;
@@ -1043,7 +1043,7 @@ nni_ctx_find(nni_ctx **cp, uint32_t id, bool closing)
10431043
// we can close it, then we still allow. In the case
10441044
// the only valid operation will be to close the
10451045
// socket.)
1046-
if (ctx->c_closed || ((!closing) && ctx->c_sock->s_closed)) {
1046+
if (ctx->c_closed || ctx->c_sock->s_closed) {
10471047
rv = NNG_ECLOSED;
10481048
} else {
10491049
ctx->c_ref++;

src/core/socket.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,8 @@ extern void nni_sock_set_pipe_cb(nni_sock *sock, int, nng_pipe_cb, void *);
7373
// sockets (will also return NNG_ENOTSUP).
7474
extern int nni_ctx_open(nni_ctx **, nni_sock *);
7575

76-
// nni_ctx_find finds a context given its id. The last argument should
77-
// be true if the context is acquired merely to close it, false otherwise.
78-
// (If the socket for the context is being closed, then this will return
79-
// NNG_ECLOSED unless the final argument is true.)
80-
extern int nni_ctx_find(nni_ctx **, uint32_t, bool);
76+
// nni_ctx_find finds a context given its id.
77+
extern int nni_ctx_find(nni_ctx **, uint32_t);
8178

8279
extern void *nni_ctx_proto_data(nni_ctx *);
8380

src/nng.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ nng_ctx_close(nng_ctx c)
272272
int rv;
273273
nni_ctx *ctx;
274274

275-
if ((rv = nni_ctx_find(&ctx, c.id, true)) != 0) {
275+
if ((rv = nni_ctx_find(&ctx, c.id)) != 0) {
276276
return (rv);
277277
}
278278
// no release, close releases implicitly.
@@ -293,7 +293,7 @@ nng_ctx_recvmsg(nng_ctx cid, nng_msg **msgp, int flags)
293293
nni_aio aio;
294294
nni_ctx *ctx;
295295

296-
if ((rv = nni_ctx_find(&ctx, cid.id, false)) != 0) {
296+
if ((rv = nni_ctx_find(&ctx, cid.id)) != 0) {
297297
return (rv);
298298
}
299299

@@ -326,7 +326,7 @@ nng_ctx_recv(nng_ctx cid, nng_aio *aio)
326326
int rv;
327327
nni_ctx *ctx;
328328

329-
if ((rv = nni_ctx_find(&ctx, cid.id, false)) != 0) {
329+
if ((rv = nni_ctx_find(&ctx, cid.id)) != 0) {
330330
if (nni_aio_begin(aio) == 0) {
331331
nni_aio_finish_error(aio, rv);
332332
}
@@ -348,7 +348,7 @@ nng_ctx_send(nng_ctx cid, nng_aio *aio)
348348
}
349349
return;
350350
}
351-
if ((rv = nni_ctx_find(&ctx, cid.id, false)) != 0) {
351+
if ((rv = nni_ctx_find(&ctx, cid.id)) != 0) {
352352
if (nni_aio_begin(aio) == 0) {
353353
nni_aio_finish_error(aio, rv);
354354
}
@@ -368,7 +368,7 @@ nng_ctx_sendmsg(nng_ctx cid, nng_msg *msg, int flags)
368368
if (msg == NULL) {
369369
return (NNG_EINVAL);
370370
}
371-
if ((rv = nni_ctx_find(&ctx, cid.id, false)) != 0) {
371+
if ((rv = nni_ctx_find(&ctx, cid.id)) != 0) {
372372
return (rv);
373373
}
374374

@@ -403,7 +403,7 @@ ctx_get(nng_ctx id, const char *n, void *v, size_t *szp, nni_type t)
403403
nni_ctx *ctx;
404404
int rv;
405405

406-
if ((rv = nni_ctx_find(&ctx, id.id, false)) != 0) {
406+
if ((rv = nni_ctx_find(&ctx, id.id)) != 0) {
407407
return (rv);
408408
}
409409
rv = nni_ctx_getopt(ctx, n, v, szp, t);
@@ -447,7 +447,7 @@ ctx_set(nng_ctx id, const char *n, const void *v, size_t sz, nni_type t)
447447
nni_ctx *ctx;
448448
int rv;
449449

450-
if ((rv = nni_ctx_find(&ctx, id.id, false)) != 0) {
450+
if ((rv = nni_ctx_find(&ctx, id.id)) != 0) {
451451
return (rv);
452452
}
453453
rv = nni_ctx_setopt(ctx, n, v, sz, t);

src/sp/protocol/pubsub0/sub.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ nng_sub0_ctx_subscribe(nng_ctx id, const void *buf, size_t sz)
753753
nni_ctx *c;
754754
sub0_ctx *ctx;
755755

756-
if ((rv = nni_ctx_find(&c, id.id, false)) != 0) {
756+
if ((rv = nni_ctx_find(&c, id.id)) != 0) {
757757
return (rv);
758758
}
759759
// validate the socket type
@@ -774,7 +774,7 @@ nng_sub0_ctx_unsubscribe(nng_ctx id, const void *buf, size_t sz)
774774
nni_ctx *c;
775775
sub0_ctx *ctx;
776776

777-
if ((rv = nni_ctx_find(&c, id.id, false)) != 0) {
777+
if ((rv = nni_ctx_find(&c, id.id)) != 0) {
778778
return (rv);
779779
}
780780
// validate the socket type

0 commit comments

Comments
 (0)