static void op_fini (void *impl) { ctx_t *c = impl; assert (c->magic == CTX_MAGIC); if (c->pollfd >= 0) close (c->pollfd); msglist_destroy (c->queue); c->magic = ~CTX_MAGIC; free (c); }
void flux_handle_destroy (flux_t *hp) { if (hp) { flux_t h = *hp; if (h && --h->usecount == 0) { zhash_destroy (&h->aux); if (h->ops->impl_destroy) h->ops->impl_destroy (h->impl); tagpool_destroy (h->tagpool); if (h->dso) dlclose (h->dso); msglist_destroy (h->queue); if (h->pollfd >= 0) (void)close (h->pollfd); free (h); } *hp = NULL; } }
void flux_handle_destroy (flux_t *h) { if (h && --h->usecount == 0) { zhash_destroy (&h->aux); if ((h->flags & FLUX_O_CLONE)) { flux_handle_destroy (h->parent); // decr usecount } else { if (h->ops->impl_destroy) h->ops->impl_destroy (h->impl); tagpool_destroy (h->tagpool); if (h->dso) dlclose (h->dso); msglist_destroy (h->queue); if (h->pollfd >= 0) (void)close (h->pollfd); } free (h); } }
int main (int argc, char *argv[]) { msglist_t *ml; int e; char *msg; struct pollfd pfd; plan (19); ok ((ml = msglist_create (free)) != NULL, "msglist_create works"); ok ((e = msglist_pollevents (ml)) >= 0 && e == POLLOUT, "msglist_pollevents on empty msglist returns POLLOUT"); ok (msglist_append (ml, xstrdup ("foo")) == 0, "msglist_append 'foo' works"); ok ((e = msglist_pollevents (ml)) >= 0 && e == (POLLOUT | POLLIN), "msglist_pollevents on non-empty msglist returns POLLOUT | POLLIN"); ok (msglist_push (ml, xstrdup ("bar")) == 0, "msglist_push 'bar' works"); ok ((e = msglist_pollevents (ml)) >= 0 && e == (POLLOUT | POLLIN), "msglist_pollevents still returns POLLOUT | POLLIN"); ok ((msg = msglist_pop (ml)) != NULL && !strcmp (msg, "bar"), "msglist_pop returns 'bar'"); ok ((e = msglist_pollevents (ml)) >= 0 && e == (POLLOUT | POLLIN), "msglist_pollevents still returns POLLOUT | POLLIN"); free (msg); ok ((msg = msglist_pop (ml)) != NULL && !strcmp (msg, "foo"), "msglist_pop returns 'foo'"); ok ((e = msglist_pollevents (ml)) >= 0 && e == POLLOUT, "msglist_pollevents on empty msglist returns POLLOUT"); free (msg); ok ((pfd.fd = msglist_pollfd (ml)) >= 0, "msglist_pollfd works"); pfd.events = POLLIN, pfd.revents = 0, ok (poll (&pfd, 1, 0) == 1 && pfd.revents == POLLIN, "pollfd suggests we read pollevents"); ok ((e = msglist_pollevents (ml)) >= 0 && e == POLLOUT, "msglist_pollevents on empty msglist returns POLLOUT"); pfd.events = POLLIN, pfd.revents = 0, ok (poll (&pfd, 1, 0) == 0, "pollfd is no longer ready"); ok (msglist_push (ml, xstrdup ("foo")) == 0, "msglist_push 'foo' works"); pfd.events = POLLIN, pfd.revents = 0, ok (poll (&pfd, 1, 0) == 1 && pfd.revents == POLLIN, "pollfd suggests we read pollevents"); ok ((e = msglist_pollevents (ml)) >= 0 && e == (POLLOUT | POLLIN), "msglist_pollevents on non-empty msglist returns POLLOUT | POLLIN"); pfd.events = POLLIN, pfd.revents = 0, ok (poll (&pfd, 1, 0) == 0, "pollfd is no longer ready"); ok ((e = msglist_pollevents (ml)) >= 0 && e == (POLLOUT | POLLIN), "msglist_pollevents still returns POLLOUT | POLLIN"); msglist_destroy (ml); done_testing (); return (0); }