- errcode = gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
-
- xbt_dict_free(&refs);
- gras_cbps_free(&state);
-
- return errcode;
-}
-
-/**
- * gras_datadesc_recv_rec:
- *
- * Do the data reception job recursively.
- *
- * subsize used only to deal with vicious case of reference to dynamic array.
- * This size is needed at the reference reception level (to allocate enough
- * space) and at the array reception level (to fill enough room).
- *
- * Having this size passed as an argument of the recursive function is a crude
- * hack, but I was told that working code is sometimes better than neat one ;)
- */
-static xbt_error_t
-gras_datadesc_recv_rec(gras_socket_t sock,
- gras_cbps_t state,
- xbt_dict_t refs,
- gras_datadesc_type_t type,
- int r_arch,
- char **r_data,
- long int r_lgr,
- char *l_data,
- int subsize,
- int detect_cycle) {
-
- xbt_error_t errcode;
- int cpt;
- gras_datadesc_type_t sub_type;
-
- VERB2("Recv a %s @%p", type->name, (void*)l_data);
- xbt_assert(l_data);
-
- switch (type->category_code) {
- case e_gras_datadesc_type_cat_scalar:
- if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
- TRY(gras_trp_chunk_recv(sock, (char*)l_data, type->size[r_arch]));
- if (r_arch != GRAS_THISARCH)
- TRY(gras_dd_convert_elm(type,1,r_arch, l_data,l_data));
- } else {
- void *ptr = xbt_malloc(type->size[r_arch]);
-
- TRY(gras_trp_chunk_recv(sock, (char*)ptr, type->size[r_arch]));
- if (r_arch != GRAS_THISARCH)
- TRY(gras_dd_convert_elm(type,1,r_arch, ptr,l_data));
- free(ptr);
- }
- break;
-
- case e_gras_datadesc_type_cat_struct: {
- gras_dd_cat_struct_t struct_data;
- gras_dd_cat_field_t field;
-
- struct_data = type->category.struct_data;
-
- xbt_assert1(struct_data.closed,
- "Please call gras_datadesc_declare_struct_close on %s before receiving it",
- type->name);
- VERB1(">> Receive all fields of the structure %s",type->name);
- xbt_dynar_foreach(struct_data.fields, cpt, field) {
- char *field_data = l_data + field->offset[GRAS_THISARCH];
-
- sub_type = field->type;
-
- TRY(gras_datadesc_recv_rec(sock,state,refs, sub_type,
- r_arch,NULL,0,
- field_data,-1,
- detect_cycle || sub_type->cycle));
- }
- VERB1("<< Received all fields of the structure %s", type->name);
-
- break;
- }
-
- case e_gras_datadesc_type_cat_union: {
- gras_dd_cat_union_t union_data;
- gras_dd_cat_field_t field=NULL;
- int field_num;
-
- union_data = type->category.union_data;
-
- xbt_assert1(union_data.closed,
- "Please call gras_datadesc_declare_union_close on %s before receiving it",
- type->name);
- /* retrieve the field number */
- TRY(gras_dd_recv_int(sock, r_arch, &field_num));
- if (field_num < 0)
- RAISE1(mismatch_error,
- "Received union field for %s is negative", type->name);
- if (field_num < xbt_dynar_length(union_data.fields))
- RAISE3(mismatch_error,
- "Received union field for %s is %d but there is only %lu fields",
- type->name, field_num, xbt_dynar_length(union_data.fields));
-
- /* Recv the content */
- field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
- sub_type = field->type;
-
- TRY(gras_datadesc_recv_rec(sock,state,refs, sub_type,
- r_arch,NULL,0,
- l_data,-1,
- detect_cycle || sub_type->cycle));
- break;
- }
-
- case e_gras_datadesc_type_cat_ref: {
- char **r_ref = NULL;
- char **l_ref = NULL;
- gras_dd_cat_ref_t ref_data;
-
- ref_data = type->category.ref_data;
-
- /* Get the referenced type locally or from peer */
- sub_type = ref_data.type;
- if (sub_type == NULL) {
- int ref_code;
- TRY(gras_dd_recv_int(sock, r_arch, &ref_code));
- TRY(gras_datadesc_by_id(ref_code, &sub_type));
- }
-
- /* Get the actual value of the pointer for cycle handling */
- if (!pointer_type) {
- pointer_type = gras_datadesc_by_name("data pointer");
- xbt_assert(pointer_type);
- }
-
- r_ref = xbt_malloc(pointer_type->size[r_arch]);
-
- TRY(gras_trp_chunk_recv(sock, (char*)r_ref,
- pointer_type->size[r_arch]));
-
- /* Receive the pointed data only if not already sent */
- if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
- VERB1("Not receiving data remotely referenced @%p since it's NULL",
- *(void **)r_ref);
- *(void**)l_data = NULL;
- free(r_ref);
- break;
- }
-
- errcode = detect_cycle
- ? xbt_dict_get_ext(refs,
- (char*)r_ref, pointer_type->size[r_arch],
- (void**)&l_ref)
- : mismatch_error;
-
- if (errcode == mismatch_error) {
- int subsubcount = 0;
- void *l_referenced=NULL;
-
- VERB2("Receiving a ref to '%s', remotely @%p",
- sub_type->name, *(void**)r_ref);
- if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
- /* Damn. Reference to a dynamic array. Allocating the size for it
- is more complicated */
- gras_dd_cat_array_t array_data = sub_type->category.array_data;
- gras_datadesc_type_t subsub_type;