aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/event.c32
-rw-r--r--src/core/event.h2
-rw-r--r--src/core/socket.c8
3 files changed, 39 insertions, 3 deletions
diff --git a/src/core/event.c b/src/core/event.c
index 1b264632..73bc1c00 100644
--- a/src/core/event.c
+++ b/src/core/event.c
@@ -95,7 +95,7 @@ nni_notifier(void *arg)
// No interest.
continue;
}
- notify->n_func(event, &notify->n_arg);
+ notify->n_func(event, notify->n_arg);
}
nni_mtx_unlock(&sock->s_notify_mx);
@@ -112,3 +112,33 @@ nni_notifier(void *arg)
}
nni_mtx_unlock(&sock->s_mx);
}
+
+
+nni_notify *
+nni_add_notify(nni_sock *sock, int mask, nng_notify_func fn, void *arg)
+{
+ nni_notify *notify;
+
+ if ((notify = NNI_ALLOC_STRUCT(notify)) == NULL) {
+ return (NULL);
+ }
+ notify->n_func = fn;
+ notify->n_arg = arg;
+ notify->n_mask = mask;
+ NNI_LIST_NODE_INIT(&notify->n_node);
+
+ nni_mtx_lock(&sock->s_notify_mx);
+ nni_list_append(&sock->s_notify, notify);
+ nni_mtx_unlock(&sock->s_notify_mx);
+ return (notify);
+}
+
+
+void
+nni_rem_notify(nni_sock *sock, nni_notify *notify)
+{
+ nni_mtx_lock(&sock->s_notify_mx);
+ nni_list_remove(&sock->s_notify, notify);
+ nni_mtx_unlock(&sock->s_notify_mx);
+ NNI_FREE_STRUCT(notify);
+}
diff --git a/src/core/event.h b/src/core/event.h
index 8b160a89..74d6fddb 100644
--- a/src/core/event.h
+++ b/src/core/event.h
@@ -37,5 +37,7 @@ extern int nni_ev_init(nni_event *, int, nni_sock *);
extern void nni_ev_fini(nni_event *);
extern void nni_ev_submit(nni_event *); // call holding sock lock
extern void nni_ev_wait(nni_event *); // call holding sock lock
+extern nni_notify *nni_add_notify(nni_sock *, int, nng_notify_func, void *);
+extern void nni_rem_notify(nni_sock *, nni_notify *);
#endif // CORE_EVENT_H
diff --git a/src/core/socket.c b/src/core/socket.c
index 734e4da8..1e9fe11f 100644
--- a/src/core/socket.c
+++ b/src/core/socket.c
@@ -232,8 +232,12 @@ nni_sock_open(nni_sock **sockp, uint16_t pnum)
goto fail;
}
- if (((rv = nni_ev_init(&sock->s_recv_ev, NNG_EVENT_RECV, sock)) != 0) ||
- ((rv = nni_ev_init(&sock->s_send_ev, NNG_EVENT_SEND, sock)) != 0)) {
+ rv = nni_ev_init(&sock->s_recv_ev, NNG_EV_CAN_RECV, sock);
+ if (rv != 0) {
+ goto fail;
+ }
+ rv = nni_ev_init(&sock->s_send_ev, NNG_EV_CAN_SEND, sock);
+ if (rv != 0) {
goto fail;
}