+void gras_trp_sg_socket_client(gras_trp_plugin_t self,
+ const char*host,
+ int port,
+ /* OUT */ gras_socket_t sock)
+{
+
+ smx_host_t peer;
+ gras_hostdata_t *hd;
+ gras_trp_sg_sock_data_t data;
+ gras_sg_portrec_t pr;
+
+ /* make sure this socket will reach someone */
+ if (!(peer = SIMIX_req_host_get_by_name(host)))
+ THROW1(mismatch_error, 0,
+ "Can't connect to %s: no such host.\n", host);
+
+ if (!(hd = (gras_hostdata_t *) SIMIX_req_host_get_data(peer)))
+ THROW1(mismatch_error, 0,
+ "can't connect to %s: no process on this host",
+ host);
+
+ pr = find_port(hd, port);
+
+ if (pr == NULL) {
+ THROW2(mismatch_error, 0,
+ "can't connect to %s:%d, no process listen on this port",
+ host, port);
+ }
+
+ /* Ensure that the listener is expecting the kind of stuff we want to send */
+ if (pr->meas && !sock->meas) {
+ THROW2(mismatch_error, 0,
+ "can't connect to %s:%d in regular mode, the process listen "
+ "in measurement mode on this port", host,
+ port);
+ }
+ if (!pr->meas && sock->meas) {
+ THROW2(mismatch_error, 0,
+ "can't connect to %s:%d in measurement mode, the process listen "
+ "in regular mode on this port", host,
+ port);
+ }
+
+ /* create simulation data of the socket */
+ data = xbt_new0(s_gras_trp_sg_sock_data_t, 1);
+ data->client = SIMIX_process_self();
+ data->server = pr->server;
+ data->server_port = port;
+ data->client_port = gras_os_myport();
+
+ /* initialize synchronization stuff on the socket */
+ data->rdv_server = pr->rdv;
+ data->rdv_client = SIMIX_req_rdv_create(NULL);
+ data->comm_recv = SIMIX_req_comm_irecv(data->rdv_client, &data->msg, NULL, NULL, NULL);
+
+ /* connect that simulation data to the socket */
+ sock->data = data;
+ sock->incoming = 1;
+
+ XBT_DEBUG("%s (PID %d) connects in %s mode to %s:%d (rdv_ser:%p, rdv_cli:%p, comm:%p)",
+ SIMIX_req_process_get_name(SIMIX_process_self()), gras_os_getpid(),
+ sock->meas ? "meas" : "regular", host, port,
+ data->rdv_server,data->rdv_client,data->comm_recv);