ib/cm: separate listen callback into own handler
[mirror/winof/.git] / core / al / kernel / al_cm.c
index 955985a..177bb9e 100644 (file)
@@ -77,28 +77,49 @@ cm_cep_handler(const ib_al_handle_t h_al, const net32_t cid)
        void                            *context;\r
        net32_t                         new_cid;\r
        ib_mad_element_t        *mad;\r
-       iba_cm_id                       *id, *listen_id;\r
+       iba_cm_id                       *id;\r
        iba_cm_event            event;\r
        NTSTATUS                        status;\r
 \r
        while (al_cep_poll(h_al, cid, &context, &new_cid, &mad) == IB_SUCCESS) {\r
 \r
-               if (new_cid == AL_INVALID_CID) {\r
-                       id = (iba_cm_id *) context;\r
-               } else {\r
-                       listen_id = (iba_cm_id *) context;\r
+               id = (iba_cm_id *) context;\r
+               kal_cep_format_event(h_al, id->cid, mad, &event);\r
+\r
+               status = id->callback(id, &event);\r
+               if (!NT_SUCCESS(status)) {\r
+                       kal_cep_config(h_al, new_cid, NULL, NULL, NULL);\r
+                       kal_cep_destroy(h_al, id->cid, status);\r
+                       cm_free_id(id);\r
+               }\r
+               ib_put_mad(mad);\r
+       }\r
+}\r
+\r
+static void\r
+cm_listen_handler(const ib_al_handle_t h_al, const net32_t cid)\r
+{\r
+       void                            *context;\r
+       net32_t                         new_cid;\r
+       ib_mad_element_t        *mad;\r
+       iba_cm_id                       *id, *listen_id;\r
+       iba_cm_event            event;\r
+       NTSTATUS                        status;\r
+\r
+       while (al_cep_poll(h_al, cid, &context, &new_cid, &mad) == IB_SUCCESS) {\r
 \r
-                       id = cm_alloc_id(listen_id->callback, listen_id);\r
-                       if (id == NULL) {\r
-                               kal_cep_destroy(h_al, new_cid, STATUS_NO_MORE_ENTRIES);\r
-                               ib_put_mad(mad);\r
-                               continue;\r
-                       }\r
+               listen_id = (iba_cm_id *) context;\r
 \r
-                       kal_cep_config(h_al, new_cid, cm_cep_handler, id, cm_destroy_handler);\r
-                       id->cid = new_cid;\r
+               id = cm_alloc_id(listen_id->callback, listen_id);\r
+               if (id == NULL) {\r
+                       kal_cep_destroy(h_al, new_cid, STATUS_NO_MORE_ENTRIES);\r
+                       ib_put_mad(mad);\r
+                       continue;\r
                }\r
 \r
+               kal_cep_config(h_al, new_cid, cm_cep_handler, id, cm_destroy_handler);\r
+               id->cid = new_cid;\r
+\r
                kal_cep_format_event(h_al, id->cid, mad, &event);\r
                status = id->callback(id, &event);\r
                if (!NT_SUCCESS(status)) {\r
@@ -157,6 +178,7 @@ cm_listen(iba_cm_id *p_id, net64_t service_id, void *p_compare_buf,
        info.cmp_len = compare_len;\r
        info.cmp_offset = compare_offset;\r
        \r
+       kal_cep_config(gh_al, p_id->cid, cm_listen_handler, p_id, cm_destroy_handler);\r
        ib_status = al_cep_listen(gh_al, p_id->cid, &info);\r
        return ib_to_ntstatus(ib_status);\r
 }\r