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_simix/Transport/gras_simix_transport_private.h"
12 //#include "msg/msg.h"
13 #include "gras_simix/Virtu/gras_simix_virtu_sg.h"
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_trp);
17 /* check transport_private.h for an explanation of this variable; this just need to be defined to NULL in SG */
18 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) {
33 gras_trp_procdata_t pd = (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;
36 gras_socket_t active_socket;
37 gras_socket_t sock_iter; /* iterating over all sockets */
40 DEBUG0("Trying to get the lock pd, trp_select");
41 SIMIX_mutex_lock(pd->mutex);
42 DEBUG3("select on %s@%s with timeout=%f",
43 SIMIX_process_get_name(SIMIX_process_self()),
44 SIMIX_host_get_name(SIMIX_host_self()),
47 if (xbt_fifo_size(pd->active_socket) == 0) {
48 /* message didn't arrive yet, wait */
49 SIMIX_cond_wait_timeout(pd->cond,pd->mutex,timeout);
52 if (xbt_fifo_size(pd->active_socket) == 0) {
54 SIMIX_mutex_unlock(pd->mutex);
55 THROW0(timeout_error,0,"Timeout");
57 active_socket = xbt_fifo_shift(pd->active_socket);
59 /* Ok, got something. Open a socket back to the expeditor */
61 /* Try to reuse an already openned socket to that expeditor */
62 DEBUG1("Open sockets size %lu",xbt_dynar_length(pd->sockets));
63 xbt_dynar_foreach(pd->sockets,cursor,sock_iter) {
64 DEBUG1("Consider %p as outgoing socket to expeditor",sock_iter);
66 if (sock_iter->meas || !sock_iter->outgoing)
68 if ((sock_iter->peer_port == active_socket->port) &&
69 (((gras_trp_sg_sock_data_t*)sock_iter->data)->to_host == SIMIX_process_get_host(((gras_trp_sg_sock_data_t*)active_socket->data)->from_process))) {
70 SIMIX_mutex_unlock(pd->mutex);
75 /* Socket to expeditor not created yet */
76 DEBUG0("Create a socket to the expeditor");
78 trp = gras_trp_plugin_get_by_name("sg");
80 gras_trp_socket_new(1,&res);
90 /* unitialize the ports */
91 res->peer_port = active_socket->port;
92 res->port = active_socket->peer_port;
95 sockdata = xbt_new(gras_trp_sg_sock_data_t,1);
96 sockdata->from_process = SIMIX_process_self();
97 sockdata->to_process = ((gras_trp_sg_sock_data_t*)(active_socket->data))->from_process;
99 sockdata->to_host = SIMIX_process_get_host(((gras_trp_sg_sock_data_t*)(active_socket->data))->from_process);
101 res->data = sockdata;
102 res->peer_name = strdup(SIMIX_host_get_name(sockdata->to_host));
104 gras_trp_buf_init_sock(res);
106 DEBUG4("Create socket to process:%s(Port %d) from process: %s(Port %d)",SIMIX_process_get_name(sockdata->from_process),res->peer_port, SIMIX_process_get_name(sockdata->to_process), res->port);
108 SIMIX_mutex_unlock(pd->mutex);
113 /* dummy implementations of the functions used in RL mode */
115 void gras_trp_tcp_setup(gras_trp_plugin_t plug) { THROW0(mismatch_error,0,NULL); }
116 void gras_trp_file_setup(gras_trp_plugin_t plug){ THROW0(mismatch_error,0,NULL); }
117 void gras_trp_iov_setup(gras_trp_plugin_t plug) { THROW0(mismatch_error,0,NULL); }
119 gras_socket_t gras_trp_buf_init_sock(gras_socket_t sock) { return sock;}