-
-/** \brief Send the data pointed by \a payload as a message of type
- * \a msgtype to the peer \a sock */
-xbt_error_t
-gras_msg_send(gras_socket_t sock,
- gras_msgtype_t msgtype,
- void *payload) {
-
- xbt_error_t errcode;
- static gras_datadesc_type_t string_type=NULL;
-
- if (!msgtype)
- RAISE0(mismatch_error,
- "Cannot send the NULL message (did msgtype_by_name fail?)");
-
- if (!string_type) {
- string_type = gras_datadesc_by_name("string");
- xbt_assert(string_type);
- }
-
- DEBUG3("send '%s' to %s:%d", msgtype->name,
- gras_socket_peer_name(sock),gras_socket_peer_port(sock));
- TRY(gras_trp_chunk_send(sock, GRAS_header, 6));
-
- TRY(gras_datadesc_send(sock, string_type, &msgtype->name));
- TRY(gras_datadesc_send(sock, msgtype->ctn_type, payload));
- TRY(gras_trp_flush(sock));
-
- return no_error;
-}
-/*
- * receive the next message on the given socket.
- */
-xbt_error_t
-gras_msg_recv(gras_socket_t sock,
- gras_msgtype_t *msgtype,
- void **payload,
- int *payload_size) {
-
- xbt_error_t errcode;
- static gras_datadesc_type_t string_type=NULL;
- char header[6];
- int cpt;
- int r_arch;
- char *msg_name=NULL;
-
- if (!string_type) {
- string_type=gras_datadesc_by_name("string");
- xbt_assert(string_type);
- }
-
- TRY(gras_trp_chunk_recv(sock, header, 6));
- for (cpt=0; cpt<4; cpt++)
- if (header[cpt] != GRAS_header[cpt])
- RAISE2(mismatch_error,"Incoming bytes do not look like a GRAS message (header='%.4s' not '%.4s')",header,GRAS_header);
- if (header[4] != GRAS_header[4])
- RAISE2(mismatch_error,"GRAS protocol mismatch (got %d, use %d)",
- (int)header[4], (int)GRAS_header[4]);
- r_arch = (int)header[5];
- DEBUG2("Handle an incoming message using protocol %d (remote is %s)",
- (int)header[4],gras_datadesc_arch_name(r_arch));
-
- TRY(gras_datadesc_recv(sock, string_type, r_arch, &msg_name));
- errcode = xbt_set_get_by_name(_gras_msgtype_set,
- msg_name,(xbt_set_elm_t*)msgtype);
- if (errcode != no_error)
- RAISE2(errcode,
- "Got error %s while retrieving the type associated to messages '%s'",
- xbt_error_name(errcode),msg_name);
- /* FIXME: Survive unknown messages */
- free(msg_name);
-
- *payload_size=gras_datadesc_size((*msgtype)->ctn_type);
- xbt_assert2(*payload_size > 0,
- "%s %s",
- "Dynamic array as payload is forbided for now (FIXME?).",
- "Reference to dynamic array is allowed.");
- *payload = xbt_malloc(*payload_size);
- TRY(gras_datadesc_recv(sock, (*msgtype)->ctn_type, r_arch, *payload));
-
- return no_error;