MU_TEST(stress, parallel_print_protocol) { LWMsgContext* context = NULL; LWMsgDataContext* dcontext = NULL; LWMsgProtocol* protocol = NULL; char* text = NULL; MU_TRY(lwmsg_context_new(NULL, &context)); MU_TRY(lwmsg_data_context_new(context, &dcontext)); MU_TRY(lwmsg_protocol_new(context, &protocol)); MU_TRY(lwmsg_protocol_add_protocol_spec(protocol, counterprotocol_spec)); MU_TRY(lwmsg_protocol_print_alloc(protocol, 4, &text)); MU_VERBOSE("\n%s", text); }
static LWMsgStatus lwmsg_peer_startup( LWMsgPeer* peer ) { LWMsgStatus status = LWMSG_STATUS_SUCCESS; LWMsgRing* ring = NULL; PeerEndpoint* endpoint = NULL; PeerListenTask* task = NULL; char* message = NULL; if (!peer->listen_tasks) { BAIL_ON_ERROR(status = lwmsg_task_group_new(peer->task_manager, &peer->listen_tasks)); } for (ring = peer->listen_endpoints.next; ring != &peer->listen_endpoints; ring = ring->next) { endpoint = LWMSG_OBJECT_FROM_MEMBER(ring, PeerEndpoint, ring); switch (endpoint->type) { case LWMSG_ENDPOINT_DIRECT: BAIL_ON_ERROR(status = lwmsg_direct_listen(endpoint->endpoint, peer)); break; default: BAIL_ON_ERROR(status = lwmsg_peer_listen_task_new( peer, endpoint->type, endpoint->endpoint, endpoint->permissions, endpoint->fd, &task)); task = NULL; } } /* Run all listen tasks */ lwmsg_task_group_wake(peer->listen_tasks); LWMSG_LOG_INFO(peer->context, "Listener started"); if (lwmsg_context_would_log(peer->context, LWMSG_LOGLEVEL_TRACE)) { BAIL_ON_ERROR(status = lwmsg_protocol_print_alloc(peer->protocol, 4, &message)); LWMSG_LOG_TRACE(peer->context, "Listen protocol:\n%s", message); } done: if (message) { lwmsg_context_free(peer->protocol->context, message); } return status; error: if (peer->listen_tasks) { lwmsg_task_group_cancel(peer->listen_tasks); lwmsg_task_group_wait(peer->listen_tasks); lwmsg_task_group_delete(peer->listen_tasks); peer->listen_tasks = NULL; } goto done; }