void pmix_usock_init(pmix_usock_cbfunc_t cbfunc) { pmix_usock_posted_recv_t *req; /* setup the usock globals */ PMIX_CONSTRUCT(&pmix_usock_globals.posted_recvs, pmix_list_t); /* if a cbfunc was given, post a persistent recv * for the special 0 tag so the client can recv * error notifications from the server */ if (NULL != cbfunc) { req = PMIX_NEW(pmix_usock_posted_recv_t); req->tag = 0; req->cbfunc = cbfunc; pmix_output_verbose(5, pmix_globals.debug_output, "posting notification recv on tag %d", req->tag); /* add it to the list of recvs - we cannot have unexpected messages * in this subsystem as the server never sends us something that * we didn't previously request */ pmix_list_prepend(&pmix_usock_globals.posted_recvs, &req->super); } }
void pmix_usock_send_recv(int fd, short args, void *cbdata) { pmix_ptl_sr_t *ms = (pmix_ptl_sr_t*)cbdata; pmix_ptl_posted_recv_t *req; pmix_ptl_send_t *snd; uint32_t tag; /* acquire the object */ PMIX_ACQUIRE_OBJECT(ms); if (ms->peer->sd < 0) { /* this peer's socket has been closed */ PMIX_RELEASE(ms); /* ensure we post the object before another thread * picks it back up */ PMIX_POST_OBJECT(NULL); return; } /* take the next tag in the sequence */ pmix_ptl_globals.current_tag++; if (UINT32_MAX == pmix_ptl_globals.current_tag ) { pmix_ptl_globals.current_tag = PMIX_PTL_TAG_DYNAMIC; } tag = pmix_ptl_globals.current_tag; if (NULL != ms->cbfunc) { /* if a callback msg is expected, setup a recv for it */ req = PMIX_NEW(pmix_ptl_posted_recv_t); req->tag = tag; req->cbfunc = ms->cbfunc; req->cbdata = ms->cbdata; pmix_output_verbose(5, pmix_ptl_base_framework.framework_output, "posting recv on tag %d", req->tag); /* add it to the list of recvs - we cannot have unexpected messages * in this subsystem as the server never sends us something that * we didn't previously request */ pmix_list_prepend(&pmix_ptl_globals.posted_recvs, &req->super); } snd = PMIX_NEW(pmix_ptl_send_t); snd->hdr.pindex = pmix_globals.pindex; snd->hdr.tag = tag; snd->hdr.nbytes = ms->bfr->bytes_used; snd->data = ms->bfr; /* always start with the header */ snd->sdptr = (char*)&snd->hdr; snd->sdbytes = sizeof(pmix_usock_hdr_t); /* if there is no message on-deck, put this one there */ if (NULL == ms->peer->send_msg) { ms->peer->send_msg = snd; } else { /* add it to the queue */ pmix_list_append(&ms->peer->send_queue, &snd->super); } /* ensure the send event is active */ if (!ms->peer->send_ev_active) { ms->peer->send_ev_active = true; PMIX_POST_OBJECT(snd); pmix_event_add(&ms->peer->send_event, 0); } /* cleanup */ PMIX_RELEASE(ms); PMIX_POST_OBJECT(snd); }