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(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;
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]);
394 type->send(type,state,data);
397 switch (type->category_code) {
398 case e_gras_datadesc_type_cat_scalar:
399 gras_trp_send(sock, data, type->size[GRAS_THISARCH], 1);
402 case e_gras_datadesc_type_cat_struct: {
403 gras_dd_cat_struct_t struct_data;
404 gras_dd_cat_field_t field;
407 struct_data = type->category.struct_data;
408 xbt_assert1(struct_data.closed,
409 "Please call gras_datadesc_declare_struct_close on %s before sending it",
411 VERB1(">> Send all fields of the structure %s",type->name);
412 xbt_dynar_foreach(struct_data.fields, cpt, field) {
414 field_data += field->offset[GRAS_THISARCH];
416 sub_type = field->type;
419 field->send(type,state,field_data);
421 VERB1("Send field %s",field->name);
422 gras_datadesc_send_rec(sock,state,refs,sub_type, field_data,
423 detect_cycle || sub_type->cycle);
426 VERB1("<< Sent all fields of the structure %s", type->name);
431 case e_gras_datadesc_type_cat_union: {
432 gras_dd_cat_union_t union_data;
433 gras_dd_cat_field_t field=NULL;
436 union_data = type->category.union_data;
438 xbt_assert1(union_data.closed,
439 "Please call gras_datadesc_declare_union_close on %s before sending it",
441 /* retrieve the field number */
442 field_num = union_data.selector(type, state, data);
444 xbt_assert1(field_num > 0,
445 "union field selector of %s gave a negative value",
448 xbt_assert3(field_num < xbt_dynar_length(union_data.fields),
449 "union field selector of %s returned %d but there is only %lu fields",
450 type->name, field_num, xbt_dynar_length(union_data.fields));
452 /* Send the field number */
453 gras_dd_send_int(sock, &field_num, 0 /* not stable */);
455 /* Send the content */
456 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
457 sub_type = field->type;
460 field->send(type,state,data);
462 gras_datadesc_send_rec(sock,state,refs, sub_type, data,
463 detect_cycle || sub_type->cycle);
468 case e_gras_datadesc_type_cat_ref: {
469 gras_dd_cat_ref_t ref_data;
470 void **ref=(void**)data;
471 int reference_is_to_send;
473 ref_data = type->category.ref_data;
475 /* Detect the referenced type and send it to peer if needed */
476 sub_type = ref_data.type;
477 if (sub_type == NULL) {
478 sub_type = (*ref_data.selector)(type,state,data);
479 gras_dd_send_int(sock, (int*) &(sub_type->code),1 /*stable*/);
482 /* Send the actual value of the pointer for cycle handling */
484 pointer_type = gras_datadesc_by_name("data pointer");
485 xbt_assert(pointer_type);
488 gras_trp_send(sock, (char*)data,
489 pointer_type->size[GRAS_THISARCH], 1 /*stable*/);
491 /* Send the pointed data only if not already sent */
492 if (*(void**)data == NULL) {
493 VERB0("Not sending NULL referenced data");
497 reference_is_to_send = 0;
500 /* return ignored. Just checking whether it's known or not */
501 xbt_dict_get_ext(refs,(char*)ref, sizeof(char*));
503 reference_is_to_send = 1;
505 if (e.category != not_found_error)
507 reference_is_to_send = 1;
511 if (reference_is_to_send) {
512 VERB1("Sending data referenced at %p", (void*)*ref);
514 xbt_dict_set_ext(refs, (char*)ref, sizeof(void*), ref, NULL);
515 gras_datadesc_send_rec(sock,state,refs, sub_type, *ref,
516 detect_cycle || sub_type->cycle);
519 VERB1("Not sending data referenced at %p (already done)", (void*)*ref);
525 case e_gras_datadesc_type_cat_array: {
526 gras_dd_cat_array_t array_data;
531 array_data = type->category.array_data;
533 /* determine and send the element count */
534 count = array_data.fixed_size;
536 count = array_data.dynamic_size(type,state,data);
537 xbt_assert1(count >=0,
538 "Invalid (negative) array size for type %s",type->name);
539 gras_dd_send_int(sock, &count, 0/*non-stable*/);
542 /* send the content */
543 sub_type = array_data.type;
544 elm_size = sub_type->aligned_size[GRAS_THISARCH];
545 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
546 VERB1("Array of %d scalars, send it in one shot",count);
547 gras_trp_send(sock, data,
548 sub_type->aligned_size[GRAS_THISARCH] * count,
550 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
551 sub_type->category.array_data.fixed_size > 0 &&
552 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
554 VERB1("Array of %d fixed array of scalars, send it in one shot",count);
555 gras_trp_send(sock, data,
556 sub_type->category.array_data.type->aligned_size[GRAS_THISARCH]
557 * count * sub_type->category.array_data.fixed_size,
561 for (cpt=0; cpt<count; cpt++) {
562 gras_datadesc_send_rec(sock,state,refs, sub_type, ptr,
563 detect_cycle || sub_type->cycle);
571 xbt_assert0(0, "Invalid type");
576 * gras_datadesc_send:
578 * Copy the data pointed by src and described by type to the socket
581 void gras_datadesc_send(gras_socket_t sock,
582 gras_datadesc_type_t type,
586 static gras_cbps_t state=NULL;
587 xbt_dict_t refs; /* all references already sent */
589 xbt_assert0(type,"called with NULL type descriptor");
591 refs = xbt_dict_new();
593 state = gras_cbps_new();
596 gras_datadesc_send_rec(sock,state,refs,type,(char*)src, type->cycle);
598 xbt_dict_free(&refs);
599 gras_cbps_reset(state);
606 * gras_datadesc_recv_rec:
608 * Do the data reception job recursively.
610 * subsize used only to deal with vicious case of reference to dynamic array.
611 * This size is needed at the reference reception level (to allocate enough
612 * space) and at the array reception level (to fill enough room).
614 * Having this size passed as an argument of the recursive function is a crude
615 * hack, but I was told that working code is sometimes better than neat one ;)
618 gras_datadesc_recv_rec(gras_socket_t sock,
621 gras_datadesc_type_t type,
630 gras_datadesc_type_t sub_type;
633 VERB2("Recv a %s @%p", type->name, (void*)l_data);
636 switch (type->category_code) {
637 case e_gras_datadesc_type_cat_scalar:
638 if (type->size[GRAS_THISARCH] == type->size[r_arch]) {
639 gras_trp_recv(sock, (char*)l_data, type->size[r_arch]);
640 if (r_arch != GRAS_THISARCH)
641 gras_dd_convert_elm(type,1,r_arch, l_data,l_data);
643 void *ptr = xbt_malloc(type->size[r_arch]);
645 gras_trp_recv(sock, (char*)ptr, type->size[r_arch]);
646 if (r_arch != GRAS_THISARCH)
647 gras_dd_convert_elm(type,1,r_arch, ptr,l_data);
652 case e_gras_datadesc_type_cat_struct: {
653 gras_dd_cat_struct_t struct_data;
654 gras_dd_cat_field_t field;
656 struct_data = type->category.struct_data;
658 xbt_assert1(struct_data.closed,
659 "Please call gras_datadesc_declare_struct_close on %s before receiving it",
661 VERB1(">> Receive all fields of the structure %s",type->name);
662 xbt_dynar_foreach(struct_data.fields, cpt, field) {
663 char *field_data = l_data + field->offset[GRAS_THISARCH];
665 sub_type = field->type;
667 gras_datadesc_recv_rec(sock,state,refs, sub_type,
670 detect_cycle || sub_type->cycle);
673 field->recv(type,state,(void*)l_data);
676 VERB1("<< Received all fields of the structure %s", type->name);
681 case e_gras_datadesc_type_cat_union: {
682 gras_dd_cat_union_t union_data;
683 gras_dd_cat_field_t field=NULL;
686 union_data = type->category.union_data;
688 xbt_assert1(union_data.closed,
689 "Please call gras_datadesc_declare_union_close on %s before receiving it",
691 /* retrieve the field number */
692 gras_dd_recv_int(sock, r_arch, &field_num);
694 THROW1(mismatch_error,0,
695 "Received union field for %s is negative", type->name);
696 if (field_num > xbt_dynar_length(union_data.fields))
697 THROW3(mismatch_error,0,
698 "Received union field for %s is said to be #%d but there is only %lu fields",
699 type->name, field_num, xbt_dynar_length(union_data.fields));
701 /* Recv the content */
702 field = xbt_dynar_get_as(union_data.fields, field_num, gras_dd_cat_field_t);
703 sub_type = field->type;
705 gras_datadesc_recv_rec(sock,state,refs, sub_type,
708 detect_cycle || sub_type->cycle);
710 field->recv(type,state,l_data);
715 case e_gras_datadesc_type_cat_ref: {
718 gras_dd_cat_ref_t ref_data;
719 int reference_is_to_recv = 0;
721 ref_data = type->category.ref_data;
723 /* Get the referenced type locally or from peer */
724 sub_type = ref_data.type;
725 if (sub_type == NULL) {
727 gras_dd_recv_int(sock, r_arch, &ref_code);
728 sub_type = gras_datadesc_by_id(ref_code);
731 /* Get the actual value of the pointer for cycle handling */
733 pointer_type = gras_datadesc_by_name("data pointer");
734 xbt_assert(pointer_type);
737 r_ref = xbt_malloc(pointer_type->size[r_arch]);
739 gras_trp_recv(sock, (char*)r_ref,
740 pointer_type->size[r_arch]);
742 /* Receive the pointed data only if not already sent */
743 if (gras_dd_is_r_null(r_ref, pointer_type->size[r_arch])) {
744 VERB1("Not receiving data remotely referenced @%p since it's NULL",
746 *(void**)l_data = NULL;
751 reference_is_to_recv = 0;
754 l_ref = xbt_dict_get_ext(refs, (char*)r_ref, pointer_type->size[r_arch]);
756 reference_is_to_recv = 1;
758 if (e.category != not_found_error)
760 reference_is_to_recv = 1;
763 if (reference_is_to_recv) {
765 void *l_referenced=NULL;
767 VERB2("Receiving a ref to '%s', remotely @%p",
768 sub_type->name, *(void**)r_ref);
769 if (sub_type->category_code == e_gras_datadesc_type_cat_array) {
770 /* Damn. Reference to a dynamic array. Allocating the space for it
771 is more complicated */
772 gras_dd_cat_array_t array_data = sub_type->category.array_data;
773 gras_datadesc_type_t subsub_type;
775 subsubcount = array_data.fixed_size;
776 if (subsubcount == 0)
777 gras_dd_recv_int(sock, r_arch, &subsubcount);
779 subsub_type = array_data.type;
782 gras_dd_alloc_ref(refs,
783 subsub_type->size[GRAS_THISARCH] * subsubcount,
784 r_ref,pointer_type->size[r_arch],
785 (char**)&l_referenced,
788 gras_dd_alloc_ref(refs,sub_type->size[GRAS_THISARCH],
789 r_ref,pointer_type->size[r_arch],
790 (char**)&l_referenced,
794 gras_datadesc_recv_rec(sock,state,refs, sub_type,
795 r_arch,r_ref,pointer_type->size[r_arch],
796 (char*)l_referenced, subsubcount,
797 detect_cycle || sub_type->cycle);
799 *(void**)l_data=l_referenced;
800 VERB3("'%s' remotely referenced at %p locally at %p",
801 sub_type->name, *(void**)r_ref, l_referenced);
804 VERB2("NOT receiving data remotely referenced @%p (already done, @%p here)",
805 *(void**)r_ref, *(void**)l_ref);
807 *(void**)l_data=*l_ref;
814 case e_gras_datadesc_type_cat_array: {
815 gras_dd_cat_array_t array_data;
820 array_data = type->category.array_data;
821 /* determine element count locally, or from caller, or from peer */
822 count = array_data.fixed_size;
826 gras_dd_recv_int(sock, r_arch, &count);
828 THROW1(mismatch_error,0,
829 "Invalid (=0) array size for type %s",type->name);
831 /* receive the content */
832 sub_type = array_data.type;
833 if (sub_type->category_code == e_gras_datadesc_type_cat_scalar) {
834 VERB1("Array of %d scalars, get it in one shoot", count);
835 if (sub_type->aligned_size[GRAS_THISARCH] >=
836 sub_type->aligned_size[r_arch]) {
837 gras_trp_recv(sock, (char*)l_data,
838 sub_type->aligned_size[r_arch] * count);
839 if (r_arch != GRAS_THISARCH)
840 gras_dd_convert_elm(sub_type,count,r_arch, l_data,l_data);
842 ptr = xbt_malloc(sub_type->aligned_size[r_arch] * count);
844 gras_trp_recv(sock, (char*)ptr,
845 sub_type->size[r_arch] * count);
846 if (r_arch != GRAS_THISARCH)
847 gras_dd_convert_elm(sub_type,count,r_arch, ptr,l_data);
850 } else if (sub_type->category_code == e_gras_datadesc_type_cat_array &&
851 sub_type->category.array_data.fixed_size > 0 &&
852 sub_type->category.array_data.type->category_code == e_gras_datadesc_type_cat_scalar) {
853 gras_datadesc_type_t subsub_type;
854 array_data = sub_type->category.array_data;
855 subsub_type = array_data.type;
857 VERB1("Array of %d fixed array of scalars, get it in one shot",count);
858 if (subsub_type->aligned_size[GRAS_THISARCH] >=
859 subsub_type->aligned_size[r_arch]) {
860 gras_trp_recv(sock, (char*)l_data,
861 subsub_type->aligned_size[r_arch] * count *
862 array_data.fixed_size);
863 if (r_arch != GRAS_THISARCH)
864 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, l_data,l_data);
866 ptr = xbt_malloc(subsub_type->aligned_size[r_arch] * count*array_data.fixed_size);
868 gras_trp_recv(sock, (char*)ptr,
869 subsub_type->size[r_arch] * count*array_data.fixed_size);
870 if (r_arch != GRAS_THISARCH)
871 gras_dd_convert_elm(subsub_type,count*array_data.fixed_size,r_arch, ptr,l_data);
877 /* not scalar content, get it recursively (may contain pointers) */
878 elm_size = sub_type->aligned_size[GRAS_THISARCH];
879 VERB2("Receive a %d-long array of %s",count, sub_type->name);
882 for (cpt=0; cpt<count; cpt++) {
883 gras_datadesc_recv_rec(sock,state,refs, sub_type,
884 r_arch, NULL, 0, ptr,-1,
885 detect_cycle || sub_type->cycle);
894 xbt_assert0(0, "Invalid type");
898 type->recv(type,state,l_data);
903 * gras_datadesc_recv:
905 * Get an instance of the datatype described by @type from the @socket,
906 * and store a pointer to it in @dst
910 gras_datadesc_recv(gras_socket_t sock,
911 gras_datadesc_type_t type,
916 static gras_cbps_t state=NULL; /* callback persistent state */
917 xbt_dict_t refs; /* all references already sent */
919 refs = xbt_dict_new();
921 state = gras_cbps_new();
923 xbt_assert0(type,"called with NULL type descriptor");
925 gras_datadesc_recv_rec(sock, state, refs, type,
930 xbt_dict_free(&refs);
931 gras_cbps_reset(state);