+ char name[256];
+ static unsigned int count=0;
+
+ smx_action_t act; /* simix action */
+ gras_trp_sg_sock_data_t *sock_data;
+ gras_hostdata_t *hd;
+ gras_hostdata_t *remote_hd;
+ gras_trp_procdata_t trp_remote_proc;
+ gras_msg_procdata_t msg_remote_proc;
+ gras_msg_t msg; /* message to send */
+
+ sock_data = (gras_trp_sg_sock_data_t *)sock->data;
+ hd = (gras_hostdata_t *)SIMIX_host_get_data(SIMIX_host_self());
+ remote_hd = (gras_hostdata_t *)SIMIX_host_get_data(sock_data->to_host);
+
+ xbt_assert0(sock->meas, "SG chunk exchange shouldn't be used on non-measurement sockets");
+
+
+ sprintf(name,"Chunk[%d]",count++);
+ /*initialize gras message */
+ msg = xbt_new(s_gras_msg_t,1);
+ msg->expe = sock;
+ msg->payl_size=size;
+
+ if (data) {
+ msg->payl=(void*)xbt_malloc(size);
+ memcpy(msg->payl,data,size);
+ } else {
+ msg->payl = NULL;
+ }
+
+ /* put message on msg_queue */
+ msg_remote_proc = (gras_msg_procdata_t)gras_libdata_by_name_from_remote("gras_msg",sock_data->to_process);
+ xbt_fifo_push(msg_remote_proc->msg_to_receive_queue,msg);
+
+ /* wake-up the receiver */
+ trp_remote_proc = (gras_trp_procdata_t)gras_libdata_by_name_from_remote("gras_trp",sock_data->to_process);
+ SIMIX_cond_signal(trp_remote_proc->cond);
+
+ SIMIX_mutex_lock(remote_hd->mutex_port[sock->peer_port]);
+ /* wait for the receiver */
+ SIMIX_cond_wait(remote_hd->cond_port[sock->peer_port], remote_hd->mutex_port[sock->peer_port]);
+
+ /* creates simix action and waits its ends, waits in the sender host condition*/
+ DEBUG5("send chunk %s from %s to %s:%d (size=%ld)",
+ name, SIMIX_host_get_name(SIMIX_host_self()),
+ SIMIX_host_get_name(sock_data->to_host), sock->peer_port,size);
+
+ act = SIMIX_action_communicate(sock_data->to_host, SIMIX_host_self(),name, size, -1);
+ SIMIX_register_action_to_condition(act,remote_hd->cond_port[sock->peer_port]);
+ SIMIX_register_condition_to_action(act,remote_hd->cond_port[sock->peer_port]);
+
+ SIMIX_host_get_name(sock_data->to_host),SIMIX_process_get_name(sock_data->to_process),
+
+ SIMIX_cond_wait(remote_hd->cond_port[sock->peer_port], remote_hd->mutex_port[sock->peer_port]);
+ /* error treatmeant */
+
+ /* cleanup structures */
+ SIMIX_action_destroy(act);
+ SIMIX_mutex_unlock(remote_hd->mutex_port[sock->peer_port]);
+ SIMIX_cond_signal(remote_hd->cond_port[sock->peer_port]);