3 /* sg_transport - SG specific functions for transport */
5 /* Authors: Martin Quinson */
6 /* Copyright (C) 2004 Martin Quinson. */
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. */
11 #include "Transport/transport_private.h"
13 #include "Virtu/virtu_sg.h"
15 GRAS_LOG_EXTERNAL_CATEGORY(transport);
16 GRAS_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.
30 gras_trp_select(double timeout,
31 gras_socket_t **dst) {
34 double startTime=gras_time();
35 gras_procdata_t *pd=gras_procdata_get();
36 gras_trp_sg_sock_data_t *sockdata;
37 gras_trp_plugin_t *trp;
39 gras_socket_t *sock_iter; /* iterating over all sockets */
40 int cursor; /* iterating over all sockets */
43 gras_hostdata_t *remote_hd;
45 DEBUG1("select with timeout=%d",timeout);
47 r_pid = MSG_task_probe_from((m_channel_t) pd->chan);
49 /* Try to reuse an already openned socket to that expeditor */
50 gras_dynar_foreach(pd->sockets,cursor,sock_iter) {
51 DEBUG1("Consider %p as outgoing socket to expeditor",sock_iter);
52 sockdata = sock_iter->data;
54 if (sock_iter->raw || !sock_iter->outgoing)
57 if (sockdata->from_PID == r_pid) {
63 /* Socket to expeditor not created yet */
64 DEBUG0("Create a socket to the expeditor");
66 TRY(gras_trp_plugin_get_by_name("sg",&trp));
68 TRY(gras_trp_socket_new(1,dst));
73 (*dst)->accepting = 0;
78 if (!(sockdata = malloc(sizeof(gras_trp_sg_sock_data_t))))
81 sockdata->from_PID = r_pid;
82 sockdata->to_PID = MSG_process_self_PID();
83 sockdata->to_host = MSG_process_get_host(MSG_process_from_PID(r_pid));
84 (*dst)->data = sockdata;
86 (*dst)->peer_port = -1;
87 (*dst)->peer_name = strdup(MSG_host_get_name(sockdata->to_host));
89 remote_hd=(gras_hostdata_t *)MSG_host_get_data(sockdata->to_host);
90 gras_assert0(remote_hd,"Run gras_process_init!!");
92 sockdata->to_chan = -1;
93 for (cpt=0; cpt< GRAS_MAX_CHANNEL; cpt++)
94 if (r_pid == remote_hd->proc[cpt])
95 sockdata->to_chan = cpt;
97 gras_assert0(sockdata->to_chan>0,
98 "Got a message from a process without channel");
102 MSG_process_sleep(0.01);
104 } while (gras_time()-startTime < timeout
105 || MSG_task_Iprobe((m_channel_t) pd->chan));
107 return timeout_error;
112 /* dummy implementations of the functions used in RL mode */
114 gras_error_t gras_trp_tcp_setup(gras_trp_plugin_t *plug) {
115 return mismatch_error;
117 gras_error_t gras_trp_file_setup(gras_trp_plugin_t *plug) {
118 return mismatch_error;