Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Plug a memleak on the name of the incomming messages
[simgrid.git] / src / gras / Transport / sg_transport.c
1 /* $Id$ */
2
3 /* sg_transport - SG specific functions for transport                       */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2004 Martin Quinson.                                       */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include "Transport/transport_private.h"
12 #include <msg.h>
13 #include "Virtu/virtu_sg.h"
14
15 GRAS_LOG_EXTERNAL_CATEGORY(transport);
16 GRAS_LOG_DEFAULT_CATEGORY(transport);
17
18 /**
19  * gras_trp_select:
20  *
21  * Returns the next socket to service having a message awaiting.
22  *
23  * if timeout<0, we ought to implement the adaptative timeout (FIXME)
24  *
25  * if timeout=0, do not wait for new message, only handle the ones already there.
26  *
27  * if timeout>0 and no message there, wait at most that amount of time before giving up.
28  */
29 gras_error_t 
30 gras_trp_select(double timeout, 
31                 gras_socket_t **dst) {
32
33   double startTime=gras_time();
34   gras_procdata_t *pd=gras_procdata_get();
35   gras_trp_sg_sock_data_t *sockdata;
36
37   int r_pid, cpt;
38   m_process_t remote;
39   gras_hostdata_t *remote_hd;
40  
41   do {
42     r_pid = MSG_task_probe_from((m_channel_t) pd->chan);
43     if (r_pid >= 0) {
44       *dst = pd->sock;
45       sockdata = (*dst)->data;
46
47       remote = MSG_process_from_PID(r_pid);
48       sockdata->from_PID = r_pid;
49       sockdata->to_PID = MSG_process_self_PID();
50       sockdata->to_host = MSG_process_get_host(remote);
51
52       remote_hd=(gras_hostdata_t *)MSG_host_get_data(sockdata->to_host);
53       gras_assert0(remote_hd,"Run gras_process_init!!");
54
55       sockdata->to_chan = -1;
56       for (cpt=0; cpt< GRAS_MAX_CHANNEL; cpt++)
57         if (r_pid == remote_hd->proc[cpt])
58           sockdata->to_chan = cpt;
59
60       gras_assert0(sockdata->to_chan>0,
61                    "Got a message from a process without channel");
62
63       return no_error;
64     } else {
65       MSG_process_sleep(0.01);
66     }
67   } while (gras_time()-startTime < timeout
68            || MSG_task_Iprobe((m_channel_t) pd->chan));
69
70   return timeout_error;
71
72 }
73
74
75 /* dummy implementations of the functions used in RL mode */
76
77 gras_error_t gras_trp_tcp_setup(gras_trp_plugin_t *plug) {
78   return mismatch_error;
79 }
80 gras_error_t gras_trp_file_setup(gras_trp_plugin_t *plug) {
81   return mismatch_error;
82 }