com-library/libvcacom/vca_com.c
int vca_com_send_msg(vca_com_t * com, 
		     vca_com_addr * dst, 
		     char * msg,
		     unsigned long long length,
		     unsigned int c) {
  
  char sspace[4096];
  void * buffer = (void*) sspace;
  vca_com_msg_hdr * hdr = NULL;
  unsigned long long full_length = length + sizeof(vca_com_msg_hdr);
  int ret = 0;

  // for short messages rely on the stack allocated array, otherwise default ot dyn. mem alloc
  if(full_length > 4096) {
    buffer = malloc(full_length);
  }
  
  // setup msg hdr hdr
  hdr = vca_com_msg_get_hdr(buffer);
  memset(hdr, 0, sizeof(vca_com_msg_hdr));
  vca_com_cpy_addr(&com->self, &hdr->src);
  vca_com_cpy_addr(dst, &hdr->dst);
  hdr->length = length;

  // copy message
  if(length > 0) {
    memcpy(vca_com_msg_get_msg(buffer), msg, length);
  }

  ret = vca_com_send_hdrless_msg(com, buffer, full_length, c);
  
  // free dyn. allocated msg after sending
  if(buffer != sspace) {
    free(buffer);
  }

  return ret;
}
// send message msg to dst via com
send message msg to dst via com
send message msg to dst via com
int vca_com_send_msg(vca_com_t * com, 
		     vca_com_addr * dst, 
		     char * msg,
		     unsigned long long length,
		     unsigned int c) {
  char sspace[4096];
  void * buffer = (void*) sspace;
  vca_com_msg_hdr * hdr = NULL;
  unsigned long long full_length = length + sizeof(vca_com_msg_hdr);
  int ret = 0;
  if(full_length > 4096) {
    buffer = malloc(full_length);
  }
  hdr = vca_com_msg_get_hdr(buffer);
  memset(hdr, 0, sizeof(vca_com_msg_hdr));
  vca_com_cpy_addr(&com->self, &hdr->src);
  vca_com_cpy_addr(dst, &hdr->dst);
  hdr->length = length;
  if(length > 0) {
    memcpy(vca_com_msg_get_msg(buffer), msg, length);
  }
  ret = vca_com_send_hdrless_msg(com, buffer, full_length, c);
  if(buffer != sspace) {
    free(buffer);
  }
  return ret;
}
int vca_com_send_msg ( vca_com_t * com , vca_com_addr * dst , char * msg , unsigned long long length , unsigned int c ) { char sspace [ 4096 ] ; void * buffer = ( void * ) sspace ; vca_com_msg_hdr * hdr = NULL ; unsigned long long full_length = length + sizeof ( vca_com_msg_hdr ) ; int ret = 0 ; if ( full_length > 4096 ) { buffer = malloc ( full_length ) ; } hdr = vca_com_msg_get_hdr ( buffer ) ; memset ( hdr , 0 , sizeof ( vca_com_msg_hdr ) ) ; vca_com_cpy_addr ( & com -> self , & hdr -> src ) ; vca_com_cpy_addr ( dst , & hdr -> dst ) ; hdr -> length = length ; if ( length > 0 ) { memcpy ( vca_com_msg_get_msg ( buffer ) , msg , length ) ; } ret = vca_com_send_hdrless_msg ( com , buffer , full_length , c ) ; if ( buffer != sspace ) { free ( buffer ) ; } return ret ; }
send message msg to dst via com
send message msg to dst via com
// for short messages rely on the stack allocated array, otherwise default ot dyn. mem alloc // setup msg hdr hdr // copy message // free dyn. allocated msg after sending