static int op_send (void *impl, const flux_msg_t *msg, int flags) { ctx_t *c = impl; assert (c->magic == CTX_MAGIC); int type; flux_msg_t *cpy = NULL; int rc = -1; if (!(cpy = flux_msg_copy (msg, true))) goto done; if (flux_msg_get_type (cpy, &type) < 0) goto done; switch (type) { case FLUX_MSGTYPE_REQUEST: case FLUX_MSGTYPE_EVENT: if (flux_msg_enable_route (cpy) < 0) goto done; if (flux_msg_push_route (cpy, fake_uuid) < 0) goto done; break; } if (msglist_append (c->queue, cpy) < 0) goto done; cpy = NULL; /* c->queue now owns cpy */ rc = 0; done: if (cpy) flux_msg_destroy (cpy); return rc; }
static int op_send (void *impl, const flux_msg_t *msg, int flags) { ctx_t *c = impl; assert (c->magic == CTX_MAGIC); int type; flux_msg_t *cpy = NULL; int rc = -1; if (!(cpy = flux_msg_copy (msg, true))) goto done; if (flux_msg_get_type (cpy, &type) < 0) goto done; if (msglist_append (c->queue, cpy) < 0) goto done; cpy = NULL; /* c->queue now owns cpy */ rc = 0; done: if (cpy) flux_msg_destroy (cpy); return rc; }
/* FIXME: FLUX_O_TRACE will show these messages being received again * So will message counters. */ int flux_requeue (flux_t h, const flux_msg_t *msg, int flags) { flux_msg_t *cpy; int rc; if (flags != FLUX_RQ_TAIL && flags != FLUX_RQ_HEAD) { errno = EINVAL; goto fatal; } if (!(cpy = flux_msg_copy (msg, true))) goto fatal; if (flags == FLUX_RQ_TAIL) rc = msglist_append (h->queue, cpy); else rc = msglist_push (h->queue, cpy); if (rc < 0) { flux_msg_destroy (cpy); goto fatal; } return 0; fatal: FLUX_FATAL (h); return -1; }
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); }