Exemplo n.º 1
0
void allocate_and_send(stk::CommSparse& comm, const std::vector<SideSharingData>& sideSharingDataThisProc, const std::vector<stk::mesh::impl::IdViaSidePair>& idAndSides)
{
    pack_data(comm, sideSharingDataThisProc, idAndSides);
    comm.allocate_buffers();
    pack_data(comm, sideSharingDataThisProc, idAndSides);
    comm.communicate();
}
Exemplo n.º 2
0
/**
 *  \param procedure procedure ID
 *  \param data unpacked message data
 *  \param len data length
 *
 *  Creates SysEx message then sends it. This function uses folowing global variables: device_id, family_id and product_id.
 **/
void send_message(gint procedure, gchar *data, gint len)
{
    GString *msg = g_string_new_len("\xF0"          /* SysEx status byte */
                                    "\x00\x00\x10", /* Manufacturer ID   */
                                    4);
    g_string_append_printf(msg,
                           "%c%c%c"   /* device, family, product ID */
                           "%c",      /* procedure */
                           device_id, family_id, product_id,
                           procedure);

    if (len > 0) {
        GString *tmp = pack_data(data, len);
        g_string_append_len(msg, tmp->str, tmp->len);
        g_string_free(tmp, TRUE);
    }

    g_string_append_printf(msg, "%c\xF7",
                           calculate_checksum(&msg->str[1], msg->len - 1));

    debug_msg(DEBUG_VERBOSE, "Sending %s len %d",
                              get_message_name(procedure), len);

    send_data(msg->str, msg->len);

    g_string_free(msg, TRUE);
}
Exemplo n.º 3
0
static int
pack_u16(struct asr_pack *p, uint16_t v)
{
	v = htons(v);

	return (pack_data(p, &v, 2));
}
Exemplo n.º 4
0
/**
 *
 * @brief 处理srch命令的函数
 *
 * @param[in] cmd_no 命令号,一个函数可能处理多条命令,可以用命令号来区分
 * @param[in] req_head 请求数据的nshead_t*
 * @param[in] req_buf 请求数据的buffer,本buffer不包含nshead_t
 * @param[out] res_head 应答数据的nshead_t*
 * @param[out] res_buf 应答数据的buffer,本buffer不包含nshead_t
 * @return
 *       0  : 成功
 *       -1 : 失败,socket将直接关闭,不给client返回错误信息
 **/
