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. */
11 #include "gras/Transport/transport_private.h"
13 #include "gras/Virtu/virtu_sg.h"
15 XBT_LOG_EXTERNAL_CATEGORY(transport);
16 XBT_LOG_DEFAULT_CATEGORY(transport);
21 * Returns the next socket to service having a message awaiting.
23 * if timeout<0, we ought to implement the adaptative timeout (FIXME)
25 * if timeout=0, do not wait for new message, only handle the ones already there.
27 * if timeout>0 and no message there, wait at most that amount of time before giving up.
29 gras_socket_t gras_trp_select(double timeout) {
32 gras_trp_procdata_t pd =
33 (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id);
34 gras_trp_sg_sock_data_t *sockdata;
35 gras_trp_plugin_t trp;
37 gras_socket_t sock_iter; /* iterating over all sockets */
40 gras_sg_portrec_t pr; /* iterating to find the chanel of expeditor */
43 gras_hostdata_t *remote_hd;
45 DEBUG3("select on %s@%s with timeout=%f",
46 MSG_process_get_name(MSG_process_self()),
47 MSG_host_get_name(MSG_host_self()),
50 MSG_channel_select_from((m_channel_t) pd->chan, timeout, &r_pid);
54 THROW0(timeout_error,0,"Timeout");
57 /* Ok, got something. Open a socket back to the expeditor */
59 /* Try to reuse an already openned socket to that expeditor */
60 xbt_dynar_foreach(pd->sockets,cursor,sock_iter) {
61 DEBUG1("Consider %p as outgoing socket to expeditor",sock_iter);
63 if (sock_iter->meas || !sock_iter->outgoing)
66 sockdata = sock_iter->data;
67 if (sockdata->to_PID == r_pid) {
72 /* Socket to expeditor not created yet */
73 DEBUG0("Create a socket to the expeditor");
75 trp = gras_trp_plugin_get_by_name("sg");
77 gras_trp_socket_new(1,&res);
87 sockdata = xbt_new(gras_trp_sg_sock_data_t,1);
88 sockdata->from_PID = MSG_process_self_PID();
89 sockdata->to_PID = r_pid;
90 sockdata->to_host = MSG_process_get_host(MSG_process_from_PID(r_pid));
92 gras_trp_buf_init_sock(res);
94 res->peer_name = strdup(MSG_host_get_name(sockdata->to_host));
96 remote_hd=(gras_hostdata_t *)MSG_host_get_data(sockdata->to_host);
97 xbt_assert0(remote_hd,"Run gras_process_init!!");
99 sockdata->to_chan = -1;
100 res->peer_port = -10;
101 for (cursor=0; cursor<XBT_MAX_CHANNEL; cursor++) {
102 if (remote_hd->proc[cursor] == r_pid) {
103 sockdata->to_chan = cursor;
104 DEBUG2("Chan %d on %s is for my pal",
105 cursor,res->peer_name);
107 xbt_dynar_foreach(remote_hd->ports, cpt, pr) {
108 if (sockdata->to_chan == pr.tochan) {
110 DEBUG0("Damn, it's for measurement");
114 res->peer_port = pr.port;
115 DEBUG1("Cool, it points to port %d", pr.port);
118 DEBUG2("Wrong port (tochan=%d, looking for %d)\n",
119 pr.tochan,sockdata->to_chan);
122 if (res->peer_port == -10) {
123 /* was for measurement */
124 sockdata->to_chan = -1;
126 /* found it, don't let it override by meas */
131 xbt_assert0(sockdata->to_chan != -1,
132 "Got a message from a process without channel");
138 /* dummy implementations of the functions used in RL mode */
140 void gras_trp_tcp_setup(gras_trp_plugin_t plug) { THROW0(mismatch_error,0,NULL); }
141 void gras_trp_file_setup(gras_trp_plugin_t plug){ THROW0(mismatch_error,0,NULL); }
142 void gras_trp_iov_setup(gras_trp_plugin_t plug) { THROW0(mismatch_error,0,NULL); }
144 gras_socket_t gras_trp_buf_init_sock(gras_socket_t sock) { return sock;}