@@ -641,10 +641,18 @@ static void reg_event_hdlr(int sd, short args, void *cbdata)
641641 break ;
642642 }
643643 }
644- /* if the handler wasn't found, then it may show up later - so
645- * for now just prepend it to the list */
644+ /* if the handler wasn't found, then we return an error. At some
645+ * future time, we may change this behavior and cache this handler
646+ * until the reference one has been registered. However, this could
647+ * turn out to be a laborious search procedure as the reference
648+ * event handler may in turn be dependent on another handler, etc. */
646649 if (!found ) {
647- pmix_list_prepend (cd -> list , & evhdlr -> super );
650+ /* this is an error */
651+ -- pmix_globals .events .nhdlrs ;
652+ rc = PMIX_ERR_EVENT_REGISTRATION ;
653+ index = UINT_MAX ;
654+ PMIX_RELEASE (evhdlr );
655+ goto ack ;
648656 }
649657 }
650658 if (PMIX_ERR_WOULD_BLOCK == rc ) {
@@ -710,57 +718,54 @@ static void dereg_event_hdlr(int sd, short args, void *cbdata)
710718 }
711719
712720 /* check the first and last locations */
713- if (NULL != pmix_globals .events .first ||
714- NULL != pmix_globals .events .last ) {
715- if (pmix_globals .events .first -> index == cd -> ref ||
716- pmix_globals .events .last -> index == cd -> ref ) {
717- /* found it */
718- if (pmix_globals .events .first -> index == cd -> ref ) {
719- ev = pmix_globals .events .first ;
720- } else {
721- ev = pmix_globals .events .last ;
722- }
723- if (NULL != msg ) {
724- /* if this is a default handler, see if any other default
725- * handlers remain */
726- if (NULL == ev -> codes ) {
727- if (0 == pmix_list_get_size (& pmix_globals .events .default_events )) {
728- /* tell the server to dereg our default handler */
729- if (PMIX_SUCCESS != (rc = pmix_bfrop .pack (msg , & wildcard , 1 , PMIX_STATUS ))) {
730- PMIX_RELEASE (msg );
731- goto cleanup ;
732- }
721+ if ((NULL != pmix_globals .events .first && pmix_globals .events .first -> index == cd -> ref ) ||
722+ (NULL != pmix_globals .events .last && pmix_globals .events .last -> index == cd -> ref )) {
723+ /* found it */
724+ if (NULL != pmix_globals .events .first && pmix_globals .events .first -> index == cd -> ref ) {
725+ ev = pmix_globals .events .first ;
726+ } else {
727+ ev = pmix_globals .events .last ;
728+ }
729+ if (NULL != msg ) {
730+ /* if this is a default handler, see if any other default
731+ * handlers remain */
732+ if (NULL == ev -> codes ) {
733+ if (0 == pmix_list_get_size (& pmix_globals .events .default_events )) {
734+ /* tell the server to dereg our default handler */
735+ if (PMIX_SUCCESS != (rc = pmix_bfrop .pack (msg , & wildcard , 1 , PMIX_STATUS ))) {
736+ PMIX_RELEASE (msg );
737+ goto cleanup ;
733738 }
734- } else {
735- for (n = 0 ; n < ev -> ncodes ; n ++ ) {
736- /* see if this is the last registration we have for this code */
737- PMIX_LIST_FOREACH (active , & pmix_globals .events .actives , pmix_active_code_t ) {
738- if (active -> code == ev -> codes [n ]) {
739- -- active -> nregs ;
740- if (0 == active -> nregs ) {
741- pmix_list_remove_item (& pmix_globals .events .actives , & active -> super );
742- /* tell the server to dereg this code */
743- if (PMIX_SUCCESS != (rc = pmix_bfrop .pack (msg , & active -> code , 1 , PMIX_STATUS ))) {
744- PMIX_RELEASE (active );
745- PMIX_RELEASE (msg );
746- goto cleanup ;
747- }
739+ }
740+ } else {
741+ for (n = 0 ; n < ev -> ncodes ; n ++ ) {
742+ /* see if this is the last registration we have for this code */
743+ PMIX_LIST_FOREACH (active , & pmix_globals .events .actives , pmix_active_code_t ) {
744+ if (active -> code == ev -> codes [n ]) {
745+ -- active -> nregs ;
746+ if (0 == active -> nregs ) {
747+ pmix_list_remove_item (& pmix_globals .events .actives , & active -> super );
748+ /* tell the server to dereg this code */
749+ if (PMIX_SUCCESS != (rc = pmix_bfrop .pack (msg , & active -> code , 1 , PMIX_STATUS ))) {
748750 PMIX_RELEASE (active );
751+ PMIX_RELEASE (msg );
752+ goto cleanup ;
749753 }
750- break ;
754+ PMIX_RELEASE ( active ) ;
751755 }
756+ break ;
752757 }
753758 }
754759 }
755760 }
756- if (pmix_globals .events .first -> index == cd -> ref ) {
757- pmix_globals .events .first = NULL ;
758- } else {
759- pmix_globals .events .last = NULL ;
760- }
761- PMIX_RELEASE (ev );
762- goto cleanup ;
763761 }
762+ if (ev == pmix_globals .events .first ) {
763+ pmix_globals .events .first = NULL ;
764+ } else {
765+ pmix_globals .events .last = NULL ;
766+ }
767+ PMIX_RELEASE (ev );
768+ goto cleanup ;
764769 }
765770
766771 /* the registration can be in any of three places, so check each of them */
@@ -793,11 +798,13 @@ static void dereg_event_hdlr(int sd, short args, void *cbdata)
793798 -- active -> nregs ;
794799 if (0 == active -> nregs ) {
795800 pmix_list_remove_item (& pmix_globals .events .actives , & active -> super );
796- /* tell the server to dereg this code */
797- if (PMIX_SUCCESS != (rc = pmix_bfrop .pack (msg , & active -> code , 1 , PMIX_STATUS ))) {
798- PMIX_RELEASE (active );
799- PMIX_RELEASE (msg );
800- goto cleanup ;
801+ if (NULL != msg ) {
802+ /* tell the server to dereg this code */
803+ if (PMIX_SUCCESS != (rc = pmix_bfrop .pack (msg , & active -> code , 1 , PMIX_STATUS ))) {
804+ PMIX_RELEASE (active );
805+ PMIX_RELEASE (msg );
806+ goto cleanup ;
807+ }
801808 }
802809 PMIX_RELEASE (active );
803810 }
@@ -820,11 +827,13 @@ static void dereg_event_hdlr(int sd, short args, void *cbdata)
820827 -- active -> nregs ;
821828 if (0 == active -> nregs ) {
822829 pmix_list_remove_item (& pmix_globals .events .actives , & active -> super );
823- /* tell the server to dereg this code */
824- if (PMIX_SUCCESS != (rc = pmix_bfrop .pack (msg , & active -> code , 1 , PMIX_STATUS ))) {
825- PMIX_RELEASE (active );
826- PMIX_RELEASE (msg );
827- goto cleanup ;
830+ if (NULL != msg ) {
831+ /* tell the server to dereg this code */
832+ if (PMIX_SUCCESS != (rc = pmix_bfrop .pack (msg , & active -> code , 1 , PMIX_STATUS ))) {
833+ PMIX_RELEASE (active );
834+ PMIX_RELEASE (msg );
835+ goto cleanup ;
836+ }
828837 }
829838 PMIX_RELEASE (active );
830839 }
0 commit comments