3 /* sg_transport - SG specific functions for transport */
5 /* Copyright (c) 2004 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "gras/Transport/transport_private.h"
12 #include "gras/Virtu/virtu_sg.h"
14 XBT_LOG_EXTERNAL_CATEGORY(transport);
15 XBT_LOG_DEFAULT_CATEGORY(transport);
20 * Returns the next socket to service having a message awaiting.
22 * if timeout<0, we ought to implement the adaptative timeout (FIXME)
24 * if timeout=0, do not wait for new message, only handle the ones already there.
26 * if timeout>0 and no message there, wait at most that amount of time before giving up.
29 gras_trp_select(double timeout,
33 double startTime=gras_os_time();
34 gras_procdata_t *pd=gras_procdata_get();
35 gras_trp_sg_sock_data_t *sockdata;
36 gras_trp_plugin_t *trp;
38 gras_socket_t sock_iter; /* iterating over all sockets */
41 gras_sg_portrec_t pr; /* iterating to find the chanel of expeditor */
44 gras_hostdata_t *remote_hd;
46 DEBUG3("select on %s@%s with timeout=%f",
47 MSG_process_get_name(MSG_process_self()),
48 MSG_host_get_name(MSG_host_self()),
51 r_pid = MSG_task_probe_from((m_channel_t) pd->chan);
53 /* Try to reuse an already openned socket to that expeditor */
54 xbt_dynar_foreach(pd->sockets,cursor,sock_iter) {
55 DEBUG1("Consider %p as outgoing socket to expeditor",sock_iter);
56 sockdata = sock_iter->data;
58 if (sock_iter->raw || !sock_iter->outgoing)
61 if (sockdata->from_PID == r_pid) {
67 /* Socket to expeditor not created yet */
68 DEBUG0("Create a socket to the expeditor");
70 TRY(gras_trp_plugin_get_by_name("buf",&trp));
72 gras_trp_socket_new(1,dst);
77 (*dst)->accepting = 0;
82 sockdata = xbt_new(gras_trp_sg_sock_data_t,1);
83 sockdata->from_PID = MSG_process_self_PID();
84 sockdata->to_PID = r_pid;
85 sockdata->to_host = MSG_process_get_host(MSG_process_from_PID(r_pid));
86 (*dst)->data = sockdata;
87 gras_trp_buf_init_sock(*dst);
89 (*dst)->peer_name = strdup(MSG_host_get_name(sockdata->to_host));
91 remote_hd=(gras_hostdata_t *)MSG_host_get_data(sockdata->to_host);
92 xbt_assert0(remote_hd,"Run gras_process_init!!");
94 sockdata->to_chan = -1;
95 (*dst)->peer_port = -10;
96 for (cursor=0; cursor<XBT_MAX_CHANNEL; cursor++) {
97 if (remote_hd->proc[cursor] == r_pid) {
98 sockdata->to_chan = cursor;
99 DEBUG2("Chan %d on %s is for my pal",
100 cursor,(*dst)->peer_name);
102 xbt_dynar_foreach(remote_hd->ports, cpt, pr) {
103 if (sockdata->to_chan == pr.tochan) {
105 DEBUG0("Damn, it's raw");
109 (*dst)->peer_port = pr.port;
110 DEBUG1("Cool, it points to port %d", pr.port);
113 DEBUG2("Wrong port (tochan=%d, looking for %d)\n",
114 pr.tochan,sockdata->to_chan);
117 if ((*dst)->peer_port == -10) {
119 sockdata->to_chan = -1;
121 /* found it, don't let it override by raw */
126 xbt_assert0(sockdata->to_chan != -1,
127 "Got a message from a process without channel");
132 DEBUG2("Select on %s@%s did not find anything yet",
133 MSG_process_get_name(MSG_process_self()),
134 MSG_host_get_name(MSG_host_self()));
136 /* MSG_process_sleep(1); */
137 MSG_process_sleep(0.001);
139 } while (gras_os_time()-startTime < timeout
140 || MSG_task_Iprobe((m_channel_t) pd->chan));
142 return timeout_error;
147 /* dummy implementations of the functions used in RL mode */
149 xbt_error_t gras_trp_tcp_setup(gras_trp_plugin_t *plug) {
150 return mismatch_error;
152 xbt_error_t gras_trp_file_setup(gras_trp_plugin_t *plug) {
153 return mismatch_error;