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_send/recv */
16 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_exchange,gras_ddt,
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;
26 static _XBT_INLINE void
27 gras_dd_send_int(gras_socket_t sock,int *i, int stable) {
30 int_type = gras_datadesc_by_name("int");
34 DEBUG1("send_int(%d)",*i);
35 gras_trp_send(sock, (char*)i, int_type->size[GRAS_THISARCH], stable);
38 static _XBT_INLINE void
39 gras_dd_recv_int(gras_socket_t sock, int r_arch, int *i) {
42 int_type = gras_datadesc_by_name("int");
46 if (int_type->size[GRAS_THISARCH] >= int_type->size[r_arch]) {
47 gras_trp_recv(sock, (char*)i, int_type->size[r_arch]);
48 if (r_arch != GRAS_THISARCH)
49 gras_dd_convert_elm(int_type,1,r_arch, i,i);
51 void *ptr = xbt_malloc(int_type->size[r_arch]);
53 gras_trp_recv(sock, (char*)ptr, int_type->size[r_arch]);
54 if (r_arch != GRAS_THISARCH)
55 gras_dd_convert_elm(int_type,1,r_arch, ptr,i);
58 DEBUG1("recv_int(%d)",*i);
62 * Note: here we suppose that the remote NULL is a sequence
63 * of 'length' bytes set to 0.
64 * FIXME: Check in configure?
66 static _XBT_INLINE int
67 gras_dd_is_r_null(char **r_ptr, long int length) {
70 for (i=0; i<length; i++) {
71 if ( ((unsigned char*)r_ptr) [i]) {
79 static _XBT_INLINE void
80 gras_dd_alloc_ref(xbt_dict_t refs,
83 long int r_len, /* pointer_type->size[r_arch] */
88 xbt_assert1(size>0,"Cannot allocate %ld bytes!", size);
89 l_data = xbt_malloc((size_t)size);
92 DEBUG5("alloc_ref: l_data=%p, &l_data=%p; r_ref=%p; *r_ref=%p, r_len=%ld",
93 (void*)l_data,(void*)&l_data,
94 (void*)r_ref, (void*)(r_ref?*r_ref:NULL), r_len);
95 if (detect_cycle && r_ref && !gras_dd_is_r_null( r_ref, r_len)) {
96 void *ptr = xbt_malloc(sizeof(void *));
98 CRITICAL0("Check for cycles");
99 memcpy(ptr,l_ref, sizeof(void *));
101 DEBUG2("Insert l_ref=%p under r_ref=%p",*(void**)ptr, *(void**)r_ref);
104 xbt_dict_set_ext(refs,(const char *) r_ref, r_len, ptr, free);
109 gras_datadesc_copy_rec(gras_cbps_t state,
111 gras_datadesc_type_t type,
120 gras_datadesc_type_t sub_type; /* type on which we recurse */
123 VERB4("Copy a %s (%s) from %p to %p",
124 type->name, gras_datadesc_cat_names[type->category_code],
128 type->send(type,state,src);
131 switch (type->category_code) {
132 case e_gras_datadesc_type_cat_scalar:
133 memcpy(dst,src,type->size[GRAS_THISARCH]);
134 count += type->size[GRAS_THISARCH];
137 case e_gras_datadesc_type_cat_struct: {
138 gras_dd_cat_struct_t struct_data;
139 gras_dd_cat_field_t field;
143 struct_data = type->category.struct_data;
144 xbt_assert1(struct_data.closed,
145 "Please call gras_datadesc_declare_struct_close on %s before copying it",
147 VERB1(">> Copy all fields of the structure %s",type->name);
148 xbt_dynar_foreach(struct_data.fields, cpt, field) {
149 field_src = src + field->offset[GRAS_THISARCH];
150 field_dst = dst + field->offset[GRAS_THISARCH];
152 sub_type = field->type;
155 field->send(type,state,field_src);
157 VERB1("Copy field %s",field->name);
158 count += gras_datadesc_copy_rec(state,refs,sub_type, field_src, field_dst, 0,
159 detect_cycle || sub_type->cycle);
162 VERB1("<< Copied all fields of the structure %s", type->name);
167 case e_gras_datadesc_type_cat_union: {
168 gras_dd_cat_union_t union_data;
169 gras_dd_cat_field_t field=NULL;
172 union_data = type->category.union_data;
174 xbt_assert1(union_data.closed,
175 "Please call gras_datadesc_declare_union_close on %s before copying it",
177 /* retrieve the field number */
178 field_num = union_data.selector(type, state, src);
180 xbt_assert1(field_num > 0,
181 "union field selector of %s gave a negative value",
184 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
185 "union field selector of %s returned %d but there is only %lu fields",
186 type->name, field_num, xbt_dynar_length(union_data.fields));
188 /* Copy the content */
189 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
190 sub_type = field->type;
193 field->send(type,state,src);
195 count += gras_datadesc_copy_rec(state,refs, sub_type, src, dst,0,
196 detect_cycle || sub_type->cycle);
201 case e_gras_datadesc_type_cat_ref: {
202 gras_dd_cat_ref_t ref_data;
205 int reference_is_to_cpy;
207 ref_data = type->category.ref_data;
209 /* Detect the referenced type */
210 sub_type = ref_data.type;
211 if (sub_type == NULL) {
212 sub_type = (*ref_data.selector)(type,state,src);
215 /* Send the pointed data only if not already sent */
216 if (*(void**)src == NULL) {
217 VERB0("Not copying NULL referenced data");
223 reference_is_to_cpy = 0;
226 /* return ignored. Just checking whether it's known or not */
227 n_ref=xbt_dict_get_ext(refs,(char*)o_ref, sizeof(char*));
229 reference_is_to_cpy = 1;
231 if (e.category != not_found_error)
233 reference_is_to_cpy = 1;
237 if (reference_is_to_cpy) {
239 void *l_referenced=NULL;
240 VERB2("Copy a ref to '%s' referenced at %p",sub_type->name, (void*)*o_ref);
243 pointer_type = gras_datadesc_by_name("data pointer");
244 xbt_assert(pointer_type);
247 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
248 /* Damn. Reference to a dynamic array. Allocating the space for it
249 is more complicated */
250 gras_dd_cat_array_t array_data = sub_type->category.array_data;
251 gras_datadesc_type_t subsub_type;
253 subsub_type = array_data.type;
254 subsubcount = array_data.fixed_size;
255 if (subsubcount == 0)
256 subsubcount = array_data.dynamic_size(subsub_type,state,*o_ref);
258 gras_dd_alloc_ref(refs,
259 subsub_type->size[GRAS_THISARCH] * subsubcount,
260 o_ref,pointer_type->size[GRAS_THISARCH],
261 (char**)&l_referenced,
264 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
265 o_ref,pointer_type->size[GRAS_THISARCH],
266 (char**)&l_referenced,
270 count += gras_datadesc_copy_rec(state,refs, sub_type,
271 *o_ref,(char*)l_referenced, subsubcount,
272 detect_cycle || sub_type->cycle);
274 *(void**)dst=l_referenced;
275 VERB3("'%s' previously referenced at %p now at %p",
276 sub_type->name, *(void**)o_ref, l_referenced);
279 VERB2("NOT copying data previously referenced @%p (already done, @%p now)",
280 *(void**)o_ref, *(void**)n_ref);
288 case e_gras_datadesc_type_cat_array: {
289 gras_dd_cat_array_t array_data;
290 long int array_count;
295 array_data = type->category.array_data;
297 /* determine and send the element count */
298 array_count = array_data.fixed_size;
299 if (array_count == 0)
300 array_count = subsize;
301 if (array_count == 0) {
302 array_count = array_data.dynamic_size(type,state,src);
303 xbt_assert1(array_count >=0,
304 "Invalid (negative) array size for type %s",type->name);
307 /* send the content */
308 sub_type = array_data.type;
309 elm_size = sub_type->aligned_size[GRAS_THISARCH];
310 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
311 VERB1("Array of %ld scalars, copy it in one shot",array_count);
312 memcpy(dst, src, sub_type->aligned_size[GRAS_THISARCH] * array_count);
313 count += sub_type->aligned_size[GRAS_THISARCH] * array_count;
314 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
315 sub_type->category.array_data.fixed_size > 0 &&
316 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
318 VERB1("Array of %ld fixed array of scalars, copy it in one shot",
320 memcpy(dst,src,sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
321 * array_count * sub_type->category.array_data.fixed_size);
322 count += sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
323 * array_count * sub_type->category.array_data.fixed_size;
326 VERB1("Array of %ld stuff, copy it in one after the other",array_count);
327 for (cpt=0; cpt<array_count; cpt++) {
328 VERB2("Copy the %dth stuff out of %ld",cpt,array_count);
329 count += gras_datadesc_copy_rec(state,refs, sub_type, src_ptr, dst_ptr, 0,
330 detect_cycle || sub_type->cycle);
339 xbt_assert0(0, "Invalid type");
344 * gras_datadesc_copy:
346 * Copy the data pointed by src and described by type
347 * to a new location, and store a pointer to it in dst.
350 int gras_datadesc_copy(gras_datadesc_type_t type,
351 void *src, void *dst) {
354 xbt_dict_t refs; /* all references already sent */
357 xbt_assert0(type,"called with NULL type descriptor");
359 refs = xbt_dict_new();
360 state = gras_cbps_new();
363 size = gras_datadesc_copy_rec(state,refs,type,(char*)src,(char*)dst,0,
366 xbt_dict_free(&refs);
367 gras_cbps_free(&state);
375 *** Direct use functions
379 gras_datadesc_send_rec(gras_socket_t sock,
382 gras_datadesc_type_t type,
388 gras_datadesc_type_t sub_type; /* type on which we recurse */
390 VERB2("Send a %s (%s)",
391 type->name, gras_datadesc_cat_names[type->category_code]);
393 if (!strcmp(type->name,"string"))
394 VERB1("value: '%s'",*(char**)data);
397 type->send(type,state,data);
398 DEBUG0("Run the emission callback");
401 switch (type->category_code) {
402 case e_gras_datadesc_type_cat_scalar:
403 gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1);
406 case e_gras_datadesc_type_cat_struct: {
407 gras_dd_cat_struct_t struct_data;
408 gras_dd_cat_field_t field;
411 struct_data = type->category.struct_data;
412 xbt_assert1(struct_data.closed,
413 "Please call gras_datadesc_declare_struct_close on %s before sending it",
415 VERB1(">> Send all fields of the structure %s",type->name);
416 xbt_dynar_foreach(struct_data.fields, cpt, field) {
418 field_data += field->offset[GRAS_THISARCH];
420 sub_type = field->type;
423 DEBUG1("Run the emission callback of field %s", field->name);
424 field->send(type,state,field_data);
427 VERB1("Send field %s",field->name);
428 gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
429 detect_cycle || sub_type->cycle);
432 VERB1("<< Sent all fields of the structure %s", type->name);
437 case e_gras_datadesc_type_cat_union: {
438 gras_dd_cat_union_t union_data;
439 gras_dd_cat_field_t field=NULL;
442 union_data = type->category.union_data;
444 xbt_assert1(union_data.closed,
445 "Please call gras_datadesc_declare_union_close on %s before sending it",
447 /* retrieve the field number */
448 field_num = union_data.selector(type, state, data);
450 xbt_assert1(field_num > 0,
451 "union field selector of %s gave a negative value",
454 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
455 "union field selector of %s returned %d but there is only %lu fields",
456 type->name, field_num, xbt_dynar_length(union_data.fields));
458 /* Send the field number */
459 gras_dd_send_int(sock, &field_num, 0 /* not stable */);
461 /* Send the content */
462 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
463 sub_type = field->type;
466 field->send(type,state,data);
468 gras_datadesc_send_rec(sock,state,refs, sub_type, data,
469 detect_cycle || sub_type->cycle);
474 case e_gras_datadesc_type_cat_ref: {
475 gras_dd_cat_ref_t ref_data;
476 void **ref=(void**)data;
477 int reference_is_to_send;
479 ref_data = type->category.ref_data;
481 /* Detect the referenced type and send it to peer if needed */
482 sub_type = ref_data.type;
483 if (sub_type == NULL) {
484 sub_type = (*ref_data.selector)(type,state,data);
485 gras_dd_send_int(sock, (int*) &(sub_type->code),1 /*stable*/);
488 /* Send the actual value of the pointer for cycle handling */
490 pointer_type = gras_datadesc_by_name("data pointer");
491 xbt_assert(pointer_type);
494 gras_trp_send(sock, (char*)data,
495 pointer_type->size[GRAS_THISARCH], 1 /*stable*/);
497 /* Send the pointed data only if not already sent */
498 if (*(void**)data == NULL) {
499 VERB0("Not sending NULL referenced data");
503 reference_is_to_send = 0;
506 /* return ignored. Just checking whether it's known or not */
507 xbt_dict_get_ext(refs,(char*)ref, sizeof(char*));
509 reference_is_to_send = 1;
511 if (e.category != not_found_error)
513 reference_is_to_send = 1;
517 if (reference_is_to_send) {
518 VERB1("Sending data referenced at %p", (void*)*ref);
520 xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
521 gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
522 detect_cycle || sub_type->cycle);
525 VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
531 case e_gras_datadesc_type_cat_array: {
532 gras_dd_cat_array_t array_data;
537 array_data = type->category.array_data;
539 /* determine and send the element count */
540 count = array_data.fixed_size;
542 count = array_data.dynamic_size(type,state,data);
543 xbt_assert1(count >=0,
544 "Invalid (negative) array size for type %s",type->name);
545 gras_dd_send_int(sock, &count, 0/*non-stable*/);
548 /* send the content */
549 sub_type = array_data.type;
550 elm_size = sub_type->aligned_size[GRAS_THISARCH];
551 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
552 VERB1("Array of %d scalars, send it in one shot",count);
553 gras_trp_send(sock, data,
554 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 %d fixed array of scalars, send it in one shot",count);
561 gras_trp_send(sock, data,
562 sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
563 * count * sub_type->category.array_data.fixed_size,
567 for (cpt=0; cpt<count; cpt++) {
568 gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
569 detect_cycle || sub_type->cycle);
577 xbt_assert0(0, "Invalid type");
582 * gras_datadesc_send:
584 * Copy the data pointed by src and described by type to the socket
587 void gras_datadesc_send(gras_socket_t sock,
588 gras_datadesc_type_t type,
592 static gras_cbps_t state=NULL;
593 xbt_dict_t refs; /* all references already sent */
595 xbt_assert0(type,"called with NULL type descriptor");
597 refs = xbt_dict_new();
599 state = gras_cbps_new();
602 gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
604 xbt_dict_free(&refs);
605 gras_cbps_reset(state);
612 * gras_datadesc_recv_rec:
614 * Do the data reception job recursively.
616 * subsize used only to deal with vicious case of reference to dynamic array.
617 * This size is needed at the reference reception level (to allocate enough
618 * space) and at the array reception level (to fill enough room).
620 * Having this size passed as an argument of the recursive function is a crude
621 * hack, but I was told that working code is sometimes better than neat one ;)
624 gras_datadesc_recv_rec(gras_socket_t sock,
627 gras_datadesc_type_t type,
636 gras_datadesc_type_t sub_type;
639 VERB2("Recv a %s @%p", type->name, (void*)l_data);
642 switch (type->category_code) {
643 case e_gras_datadesc_type_cat_scalar:
644 if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
645 gras_trp_recv(sock, (char*)l_data, type->size[r_arch]);
646 if (r_arch != GRAS_THISARCH)
647 gras_dd_convert_elm(type,1,r_arch, l_data,l_data);
649 void *ptr = xbt_malloc(type->size[r_arch]);
651 gras_trp_recv(sock, (char*)ptr, type->size[r_arch]);
652 if (r_arch != GRAS_THISARCH)
653 gras_dd_convert_elm(type,1,r_arch, ptr,l_data);
658 case e_gras_datadesc_type_cat_struct: {
659 gras_dd_cat_struct_t struct_data;
660 gras_dd_cat_field_t field;
662 struct_data = type->category.struct_data;
664 xbt_assert1(struct_data.closed,
665 "Please call gras_datadesc_declare_struct_close on %s before receiving it",
667 VERB1(">> Receive all fields of the structure %s",type->name);
668 xbt_dynar_foreach(struct_data.fields, cpt, field) {
669 char *field_data = l_data + field->offset[GRAS_THISARCH];
671 sub_type = field->type;
673 gras_datadesc_recv_rec(sock,state,refs, sub_type,
676 detect_cycle || sub_type->cycle);
679 DEBUG1("Run the reception callback of field %s", field->name);
680 field->recv(type,state,(void*)l_data);
684 VERB1("<< Received all fields of the structure %s", type->name);
689 case e_gras_datadesc_type_cat_union: {
690 gras_dd_cat_union_t union_data;
691 gras_dd_cat_field_t field=NULL;
694 union_data = type->category.union_data;
696 xbt_assert1(union_data.closed,
697 "Please call gras_datadesc_declare_union_close on %s before receiving it",
699 /* retrieve the field number */
700 gras_dd_recv_int(sock, r_arch, &field_num);
702 THROW1(mismatch_error,0,
703 "Received union field for %s is negative", type->name);
704 if (field_num > xbt_dynar_length(union_data.fields))
705 THROW3(mismatch_error,0,
706 "Received union field for %s is said to be #%d but there is only %lu fields",
707 type->name, field_num, xbt_dynar_length(union_data.fields));
709 /* Recv the content */
710 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
711 sub_type = field->type;
713 gras_datadesc_recv_rec(sock,state,refs, sub_type,
716 detect_cycle || sub_type->cycle);
718 field->recv(type,state,l_data);
723 case e_gras_datadesc_type_cat_ref: {
726 gras_dd_cat_ref_t ref_data;
727 int reference_is_to_recv = 0;
729 ref_data = type->category.ref_data;
731 /* Get the referenced type locally or from peer */
732 sub_type = ref_data.type;
733 if (sub_type == NULL) {
735 gras_dd_recv_int(sock, r_arch, &ref_code);
736 sub_type = gras_datadesc_by_id(ref_code);
739 /* Get the actual value of the pointer for cycle handling */
741 pointer_type = gras_datadesc_by_name("data pointer");
742 xbt_assert(pointer_type);
745 r_ref = xbt_malloc(pointer_type->size[r_arch]);
747 gras_trp_recv(sock, (char*)r_ref,
748 pointer_type->size[r_arch]);
750 /* Receive the pointed data only if not already sent */
751 if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
752 VERB1("Not receiving data remotely referenced @%p since it's NULL",
754 *(void**)l_data = NULL;
759 reference_is_to_recv = 0;
762 l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
764 reference_is_to_recv = 1;
766 if (e.category != not_found_error)
768 reference_is_to_recv = 1;
771 if (reference_is_to_recv) {
773 void *l_referenced=NULL;
775 VERB2("Receiving a ref to '%s', remotely @%p",
776 sub_type->name, *(void**)r_ref);
777 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
778 /* Damn. Reference to a dynamic array. Allocating the space for it
779 is more complicated */
780 gras_dd_cat_array_t array_data = sub_type->category.array_data;
781 gras_datadesc_type_t subsub_type;
783 subsubcount = array_data.fixed_size;
784 if (subsubcount == 0)
785 gras_dd_recv_int(sock, r_arch, &subsubcount);
787 subsub_type = array_data.type;
790 gras_dd_alloc_ref(refs,
791 subsub_type->size[GRAS_THISARCH] * subsubcount,
792 r_ref,pointer_type->size[r_arch],
793 (char**)&l_referenced,
796 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
797 r_ref,pointer_type->size[r_arch],
798 (char**)&l_referenced,
802 gras_datadesc_recv_rec(sock,state,refs, sub_type,
803 r_arch,r_ref,pointer_type->size[r_arch],
804 (char*)l_referenced, subsubcount,
805 detect_cycle || sub_type->cycle);
807 *(void**)l_data=l_referenced;
808 VERB3("'%s' remotely referenced at %p locally at %p",
809 sub_type->name, *(void**)r_ref, l_referenced);
812 VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)",
813 *(void**)r_ref, *(void**)l_ref);
815 *(void**)l_data=*l_ref;
822 case e_gras_datadesc_type_cat_array: {
823 gras_dd_cat_array_t array_data;
828 array_data = type->category.array_data;
829 /* determine element count locally, or from caller, or from peer */
830 count = array_data.fixed_size;
834 gras_dd_recv_int(sock, r_arch, &count);
836 THROW1(mismatch_error,0,
837 "Invalid (=0) array size for type %s",type->name);
839 /* receive the content */
840 sub_type = array_data.type;
841 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
842 VERB1("Array of %d scalars, get it in one shoot", count);
843 if (sub_type->aligned_size[GRAS_THISARCH] >=
844 sub_type->aligned_size[r_arch]) {
845 gras_trp_recv(sock, (char*)l_data,
846 sub_type->aligned_size[r_arch] * count);
847 if (r_arch != GRAS_THISARCH)
848 gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data);
850 ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count);
852 gras_trp_recv(sock, (char*)ptr,
853 sub_type->size[r_arch] * count);
854 if (r_arch != GRAS_THISARCH)
855 gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data);
858 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
859 sub_type->category.array_data.fixed_size > 0 &&
860 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
861 gras_datadesc_type_t subsub_type;
862 array_data = sub_type->category.array_data;
863 subsub_type = array_data.type;
865 VERB1("Array of %d fixed array of scalars, get it in one shot",count);
866 if (subsub_type->aligned_size[GRAS_THISARCH] >=
867 subsub_type->aligned_size[r_arch]) {
868 gras_trp_recv(sock, (char*)l_data,
869 subsub_type->aligned_size[r_arch] * count *
870 array_data.fixed_size);
871 if (r_arch != GRAS_THISARCH)
872 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data);
874 ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size);
876 gras_trp_recv(sock, (char*)ptr,
877 subsub_type->size[r_arch] * count*array_data.fixed_size);
878 if (r_arch != GRAS_THISARCH)
879 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data);
885 /* not scalar content, get it recursively (may contain pointers) */
886 elm_size = sub_type->aligned_size[GRAS_THISARCH];
887 VERB2("Receive a %d-long array of %s",count, sub_type->name);
890 for (cpt=0; cpt<count; cpt++) {
891 gras_datadesc_recv_rec(sock,state,refs, sub_type,
892 r_arch, NULL, 0, ptr,-1,
893 detect_cycle || sub_type->cycle);
902 xbt_assert0(0, "Invalid type");
906 type->recv(type,state,l_data);
908 if (!strcmp(type->name,"string"))
909 VERB1("value: '%s'",*(char**)l_data);
914 * gras_datadesc_recv:
916 * Get an instance of the datatype described by @type from the @socket,
917 * and store a pointer to it in @dst
921 gras_datadesc_recv(gras_socket_t sock,
922 gras_datadesc_type_t type,
927 static gras_cbps_t state=NULL; /* callback persistent state */
928 xbt_dict_t refs; /* all references already sent */
930 refs = xbt_dict_new();
932 state = gras_cbps_new();
934 xbt_assert0(type,"called with NULL type descriptor");
936 gras_datadesc_recv_rec(sock, state, refs, type,
941 xbt_dict_free(&refs);
942 gras_cbps_reset(state);