- msg=xbt_new0(s_gras_msg_t,1);
- msg->type=msgtype;
- msg->ID = ID;
-
- if (kind == e_gras_msg_kind_rpcerror) {
- /* error on remote host, carfull, payload is an exception */
- msg->payl_size=gras_datadesc_size(gras_datadesc_by_name("ex_t"));
- msg->payl=xbt_malloc(msg->payl_size);
- whole_payload_size = gras_datadesc_copy(gras_datadesc_by_name("ex_t"),
- payload,msg->payl);
- } else if (kind == e_gras_msg_kind_rpcanswer) {
- msg->payl_size=gras_datadesc_size(msgtype->answer_type);
- msg->payl=xbt_malloc(msg->payl_size);
- if (msgtype->answer_type)
- whole_payload_size = gras_datadesc_copy(msgtype->answer_type,
- payload, msg->payl);
- } else {
- msg->payl_size=gras_datadesc_size(msgtype->ctn_type);
- msg->payl=msg->payl_size?xbt_malloc(msg->payl_size):NULL;
- if (msgtype->ctn_type)
- whole_payload_size = gras_datadesc_copy(msgtype->ctn_type,
- payload, msg->payl);
+ XBT_DEBUG
+ ("Consider socket %p (data:%p; Here rdv: %p; Remote rdv: %p; Comm %p) to get a message",
+ sock, sock_data,
+ gras_socket_im_the_server(sock)?
+ sock_data->rdv_server : sock_data->rdv_client,
+ gras_socket_im_the_server(sock)?
+ sock_data->rdv_client : sock_data->rdv_server,
+ sock_data->comm_recv);
+
+
+ /* If the following assert fails in some valid conditions, we need to
+ * change the code downward looking for the socket again.
+ *
+ * For now it relies on the facts (A) that sockets and comms are aligned
+ * (B) every sockets has a posted irecv in comms
+ *
+ * This is not trivial because we need that alignment to hold after the waitany(), so
+ * after other processes get scheduled.
+ *
+ * I cannot think of conditions where they get desynchronized (A violated) as long as
+ * 1) only the listener calls that function
+ * 2) Nobody but the listener removes sockets from that set (in main listener loop)
+ * 3) New sockets are added at the end, and signified ASAP to the listener (by awaking him)
+ * The throw bellow ensures that B is never violated without failing out loudly.
+ *
+ * We cannot search by comparing the comm object pointer that object got
+ * freed by the waiting process (down in smx_network, in
+ * comm_wait_for_completion or comm_cleanup). So, actually, we could
+ * use that pointer since that's a dangling pointer, but no one changes it.
+ * I still feel unconfortable with using dangling pointers, even if that would
+ * let the code work even if A and/or B are violated, provided that
+ * (C) the new irecv is never posted before we return from waitany to that function.
+ *
+ * Another approach, robust to B violation would be to retraverse the socks dynar with
+ * an iterator, incremented only when the socket has a comm. And we've the right socket
+ * when that iterator is equal to "got", the result of waitany. Not needed if B holds.
+ */
+ xbt_assert(sock_data->comm_recv,
+ "Comm_recv of socket %p is empty; please report that nasty bug",
+ sock);
+ /* End of paranoia */
+
+ XBT_VERB("Consider receiving messages from on comm_recv %p rdv:%p (other rdv:%p)",
+ sock_data->comm_recv,
+ gras_socket_im_the_server(sock)?
+ sock_data->rdv_server : sock_data->rdv_client,
+ gras_socket_im_the_server(sock)?
+ sock_data->rdv_client : sock_data->rdv_server);
+ xbt_dynar_push(comms, &(sock_data->comm_recv));