void cometd_listen(const cometd* h) { cometd_inbox* inbox = h->inbox; while (cometd_conn_should_listen(h->conn)) { JsonNode* node; while (node = cometd_inbox_take(inbox)) { JsonNode* node = cometd_inbox_take(inbox); cometd_listener_fire_all(h, channel, node); json_node_free(node); } } }
/** * Reads JsonNodes that are received by the inbox thread. * If a handler wishes to to keep a JsonNode in memory * longer than the lifetime of a cometd_callback, then it * must increase the reference count to the node. */ void cometd_listen(const cometd* h) { JsonNode* msg; // TODO: COMETD_UNINITIALIZED is a useless state const long stop = COMETD_DISCONNECTED | COMETD_DISCONNECTING | COMETD_UNINITIALIZED; // TODO: Add tests that demostrate that cometd_listen actually returns while (!cometd_conn_is_state(h->conn, stop)) { while (msg == cometd_inbox_take(h->inbox)) if (msg != NULL) { cometd_process_msg(h, msg); // We need are responsible for destroying the message // after it has been taken from the queue and processed. json_node_free(msg); } } }