STATIC int
srch_process(int cmd_no, nshead_t * req_head, ub_buff_t * req_buf,
         nshead_t * res_head, ub_buff_t * res_buf)
{
    /**
     *在打NOTICE日志时,请使用 ub_log_pushnotice 加入日志信息
     *如果返回值不为0,将导致socket被直接关闭而不给客户返回任何信息
     **/
    srch_thread_data_t *p_thread_data;

    if(NULL == req_head || NULL == req_buf || NULL == res_head || NULL == res_buf) {
        UB_LOG_FATAL("parameter error in srch process.");
        return -1;
    }

    srch_reset_res(req_head, res_head, res_buf);

    char* req = req_buf->buf;
    char* res = res_buf->buf;

    res_head->body_len = 0;
	int response_buffer_size = ub_server_get_write_size() - sizeof (nshead_t);

    p_thread_data = (srch_thread_data_t* )ub_server_get_user_data();
    if(NULL == p_thread_data) {
        UB_LOG_FATAL("thead_data null");
        return -1;
    }

	int post_count            = 0;
	int max_post_count        = p_thread_data->max_post_count;
	u_int64_t* pids           = p_thread_data->post_ids;
	delpost_record_t* records = p_thread_data->records;

	if (!unpack_data(req, req_head->body_len, post_count, pids, max_post_count))
	{
		UB_LOG_WARNING("unpack mcpack error");
		return -1;
	}

	int ret = query(post_count, pids, records, 
			g_conf.mask_path, g_conf.index_file, g_conf.mask_file);

	if (ret < 0)
	{
		UB_LOG_WARNING("query[ret=%d] error", ret);
		return -1;
	}
	
	ret = pack_data(res, response_buffer_size, post_count, records);
	if (ret < 0)
	{
		UB_LOG_WARNING("pack mcpack error");
		return -1;
	}

	res_head->body_len = ret;

    return 0;
}
Exemplo n.º 5
0
int send_part(const char *text, unsigned int part_size, unsigned int index)
{
	int write_length;
	char text_part[part_size];

	int data_size = sizeof(struct message) - 1 + part_size;
	struct message *data = malloc(data_size);


	strncpy(text_part, &text[index * part_size], part_size); // Get part from user's input

	size_t part_length = strlen(text_part);
	pack_data(data, text_part, part_length, index, part_size); // strlen...

	LOG(DEBUG, "Sending part (%3u): '%s' (%u) #%u", index+1, text_part, part_length, data->checksum);

	if (simulate_sending) {
		write_length = data_size;
	} else {
		write_length = write(connection, data, data_size);
		if (write_length < 0)
			write_length = -errno;
	}


	free(data);

	return write_length;
}
Exemplo n.º 6
0
Arquivo: dbpack.c Projeto: braddr/cold
cBuf * pack_data(cBuf *buf, cData *data)
{
    buf = write_long(buf, data->type);
    switch (data->type) {

        case INTEGER:
            buf = write_long(buf, data->u.val);
            break;

        case FLOAT:
            buf = write_float(buf, data->u.fval);
            break;

        case STRING:
            buf = string_pack(buf, data->u.str);
            break;

        case OBJNUM:
            buf = write_long(buf, data->u.objnum);
            break;

        case LIST:
            buf = pack_list(buf, data->u.list);
            break;

        case SYMBOL:
            buf = write_ident(buf, data->u.symbol);
            break;

        case T_ERROR:
            buf = write_ident(buf, data->u.error);
            break;

        case FROB:
            buf = write_long(buf, data->u.frob->cclass);
            buf = pack_data(buf, &data->u.frob->rep);
            break;

        case DICT:
            buf = pack_dict(buf, data->u.dict);
            break;

        case BUFFER:
            buf = write_long(buf, data->u.buffer->len);
            buf = buffer_append(buf, data->u.buffer);
            break;

#ifdef USE_PARENT_OBJS
        case OBJECT:
            break;
#endif

        default: {
            INSTANCE_RECORD(data->type, r);
            buf = r->pack(buf, data);
        }
    }
    return buf;
}
Exemplo n.º 7
0
static int
pack_dname(struct asr_pack *p, const char *dname)
{
	/* dname compression would be nice to have here.
	 * need additionnal context.
	 */
	return (pack_data(p, dname, strlen(dname) + 1));
}
Exemplo n.º 8
0
cBuf *pack_handled (cBuf *buf, cData *d)
{
    HandledFrob *h = HANDLED_FROB(d);

    buf = write_long (buf, h->cclass);
    buf = pack_data  (buf, &h->rep);
    buf = write_ident(buf, h->handler);
    return buf;
}
Exemplo n.º 9
0
void send_data(ChordServer *srv, int last, uchar ttl, Node *np, chordID *id,
			   ushort n, const uchar *data)
{
	in6_addr *to_addr = &np->addr;
	ushort to_port = np->port;

	int len = pack_data(buf, last, ttl, id, n, data);

	LOG_SEND();
	send_packet(srv, &np->addr, np->port, len, buf);
}
Exemplo n.º 10
0
int
_asr_pack_header(struct asr_pack *p, const struct asr_dns_header *h)
{
	struct asr_dns_header c;

	c.id = h->id;
	c.flags = htons(h->flags);
	c.qdcount = htons(h->qdcount);
	c.ancount = htons(h->ancount);
	c.nscount = htons(h->nscount);
	c.arcount = htons(h->arcount);

	return (pack_data(p, &c, HFIXEDSZ));
}
Exemplo n.º 11
0
Arquivo: dbpack.c Projeto: braddr/cold
static cBuf * pack_list(cBuf *buf, cList *list)
{
    cData *d;

    if (!list) {
        buf = write_long(buf, -1);
    } else {
        buf = write_long(buf, list_length(list));
        for (d = list_first(list); d; d = list_next(list, d))
            buf = pack_data(buf, d);
    }

    return buf;
}
Exemplo n.º 12
0
static void do_write_data(struct imgspec* const spec, struct entry* ent,
	char* base, __u64* blkptr_offset, __u64* data_offset)
{
	do {
		if (ent->e_path && ent->e_dataoffset == 0) {
			set_dataoffset(ent, base, *blkptr_offset);
			load_entry_data(ent);
			pack_data(spec, ent, base, blkptr_offset, data_offset);
			unload_entry_data(ent);
		} else if (ent->e_firstchild) {
			do_write_data(spec, ent->e_firstchild, base,
				blkptr_offset, data_offset);
		}
	} while ((ent = ent->e_sibling));
}
Exemplo n.º 13
0
int	Parse::get_order(int p, int tmp, std::string &msg)
{
  std::string	cmd;
  std::string	type;
  std::string	size;
  std::string	num;

  if (tmp != 0)
    tmp = tmp + 1;
  cmd = msg.substr(tmp, p);
  std::istringstream	is(cmd);
  is >> type >> size >> num;
  if (type.empty() || size.empty() || num.empty())
    return (1);
  return (pack_data(type, size, num));
}
Exemplo n.º 14
0
void 
handle_remove_node(int argc, char **argv)
{
	char *data;
	int size;
	init_node(&node);
	parse_options(argc, argv);
	if (node.hostname == NULL)
		usage();

	msgxchng_request_t *req;
	data = pack_data(&size);
	req = new_msgxchng_request("1", 1, "node.remove", 11, data, size);

	free(data);
	redd_request(req, on_response);
}
Exemplo n.º 15
0
int main(){
    char *buffer=pack_data();
    unmapall();
    unpack_data(buffer);
    char *out = NULL;
    //const char *argv[]={"cat","/data/local/tmp/a.txt",NULL};
    //out=(char*)exec_bbcmd(argv);
    //printf("%s",out);
    //free(out);
    uint32_t out_len;
    const char *argv2[]={"ls","/data",NULL};
    out=(char*)exec_bbcmd(argv2,&out_len);
    printf("%s",out);
    free(out);
    const char *argv3[]={"ifconfig",NULL};
    out=(char*)exec_bbcmd(argv3,&out_len);
    printf("%s",out);
    free(out);
    free(buffer);
}
Exemplo n.º 16
0
Arquivo: dbpack.c Projeto: braddr/cold
static cBuf * pack_vars(cBuf *buf, Obj *obj)
{
    Int i;

    buf = write_long(buf, obj->vars.size);
    buf = write_long(buf, obj->vars.blanks);

    for (i = 0; i < obj->vars.size; i++) {
	buf = write_long(buf, obj->vars.hashtab[i]);
	if (obj->vars.tab[i].name != NOT_AN_IDENT) {
	    buf = write_ident(buf, obj->vars.tab[i].name);
	    buf = write_long(buf, obj->vars.tab[i].cclass);
	    buf = pack_data(buf, &obj->vars.tab[i].val);
	} else {
	    buf = write_long(buf, NOT_AN_IDENT);
	}
	buf = write_long(buf, obj->vars.tab[i].next);
    }
    return buf;
}
Exemplo n.º 17
0
void pack_model_state(dist_prcp_struct    *prcp,
                      global_param_struct *gp,
                      int                  Nveg,
                      int                  cellnum,
                      filep_struct        *filep,
                      soil_con_struct     *soil_con,
                      char                *STILL_STORM,
                      int                 *DRY_TIME,
                      float               *states,
                      int                 *count)
{
    extern option_struct options;

    double tmpval;
    int    veg;
    int    band;
    int    lidx;
    int    nidx;
    int    dist;
    int    Ndist;
    int    Nbands;
    int    byte;

    *count = 0;
    options.BINARY_STATE_FILE = TRUE;

#if SPATIAL_FROST
    int    frost_area;
#endif // SPATIAL_FROST

    cell_data_struct     ***cell;
    snow_data_struct      **snow;
    energy_bal_struct     **energy;
    veg_var_struct       ***veg_var;
    lake_var_struct         lake_var;
    int    node;

    if(options.DIST_PRCP)
        Ndist = 2;
    else
        Ndist = 1;
    Nbands = options.SNOW_BAND;

    cell    = prcp->cell;
    veg_var = prcp->veg_var;
    snow    = prcp->snow;
    energy  = prcp->energy;
    lake_var = prcp->lake_var;

    /* write cell information */
    pack_data(states, count, 1.0*cellnum);
    pack_data(states, count, 1.0*Nveg);
    pack_data(states, count, 1.0*Nbands);

    /* Write soil thermal node deltas */
    for ( nidx = 0; nidx < options.Nnode; nidx++ )
    {
        pack_data(states, count, 1.0*soil_con->dz_node[nidx]);
    }

    /* Write soil thermal node depths */
    for ( nidx = 0; nidx < options.Nnode; nidx++ )
    {
        pack_data(states, count, 1.0*soil_con->Zsum_node[nidx]);
    }

    /* Write dynamic soil properties */
#if EXCESS_ICE
    /* Write soil depth */
    for ( lidx = 0; lidx < options.Nlayer; lidx++ )
    {
        pack_data(states, count, 1.0*soil_con->depth[lidx]);
    }

    /* Write effective porosity */
    for ( lidx = 0; lidx < options.Nlayer; lidx++ )
    {
        pack_data(states, count, 1.0*soil_con->effective_porosity[lidx]);
    }

    /* Write damping depth */
    pack_data(states, count, 1.0*soil_con->dp);
#endif

    /* Output for all vegetation types */
    for ( veg = 0; veg <= Nveg; veg++ )
    {
        // Store distributed precipitation fraction
        pack_data(states, count, 1.0*prcp->mu[veg]);

        // Store distributed precipitation variables
        //pack_data(states, count, 1.0*STILL_STORM[veg]);
        if(STILL_STORM[veg]==TRUE)
            pack_data(states, count, 1.0);
        else
            pack_data(states, count, 0.0);

        pack_data(states, count, 1.0*DRY_TIME[veg]);

        /* Output for all snow bands */
        for ( band = 0; band < Nbands; band++ )
        {
            /* Write cell identification information */
            pack_data(states, count, 1.0*veg);
            pack_data(states, count, 1.0*band);

            for ( dist = 0; dist < Ndist; dist ++ )
            {
                // Store both wet and dry fractions if using distributed precipitation
                /* Write total soil moisture */
                for ( lidx = 0; lidx < options.Nlayer; lidx++ )
                {
                    tmpval = cell[dist][veg][band].layer[lidx].moist;
                    pack_data(states, count, 1.0*tmpval);
                }

                /* Write average ice content */
                for ( lidx = 0; lidx < options.Nlayer; lidx++ )
                {
#if SPATIAL_FROST
                    for ( frost_area = 0; frost_area < FROST_SUBAREAS; frost_area++ )
                    {
                        tmpval = cell[dist][veg][band].layer[lidx].ice[frost_area];
                        pack_data(states, count, 1.0*tmpval);
                    }
#else
                    tmpval = cell[dist][veg][band].layer[lidx].ice;
                    pack_data(states, count, 1.0*tmpval);
#endif // SPATIAL_FROST
                }

                /* Write dew storage */
                if ( veg < Nveg )
                {
                    tmpval = veg_var[dist][veg][band].Wdew;
                    pack_data(states, count, 1.0*tmpval);
                }
            }

            /* Write snow data */
            pack_data(states, count, 1.0*snow[veg][band].last_snow);
            pack_data(states, count, 1.0*snow[veg][band].MELTING);
            pack_data(states, count, 1.0*snow[veg][band].coverage);
            pack_data(states, count, 1.0*snow[veg][band].swq);
            pack_data(states, count, 1.0*snow[veg][band].surf_temp);
            pack_data(states, count, 1.0*snow[veg][band].surf_water);
            pack_data(states, count, 1.0*snow[veg][band].pack_temp);
            pack_data(states, count, 1.0*snow[veg][band].pack_water);
            pack_data(states, count, 1.0*snow[veg][band].density);
            pack_data(states, count, 1.0*snow[veg][band].coldcontent);
            pack_data(states, count, 1.0*snow[veg][band].snow_canopy);

            /* Write soil thermal node temperatures */
            for ( nidx = 0; nidx < options.Nnode; nidx++ )
            {
                pack_data(states, count, 1.0*energy[veg][band].T[nidx]);
            }

        }
    }

    if ( options.LAKES )
    {
        for ( dist = 0; dist < Ndist; dist ++ )
        {
            // Store both wet and dry fractions if using distributed precipitation
            /* Write total soil moisture */
            for ( lidx = 0; lidx < options.Nlayer; lidx++ )
            {
                pack_data(states, count, 1.0*lake_var.soil.layer[lidx].moist);
            }

            /* Write average ice content */
            for ( lidx = 0; lidx < options.Nlayer; lidx++ )
            {
#if SPATIAL_FROST
                for ( frost_area = 0; frost_area < FROST_SUBAREAS; frost_area++ )
                {
                    pack_data(states, count, 1.0*lake_var.soil.layer[lidx].ice[frost_area]);
                }
#else
                pack_data(states, count, 1.0*lake_var.soil.layer[lidx].ice);
#endif // SPATIAL_FROST
            }
        }
        /* Write snow data */
        pack_data(states, count, 1.0*lake_var.snow.last_snow);
        pack_data(states, count, 1.0*lake_var.snow.MELTING);
        pack_data(states, count, 1.0*lake_var.snow.coverage);
        pack_data(states, count, 1.0*lake_var.snow.swq);
        pack_data(states, count, 1.0*lake_var.snow.surf_temp);
        pack_data(states, count, 1.0*lake_var.snow.surf_water);
        pack_data(states, count, 1.0*lake_var.snow.pack_temp);
        pack_data(states, count, 1.0*lake_var.snow.pack_water);
        pack_data(states, count, 1.0*lake_var.snow.density);
        pack_data(states, count, 1.0*lake_var.snow.coldcontent);
        pack_data(states, count, 1.0*lake_var.snow.snow_canopy);

        /* Write soil thermal node temperatures */
        for ( nidx = 0; nidx < options.Nnode; nidx++ )
        {
            pack_data(states, count, 1.0*lake_var.energy.T[nidx]);
        }

        /* Write lake-specific variables */
        pack_data(states, count, 1.0*lake_var.activenod);
        pack_data(states, count, 1.0*lake_var.dz);
        pack_data(states, count, 1.0*lake_var.surfdz);
        pack_data(states, count, 1.0*lake_var.ldepth);

        for ( node = 0; node <= lake_var.activenod; node++ )
        {
            pack_data(states, count, 1.0*lake_var.surface[node]);
        }

        pack_data(states, count, 1.0*lake_var.sarea);
        pack_data(states, count, 1.0*lake_var.volume);

        for ( node = 0; node < lake_var.activenod; node++ )
        {
            pack_data(states, count, 1.0*lake_var.temp[node]);
        }

        pack_data(states, count, 1.0*lake_var.tempavg);
        pack_data(states, count, 1.0*lake_var.areai);
        pack_data(states, count, 1.0*lake_var.new_ice_area);
        pack_data(states, count, 1.0*lake_var.ice_water_eq);
        pack_data(states, count, 1.0*lake_var.hice);
        pack_data(states, count, 1.0*lake_var.tempi);
        pack_data(states, count, 1.0*lake_var.swe);
        pack_data(states, count, 1.0*lake_var.surf_temp);
        pack_data(states, count, 1.0*lake_var.pack_temp);
        pack_data(states, count, 1.0*lake_var.coldcontent);
        pack_data(states, count, 1.0*lake_var.surf_water);
        pack_data(states, count, 1.0*lake_var.pack_water);
        pack_data(states, count, 1.0*lake_var.SAlbedo);
        pack_data(states, count, 1.0*lake_var.sdepth);
    }
}
Exemplo n.º 18
0
int main(int argc, char *argv[])
{
  int sock, ret, port;
  struct sockaddr_in dest_addr;
  int addr_size;
  unsigned char buf[BUFFER_SIZE];

  port = atoi(argv[1]);

  if((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
    perror("client: socket");
    return 1;
  }

  dest_addr.sin_family = AF_INET;
  dest_addr.sin_port = htons(port);
  dest_addr.sin_addr.s_addr = inet_addr(argv[2]);

  //snprintf(buf, BUFFER_SIZE, "Hello World!");

  addr_size = sizeof(dest_addr);
  {
    FILE *fp;
    int fret, seq_num=-1;
    int c, flags;

    fp = fopen(argv[3], "r");

    if(fp != NULL) {
      // send the filename first
      int fname_len = strlen(argv[3]);

      strncpy(buf+HEADER_SIZE, argv[3], fname_len);
      pack_data(seq_num, MSG_TYPE_DATA, FLAG_FNAME, buf, fname_len+HEADER_SIZE);

      if((ret = sendto(sock, buf, fname_len+HEADER_SIZE,0,(struct sockaddr*)&dest_addr,addr_size)) == -1) {
        close(sock);
        perror("client: sendto");
        return 1;
      }
      
      seq_num++;

      // blast away the data, i say!
      while((fret = fread(buf+HEADER_SIZE, 1, DATA_SIZE, fp)) != 0) {
        flags = 0;
        printf("read %d bytes!\n", fret);

        // peek and unpeek last character
        c = fgetc(fp);
        ungetc(c,fp);

        if (c == -1) {
          flags = FLAG_EOM;
        }

        pack_data(seq_num, MSG_TYPE_DATA, flags, buf, fret+HEADER_SIZE);
        if((ret = sendto(sock, buf, fret+HEADER_SIZE,0,(struct sockaddr*)&dest_addr,addr_size)) == -1) {
          close(sock);
          perror("client: sendto");
          return 1;
        }

        seq_num++;
      }
      fclose(fp);
    }
  }

  return 0;
}