3 /* ddt_exchange - send/recv data described */
5 /* Copyright (c) 2003 Olivier Aumage. */
6 /* Copyright (c) 2003, 2004, 2005 Martin Quinson. */
7 /* All rights reserved. */
9 /* This program is free software; you can redistribute it and/or modify it
10 * under the terms of the license (GNU LGPL) which comes with this package. */
13 #include "gras/DataDesc/datadesc_private.h"
14 #include "gras/Transport/transport_interface.h" /* gras_trp_chunk_send/recv */
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(ddt_exchange,datadesc,
17 "Sending data over the network");
18 const char *gras_datadesc_cat_names[9] = {
20 "scalar", "struct", "union", "ref", "array", "ignored",
23 static gras_datadesc_type_t int_type = NULL;
24 static gras_datadesc_type_t pointer_type = NULL;
25 static _XBT_INLINE void gras_dd_send_int(gras_socket_t sock, int i);
26 static _XBT_INLINE void gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i);
28 static _XBT_INLINE void
29 gras_dd_alloc_ref(xbt_dict_t refs, long int size,
30 char **r_ref, long int r_len,
31 char **l_ref, int detect_cycle);
33 static _XBT_INLINE int
34 gras_dd_is_r_null(char **r_ptr, long int length);
36 static _XBT_INLINE void
37 gras_dd_send_int(gras_socket_t sock,int i) {
40 int_type = gras_datadesc_by_name("int");
44 DEBUG1("send_int(%d)",i);
45 gras_trp_chunk_send(sock, (char*)&i, int_type->size[GRAS_THISARCH]);
48 static _XBT_INLINE void
49 gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) {
52 int_type = gras_datadesc_by_name("int");
56 if (int_type->size[GRAS_THISARCH] >= int_type->size[r_arch]) {
57 gras_trp_chunk_recv(sock, (char*)i, int_type->size[r_arch]);
58 if (r_arch != GRAS_THISARCH)
59 gras_dd_convert_elm(int_type,1,r_arch, i,i);
61 void *ptr = xbt_malloc(int_type->size[r_arch]);
63 gras_trp_chunk_recv(sock, (char*)ptr, int_type->size[r_arch]);
64 if (r_arch != GRAS_THISARCH)
65 gras_dd_convert_elm(int_type,1,r_arch, ptr,i);
68 DEBUG1("recv_int(%d)",*i);
72 * Note: here we suppose that the remote NULL is a sequence
73 * of 'length' bytes set to 0.
74 * FIXME: Check in configure?
76 static _XBT_INLINE int
77 gras_dd_is_r_null(char **r_ptr, long int length) {
80 for (i=0; i<length; i++) {
81 if ( ((unsigned char*)r_ptr) [i]) {
89 static _XBT_INLINE void
90 gras_dd_alloc_ref(xbt_dict_t refs,
93 long int r_len, /* pointer_type->size[r_arch] */
98 xbt_assert1(size>0,"Cannot allocate %ld bytes!", size);
99 l_data = xbt_malloc((size_t)size);
102 DEBUG5("alloc_ref: l_data=%p, &l_data=%p; r_ref=%p; *r_ref=%p, r_len=%ld",
103 (void*)l_data,(void*)&l_data,
104 (void*)r_ref, (void*)(r_ref?*r_ref:NULL), r_len);
105 if (detect_cycle && r_ref && !gras_dd_is_r_null( r_ref, r_len)) {
106 void *ptr = xbt_malloc(sizeof(void *));
108 CRITICAL0("Check for cycles");
109 memcpy(ptr,l_ref, sizeof(void *));
111 DEBUG2("Insert l_ref=%p under r_ref=%p",*(void**)ptr, *(void**)r_ref);
114 xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, free);
119 gras_datadesc_copy_rec(gras_cbps_t state,
121 gras_datadesc_type_t type,
130 gras_datadesc_type_t sub_type; /* type on which we recurse */
133 VERB4("Copy a %s (%s) from %p to %p",
134 type->name, gras_datadesc_cat_names[type->category_code],
138 type->send(type,state,src);
141 switch (type->category_code) {
142 case e_gras_datadesc_type_cat_scalar:
143 memcpy(dst,src,type->size[GRAS_THISARCH]);
144 count += type->size[GRAS_THISARCH];
147 case e_gras_datadesc_type_cat_struct: {
148 gras_dd_cat_struct_t struct_data;
149 gras_dd_cat_field_t field;
153 struct_data = type->category.struct_data;
154 xbt_assert1(struct_data.closed,
155 "Please call gras_datadesc_declare_struct_close on %s before copying it",
157 VERB1(">> Copy all fields of the structure %s",type->name);
158 xbt_dynar_foreach(struct_data.fields, cpt, field) {
159 field_src = src + field->offset[GRAS_THISARCH];
160 field_dst = dst + field->offset[GRAS_THISARCH];
162 sub_type = field->type;
165 field->send(type,state,field_src);
167 VERB1("Copy field %s",field->name);
168 count += gras_datadesc_copy_rec(state,refs,sub_type, field_src, field_dst, 0,
169 detect_cycle || sub_type->cycle);
172 VERB1("<< Copied all fields of the structure %s", type->name);
177 case e_gras_datadesc_type_cat_union: {
178 gras_dd_cat_union_t union_data;
179 gras_dd_cat_field_t field=NULL;
182 union_data = type->category.union_data;
184 xbt_assert1(union_data.closed,
185 "Please call gras_datadesc_declare_union_close on %s before copying it",
187 /* retrieve the field number */
188 field_num = union_data.selector(type, state, src);
190 xbt_assert1(field_num > 0,
191 "union field selector of %s gave a negative value",
194 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
195 "union field selector of %s returned %d but there is only %lu fields",
196 type->name, field_num, xbt_dynar_length(union_data.fields));
198 /* Copy the content */
199 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
200 sub_type = field->type;
203 field->send(type,state,src);
205 count += gras_datadesc_copy_rec(state,refs, sub_type, src, dst,0,
206 detect_cycle || sub_type->cycle);
211 case e_gras_datadesc_type_cat_ref: {
212 gras_dd_cat_ref_t ref_data;
215 int reference_is_to_cpy;
217 ref_data = type->category.ref_data;
219 /* Detect the referenced type */
220 sub_type = ref_data.type;
221 if (sub_type == NULL) {
222 sub_type = (*ref_data.selector)(type,state,src);
225 /* Send the pointed data only if not already sent */
226 if (*(void**)src == NULL) {
227 VERB0("Not copying NULL referenced data");
233 reference_is_to_cpy = 0;
236 /* return ignored. Just checking whether it's known or not */
237 n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*));
239 reference_is_to_cpy = 1;
241 if (e.category != not_found_error)
243 reference_is_to_cpy = 1;
247 if (reference_is_to_cpy) {
249 void *l_referenced=NULL;
250 VERB2("Copy a ref to '%s' referenced at %p",sub_type->name, (void*)*o_ref);
253 pointer_type = gras_datadesc_by_name("data pointer");
254 xbt_assert(pointer_type);
257 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
258 /* Damn. Reference to a dynamic array. Allocating the space for it
259 is more complicated */
260 gras_dd_cat_array_t array_data = sub_type->category.array_data;
261 gras_datadesc_type_t subsub_type;
263 subsub_type = array_data.type;
264 subsubcount = array_data.fixed_size;
265 if (subsubcount == 0)
266 subsubcount = array_data.dynamic_size(subsub_type,state,*o_ref);
268 gras_dd_alloc_ref(refs,
269 subsub_type->size[GRAS_THISARCH] * subsubcount,
270 o_ref,pointer_type->size[GRAS_THISARCH],
271 (char**)&l_referenced,
274 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
275 o_ref,pointer_type->size[GRAS_THISARCH],
276 (char**)&l_referenced,
280 count += gras_datadesc_copy_rec(state,refs, sub_type,
281 *o_ref,(char*)l_referenced, subsubcount,
282 detect_cycle || sub_type->cycle);
284 *(void**)dst=l_referenced;
285 VERB3("'%s' previously referenced at %p now at %p",
286 sub_type->name, *(void**)o_ref, l_referenced);
289 VERB2("NOT copying data previously referenced @%p (already done, @%p now)",
290 *(void**)o_ref, *(void**)n_ref);
298 case e_gras_datadesc_type_cat_array: {
299 gras_dd_cat_array_t array_data;
305 array_data = type->category.array_data;
307 /* determine and send the element count */
308 count = array_data.fixed_size;
312 count = array_data.dynamic_size(type,state,src);
313 xbt_assert1(count >=0,
314 "Invalid (negative) array size for type %s",type->name);
317 /* send the content */
318 sub_type = array_data.type;
319 elm_size = sub_type->aligned_size[GRAS_THISARCH];
320 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
321 VERB1("Array of %ld scalars, copy it in one shot",count);
322 memcpy(dst, src, sub_type->aligned_size[GRAS_THISARCH] * count);
323 count += sub_type->aligned_size[GRAS_THISARCH] * count;
324 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
325 sub_type->category.array_data.fixed_size > 0 &&
326 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
328 VERB1("Array of %ld fixed array of scalars, copy it in one shot",count);
329 memcpy(dst,src,sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
330 * count * sub_type->category.array_data.fixed_size);
331 count += sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
332 * count * sub_type->category.array_data.fixed_size;
335 for (cpt=0; cpt<count; cpt++) {
336 count += gras_datadesc_copy_rec(state,refs, sub_type, src_ptr, dst_ptr, 0,
337 detect_cycle || sub_type->cycle);
346 xbt_assert0(0, "Invalid type");
351 * gras_datadesc_copy:
353 * Copy the data pointed by src and described by type
354 * to a new location, and store a pointer to it in dst.
357 int gras_datadesc_copy(gras_datadesc_type_t type,
358 void *src, void *dst) {
361 xbt_dict_t refs; /* all references already sent */
364 xbt_assert0(type,"called with NULL type descriptor");
366 refs = xbt_dict_new();
367 state = gras_cbps_new();
370 size = gras_datadesc_copy_rec(state,refs,type,(char*)src,(char*)dst,0,
373 xbt_dict_free(&refs);
374 gras_cbps_free(&state);
382 *** Direct use functions
386 gras_datadesc_send_rec(gras_socket_t sock,
389 gras_datadesc_type_t type,
395 gras_datadesc_type_t sub_type; /* type on which we recurse */
397 VERB2("Send a %s (%s)",
398 type->name, gras_datadesc_cat_names[type->category_code]);
401 type->send(type,state,data);
404 switch (type->category_code) {
405 case e_gras_datadesc_type_cat_scalar:
406 gras_trp_chunk_send(sock, data, type->size[GRAS_THISARCH]);
409 case e_gras_datadesc_type_cat_struct: {
410 gras_dd_cat_struct_t struct_data;
411 gras_dd_cat_field_t field;
414 struct_data = type->category.struct_data;
415 xbt_assert1(struct_data.closed,
416 "Please call gras_datadesc_declare_struct_close on %s before sending it",
418 VERB1(">> Send all fields of the structure %s",type->name);
419 xbt_dynar_foreach(struct_data.fields, cpt, field) {
421 field_data += field->offset[GRAS_THISARCH];
423 sub_type = field->type;
426 field->send(type,state,field_data);
428 VERB1("Send field %s",field->name);
429 gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
430 detect_cycle || sub_type->cycle);
433 VERB1("<< Sent all fields of the structure %s", type->name);
438 case e_gras_datadesc_type_cat_union: {
439 gras_dd_cat_union_t union_data;
440 gras_dd_cat_field_t field=NULL;
443 union_data = type->category.union_data;
445 xbt_assert1(union_data.closed,
446 "Please call gras_datadesc_declare_union_close on %s before sending it",
448 /* retrieve the field number */
449 field_num = union_data.selector(type, state, data);
451 xbt_assert1(field_num > 0,
452 "union field selector of %s gave a negative value",
455 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
456 "union field selector of %s returned %d but there is only %lu fields",
457 type->name, field_num, xbt_dynar_length(union_data.fields));
459 /* Send the field number */
460 gras_dd_send_int(sock, field_num);
462 /* Send the content */
463 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
464 sub_type = field->type;
467 field->send(type,state,data);
469 gras_datadesc_send_rec(sock,state,refs, sub_type, data,
470 detect_cycle || sub_type->cycle);
475 case e_gras_datadesc_type_cat_ref: {
476 gras_dd_cat_ref_t ref_data;
477 void **ref=(void**)data;
478 int reference_is_to_send;
480 ref_data = type->category.ref_data;
482 /* Detect the referenced type and send it to peer if needed */
483 sub_type = ref_data.type;
484 if (sub_type == NULL) {
485 sub_type = (*ref_data.selector)(type,state,data);
486 gras_dd_send_int(sock, sub_type->code);
489 /* Send the actual value of the pointer for cycle handling */
491 pointer_type = gras_datadesc_by_name("data pointer");
492 xbt_assert(pointer_type);
495 gras_trp_chunk_send(sock, (char*)data,
496 pointer_type->size[GRAS_THISARCH]);
498 /* Send the pointed data only if not already sent */
499 if (*(void**)data == NULL) {
500 VERB0("Not sending NULL referenced data");
504 reference_is_to_send = 0;
507 /* return ignored. Just checking whether it's known or not */
508 xbt_dict_get_ext(refs,(char*)ref, sizeof(char*));
510 reference_is_to_send = 1;
512 if (e.category != not_found_error)
514 reference_is_to_send = 1;
518 if (reference_is_to_send) {
519 VERB1("Sending data referenced at %p", (void*)*ref);
521 xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
522 gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
523 detect_cycle || sub_type->cycle);
526 VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
532 case e_gras_datadesc_type_cat_array: {
533 gras_dd_cat_array_t array_data;
538 array_data = type->category.array_data;
540 /* determine and send the element count */
541 count = array_data.fixed_size;
543 count = array_data.dynamic_size(type,state,data);
544 xbt_assert1(count >=0,
545 "Invalid (negative) array size for type %s",type->name);
546 gras_dd_send_int(sock, count);
549 /* send the content */
550 sub_type = array_data.type;
551 elm_size = sub_type->aligned_size[GRAS_THISARCH];
552 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
553 VERB1("Array of %ld scalars, send it in one shot",count);
554 gras_trp_chunk_send(sock, data,
555 sub_type->aligned_size[GRAS_THISARCH] * count);
556 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
557 sub_type->category.array_data.fixed_size > 0 &&
558 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
560 VERB1("Array of %ld fixed array of scalars, send it in one shot",count);
561 gras_trp_chunk_send(sock, data,
562 sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
563 * count * sub_type->category.array_data.fixed_size);
566 for (cpt=0; cpt<count; cpt++) {
567 gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
568 detect_cycle || sub_type->cycle);
576 xbt_assert0(0, "Invalid type");
581 * gras_datadesc_send:
583 * Copy the data pointed by src and described by type to the socket
586 void gras_datadesc_send(gras_socket_t sock,
587 gras_datadesc_type_t type,
592 xbt_dict_t refs; /* all references already sent */
594 xbt_assert0(type,"called with NULL type descriptor");
596 refs = xbt_dict_new();
597 state = gras_cbps_new();
600 gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
602 xbt_dict_free(&refs);
603 gras_cbps_free(&state);
610 * gras_datadesc_recv_rec:
612 * Do the data reception job recursively.
614 * subsize used only to deal with vicious case of reference to dynamic array.
615 * This size is needed at the reference reception level (to allocate enough
616 * space) and at the array reception level (to fill enough room).
618 * Having this size passed as an argument of the recursive function is a crude
619 * hack, but I was told that working code is sometimes better than neat one ;)
622 gras_datadesc_recv_rec(gras_socket_t sock,
625 gras_datadesc_type_t type,
634 gras_datadesc_type_t sub_type;
637 VERB2("Recv a %s @%p", type->name, (void*)l_data);
640 switch (type->category_code) {
641 case e_gras_datadesc_type_cat_scalar:
642 if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
643 gras_trp_chunk_recv(sock, (char*)l_data, type->size[r_arch]);
644 if (r_arch != GRAS_THISARCH)
645 gras_dd_convert_elm(type,1,r_arch, l_data,l_data);
647 void *ptr = xbt_malloc(type->size[r_arch]);
649 gras_trp_chunk_recv(sock, (char*)ptr, type->size[r_arch]);
650 if (r_arch != GRAS_THISARCH)
651 gras_dd_convert_elm(type,1,r_arch, ptr,l_data);
656 case e_gras_datadesc_type_cat_struct: {
657 gras_dd_cat_struct_t struct_data;
658 gras_dd_cat_field_t field;
660 struct_data = type->category.struct_data;
662 xbt_assert1(struct_data.closed,
663 "Please call gras_datadesc_declare_struct_close on %s before receiving it",
665 VERB1(">> Receive all fields of the structure %s",type->name);
666 xbt_dynar_foreach(struct_data.fields, cpt, field) {
667 char *field_data = l_data + field->offset[GRAS_THISARCH];
669 sub_type = field->type;
671 gras_datadesc_recv_rec(sock,state,refs, sub_type,
674 detect_cycle || sub_type->cycle);
677 field->recv(type,state,(void*)l_data);
680 VERB1("<< Received all fields of the structure %s", type->name);
685 case e_gras_datadesc_type_cat_union: {
686 gras_dd_cat_union_t union_data;
687 gras_dd_cat_field_t field=NULL;
690 union_data = type->category.union_data;
692 xbt_assert1(union_data.closed,
693 "Please call gras_datadesc_declare_union_close on %s before receiving it",
695 /* retrieve the field number */
696 gras_dd_recv_int(sock, r_arch, &field_num);
698 THROW1(mismatch_error,0,
699 "Received union field for %s is negative", type->name);
700 if (field_num > xbt_dynar_length(union_data.fields))
701 THROW3(mismatch_error,0,
702 "Received union field for %s is said to be #%d but there is only %lu fields",
703 type->name, field_num, xbt_dynar_length(union_data.fields));
705 /* Recv the content */
706 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
707 sub_type = field->type;
709 gras_datadesc_recv_rec(sock,state,refs, sub_type,
712 detect_cycle || sub_type->cycle);
714 field->recv(type,state,l_data);
719 case e_gras_datadesc_type_cat_ref: {
722 gras_dd_cat_ref_t ref_data;
723 int reference_is_to_recv = 0;
725 ref_data = type->category.ref_data;
727 /* Get the referenced type locally or from peer */
728 sub_type = ref_data.type;
729 if (sub_type == NULL) {
731 gras_dd_recv_int(sock, r_arch, &ref_code);
732 sub_type = gras_datadesc_by_id(ref_code);
735 /* Get the actual value of the pointer for cycle handling */
737 pointer_type = gras_datadesc_by_name("data pointer");
738 xbt_assert(pointer_type);
741 r_ref = xbt_malloc(pointer_type->size[r_arch]);
743 gras_trp_chunk_recv(sock, (char*)r_ref,
744 pointer_type->size[r_arch]);
746 /* Receive the pointed data only if not already sent */
747 if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
748 VERB1("Not receiving data remotely referenced @%p since it's NULL",
750 *(void**)l_data = NULL;
755 reference_is_to_recv = 0;
758 l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
760 reference_is_to_recv = 1;
762 if (e.category != not_found_error)
764 reference_is_to_recv = 1;
767 if (reference_is_to_recv) {
769 void *l_referenced=NULL;
771 VERB2("Receiving a ref to '%s', remotely @%p",
772 sub_type->name, *(void**)r_ref);
773 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
774 /* Damn. Reference to a dynamic array. Allocating the space for it
775 is more complicated */
776 gras_dd_cat_array_t array_data = sub_type->category.array_data;
777 gras_datadesc_type_t subsub_type;
779 subsubcount = array_data.fixed_size;
780 if (subsubcount == 0)
781 gras_dd_recv_int(sock, r_arch, &subsubcount);
783 subsub_type = array_data.type;
786 gras_dd_alloc_ref(refs,
787 subsub_type->size[GRAS_THISARCH] * subsubcount,
788 r_ref,pointer_type->size[r_arch],
789 (char**)&l_referenced,
792 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
793 r_ref,pointer_type->size[r_arch],
794 (char**)&l_referenced,
798 gras_datadesc_recv_rec(sock,state,refs, sub_type,
799 r_arch,r_ref,pointer_type->size[r_arch],
800 (char*)l_referenced, subsubcount,
801 detect_cycle || sub_type->cycle);
803 *(void**)l_data=l_referenced;
804 VERB3("'%s' remotely referenced at %p locally at %p",
805 sub_type->name, *(void**)r_ref, l_referenced);
808 VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)",
809 *(void**)r_ref, *(void**)l_ref);
811 *(void**)l_data=*l_ref;
818 case e_gras_datadesc_type_cat_array: {
819 gras_dd_cat_array_t array_data;
824 array_data = type->category.array_data;
825 /* determine element count locally, or from caller, or from peer */
826 count = array_data.fixed_size;
830 gras_dd_recv_int(sock, r_arch, &count);
832 THROW1(mismatch_error,0,
833 "Invalid (=0) array size for type %s",type->name);
835 /* receive the content */
836 sub_type = array_data.type;
837 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
838 VERB1("Array of %d scalars, get it in one shoot", count);
839 if (sub_type->aligned_size[GRAS_THISARCH] >=
840 sub_type->aligned_size[r_arch]) {
841 gras_trp_chunk_recv(sock, (char*)l_data,
842 sub_type->aligned_size[r_arch] * count);
843 if (r_arch != GRAS_THISARCH)
844 gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data);
846 ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count);
848 gras_trp_chunk_recv(sock, (char*)ptr,
849 sub_type->size[r_arch] * count);
850 if (r_arch != GRAS_THISARCH)
851 gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data);
854 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
855 sub_type->category.array_data.fixed_size > 0 &&
856 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
857 gras_datadesc_type_t subsub_type;
858 array_data = sub_type->category.array_data;
859 subsub_type = array_data.type;
861 VERB1("Array of %d fixed array of scalars, get it in one shot",count);
862 if (subsub_type->aligned_size[GRAS_THISARCH] >=
863 subsub_type->aligned_size[r_arch]) {
864 gras_trp_chunk_recv(sock, (char*)l_data,
865 subsub_type->aligned_size[r_arch] * count *
866 array_data.fixed_size);
867 if (r_arch != GRAS_THISARCH)
868 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data);
870 ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size);
872 gras_trp_chunk_recv(sock, (char*)ptr,
873 subsub_type->size[r_arch] * count*array_data.fixed_size);
874 if (r_arch != GRAS_THISARCH)
875 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data);
881 /* not scalar content, get it recursively (may contain pointers) */
882 elm_size = sub_type->aligned_size[GRAS_THISARCH];
883 VERB2("Receive a %d-long array of %s",count, sub_type->name);
886 for (cpt=0; cpt<count; cpt++) {
887 gras_datadesc_recv_rec(sock,state,refs, sub_type,
888 r_arch, NULL, 0, ptr,-1,
889 detect_cycle || sub_type->cycle);
898 xbt_assert0(0, "Invalid type");
902 type->recv(type,state,l_data);
907 * gras_datadesc_recv:
909 * Get an instance of the datatype described by @type from the @socket,
910 * and store a pointer to it in @dst
914 gras_datadesc_recv(gras_socket_t sock,
915 gras_datadesc_type_t type,
920 gras_cbps_t state; /* callback persistent state */
921 xbt_dict_t refs; /* all references already sent */
923 refs = xbt_dict_new();
924 state = gras_cbps_new();
926 xbt_assert0(type,"called with NULL type descriptor");
928 gras_datadesc_recv_rec(sock, state, refs, type,
933 xbt_dict_free(&refs);
934 gras_cbps_free(&state);