1 /* sg_transport - SG specific functions for transport */
3 /* Copyright (c) 2004, 2005, 2006, 2007, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "gras/Transport/transport_private.h"
11 #include "gras/Virtu/virtu_sg.h"
13 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_trp);
15 /* check transport_private.h for an explanation of this variable;
16 * this just need to be defined to NULL in SG */
17 gras_socket_t _gras_lastly_selected_socket = NULL;
23 * Returns the next socket to service having a message awaiting.
25 * if timeout<0, we ought to implement the adaptative timeout (FIXME)
27 * if timeout=0, do not wait for new message, only handle the ones already there.
29 * if timeout>0 and no message there, wait at most that amount of time before giving up.
31 gras_socket_t gras_trp_select(double timeout)
34 gras_trp_procdata_t pd =
35 (gras_trp_procdata_t) gras_libdata_by_id(gras_trp_libdata_id);
36 gras_trp_sg_sock_data_t *sockdata;
37 gras_trp_plugin_t trp;
38 gras_socket_t active_socket = NULL;
39 gras_trp_sg_sock_data_t *active_socket_data;
40 gras_socket_t sock_iter; /* iterating over all sockets */
43 XBT_DEBUG("select on %s@%s with timeout=%f",
44 SIMIX_process_self_get_name(),
45 SIMIX_host_self_get_name(), timeout);
47 xbt_queue_shift_timed(pd->msg_selectable_sockets,
48 &active_socket, timeout);
50 xbt_queue_shift(pd->msg_selectable_sockets, &active_socket);
53 if (active_socket == NULL) {
55 THROWF(timeout_error, 0, "Timeout");
57 active_socket_data = (gras_trp_sg_sock_data_t *) active_socket->data;
59 /* Ok, got something. Open a socket back to the expeditor */
61 /* Try to reuse an already openned socket to that expeditor */
62 XBT_DEBUG("Open sockets size %lu", xbt_dynar_length(pd->sockets));
63 xbt_dynar_foreach(pd->sockets, cursor, sock_iter) {
64 gras_trp_sg_sock_data_t *sock_data;
65 XBT_DEBUG("Consider %p as outgoing socket to expeditor", sock_iter);
67 if (sock_iter->meas || !sock_iter->outgoing)
69 sock_data = ((gras_trp_sg_sock_data_t *) sock_iter->data);
71 if ((sock_data->to_socket == active_socket) &&
72 (sock_data->to_host ==
73 SIMIX_req_process_get_host(active_socket_data->from_process))) {
74 xbt_dynar_cursor_unlock(pd->sockets);
79 /* Socket to expeditor not created yet */
80 XBT_DEBUG("Create a socket to the expeditor");
82 trp = gras_trp_plugin_get_by_name("sg");
84 gras_trp_socket_new(1, &res);
94 /* initialize the ports */
95 //res->peer_port = active_socket->port;
96 res->port = active_socket->peer_port;
99 sockdata = xbt_new(gras_trp_sg_sock_data_t, 1);
100 sockdata->from_process = SIMIX_process_self();
101 sockdata->to_process = active_socket_data->from_process;
103 res->peer_port = ((gras_trp_procdata_t)
104 gras_libdata_by_name_from_remote("gras_trp",
105 sockdata->to_process))->
107 sockdata->to_socket = active_socket;
108 /*update the peer to_socket variable */
109 active_socket_data->to_socket = res;
110 sockdata->cond = SIMIX_req_cond_init();
111 sockdata->mutex = SIMIX_req_mutex_init();
114 SIMIX_req_process_get_host(active_socket_data->from_process);
116 res->data = sockdata;
117 res->peer_name = strdup(SIMIX_req_host_get_name(sockdata->to_host));
119 gras_trp_buf_init_sock(res);
121 XBT_DEBUG("Create socket to process:%s(Port %d) from process: %s(Port %d)",
122 SIMIX_req_process_get_name(sockdata->from_process),
124 SIMIX_req_process_get_name(sockdata->to_process), res->port);
130 /* dummy implementations of the functions used in RL mode */
132 void gras_trp_tcp_setup(gras_trp_plugin_t plug)
134 THROW(mismatch_error, 0);
137 void gras_trp_file_setup(gras_trp_plugin_t plug)
139 THROW(mismatch_error, 0);
142 void gras_trp_iov_setup(gras_trp_plugin_t plug)
144 THROW(mismatch_error, 0);
147 gras_socket_t gras_trp_buf_init_sock(gras_socket_t sock)