int CompactBlockCompleteMessage::parse(char* data, int32_t len)
 {
   if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&block_id_)) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&success_)) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_int64(&data, &len, reinterpret_cast<int64_t*> (&server_id_)) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if ((len < static_cast<int32_t> (sizeof(uint8_t))) || (len > TFS_MALLOC_MAX_SIZE))
   {
     return TFS_ERROR;
   }
   if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&flag_)) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_vint64(&data, &len, ds_list_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_object(&data, &len, reinterpret_cast<void**> (&block_info_), BLOCKINFO_SIZE) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   return TFS_SUCCESS;
 }
    int ReplicateInfoMessage::get_counter_map(char** data, int32_t* len, COUNTER_TYPE & m)
    {
      int32_t i = 0;
      int32_t size = 0;
      uint64_t server_id = 0;
      uint32_t count = 0;

      if (get_int32(data, len, &size) == TFS_ERROR)
      {
        return TFS_ERROR;
      }
      for (i = 0; i < size; ++i)
      {
        if (get_int64(data, len, reinterpret_cast<int64_t*> (&server_id)) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
        if (get_int32(data, len, reinterpret_cast<int32_t*> (&count)) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
        m.insert(COUNTER_TYPE::value_type(server_id, count));
      }
      return TFS_SUCCESS;
    }
 int ReplicateInfoMessage::parse(char* data, int32_t len)
 {
   int32_t size = 0;
   if (get_int32(&data, &len, &size) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   ReplBlock item;
   uint32_t block_id = 0;
   int32_t i = 0;
   for (i = 0; i < size; ++i)
   {
     if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&block_id)) == TFS_ERROR)
     {
       return TFS_ERROR;
     }
     if (get_object_copy(&data, &len, reinterpret_cast<void*> (&item), sizeof(ReplBlock)) == TFS_ERROR)
     {
       return TFS_ERROR;
     }
     replicating_map_.insert(REPL_BLOCK_MAP::value_type(block_id, item));
   }
   if (get_counter_map(&data, &len, source_ds_counter_))
   {
     return TFS_ERROR;
   }
   if (get_counter_map(&data, &len, dest_ds_counter_))
   {
     return TFS_ERROR;
   }
   return TFS_SUCCESS;
 }
    int RespListBlockMessage::parse(char* data, int32_t len)
    {
      int32_t i, size;
      if (get_int32(&data, &len, &status_type_) == TFS_ERROR)
      {
        return TFS_ERROR;
      }

      need_free_ = 1;
      // m_Blocks
      if (status_type_ & LB_BLOCK)
      {
        if (get_vint32(&data, &len, blocks_) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
      }

      // m_BlockPairs
      if (status_type_ & LB_PAIRS)
      {
        if (get_int32(&data, &len, &size) == TFS_ERROR)
        {
          return TFS_ERROR;
        }

        uint32_t block_id;
        for (i = 0; i < size; i++)
        {
          if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&block_id)) == TFS_ERROR)
          {
            return TFS_ERROR;
          }
          //stack or heap?
          vector < uint32_t > tmpVector;
          get_vint32(&data, &len, tmpVector);
          block_pairs_.insert(map<uint32_t, vector<uint32_t> >::value_type(block_id, tmpVector));
        }
      }
      // wblock_list_
      if (status_type_ & LB_INFOS)
      {
        if (get_int32(&data, &len, &size) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
        for (i = 0; i < size; i++)
        {
          BlockInfo* block_info = NULL;
          if (get_object(&data, &len, reinterpret_cast<void**> (&block_info), BLOCKINFO_SIZE) == TFS_ERROR)
          {
            return TFS_ERROR;
          }
          block_infos_.insert(map<uint32_t, BlockInfo*>::value_type(block_info->block_id_, block_info));
        }
      }

      return TFS_SUCCESS;

    }
 // DataServerStatInfo, block_count, block_id, block_version, ...
 int SetDataserverMessage::parse(char* data, int32_t len)
 {
   if (get_object(&data, &len, reinterpret_cast<void**> (&ds_), sizeof(DataServerStatInfo))
       == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&has_block_)) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (has_block_ > 0)
   {
     int32_t size = 0;
     if (get_int32(&data, &len, &size) == TFS_ERROR)
     {
       return TFS_ERROR;
     }
     BlockInfo* block_info;
     int32_t i = 0;
     for (i = 0; i < size; i++)
     {
       if (get_object(&data, &len, reinterpret_cast<void**> (&block_info), BLOCKINFO_SIZE)
           == TFS_ERROR)
       {
         return TFS_ERROR;
       }
       blocks_.push_back(*block_info);
     }
   }
   return TFS_SUCCESS;
 }
Exemple #6
0
//---------------------------------------------------------------------------------------------------------------------//
Field::Field(char const*& data)
{
   m_name = get_string(data);
   get_string(data); // skip description
   m_size = get_int32(data);
   m_type = get_int32(data);
   m_flags = get_int32(data);
   get_string(data); // skip enums
}
Exemple #7
0
//---------------------------------------------------------------------------------------------------------------------//
void Field::skip(char const*& data)
{
   get_string(data); // name
   get_string(data); // description
   get_int32(data);  // size
   get_int32(data);  // type
   get_int32(data);  // attribute
   get_string(data); // enum
}
Exemple #8
0
Context::Context() {
  std::vector<google::CommandLineFlagInfo> flags;
  google::GetAllFlags(&flags);
  for (size_t i = 0; i < flags.size(); i++) {
    google::CommandLineFlagInfo& flag = flags[i];
    ctx_[flag.name] = flag.is_default ? flag.default_value : flag.current_value;
  }

  num_app_threads_ = get_int32("num_table_threads") - 1;
  num_rows_per_table_ = get_int32("num_rows_per_table");
  use_svb_ = false;
  svb_completed_ = false;
}
    int GetBlockInfoMessage::parse(char* data, int32_t len)
    {
      if (get_int32(&data, &len, &mode_) == TFS_ERROR)
      {
        return TFS_ERROR;
      }
      if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&block_id_)) == TFS_ERROR)
      {
        return TFS_ERROR;
      }
      get_vint64(&data, &len, fail_server_);

      return TFS_SUCCESS;
    }
Exemple #10
0
Fichier : bn.c Projet : HansN/otp
int get_bn_from_mpint(ErlNifEnv* env, ERL_NIF_TERM term, BIGNUM** bnp)
{
    BIGNUM *ret;
    ErlNifBinary bin;
    int sz;

    if (!enif_inspect_binary(env, term, &bin))
        goto err;
    if (bin.size > INT_MAX - 4)
        goto err;

    ERL_VALGRIND_ASSERT_MEM_DEFINED(bin.data, bin.size);

    if (bin.size < 4)
        goto err;
    sz = (int)bin.size - 4;
    if (get_int32(bin.data) != sz)
        goto err;

    if ((ret = BN_bin2bn(bin.data+4, sz, NULL)) == NULL)
        goto err;

    *bnp = ret;
    return 1;

 err:
    return 0;
}
Exemple #11
0
PRIVATESTUFF int
exp1_read(descriptor *d, char *buf, int buflen)
{
    char		cmd;
    struct t_data	*td = sys_alloc(sizeof(struct t_data));

    assert(td != NULL);
    assert(buflen >= 4);
    cmd = *buf++;
    td->cmd = cmd;
    td->id = get_int32(buf);
    buf += 4;
    td->name = NULL;

    fprintf(DEBUGIO, "exp1_read: cmd = %d, id = %ld\r\n", cmd, td->id);
    switch (cmd) {
    case EXP1_REQ_GETHOSTBYNAME:
        /* buf = null-terminated hostname */
        /* XXX use something other than strdup()? */
        td->name = strdup(buf);
        driver_async(d->port, KEY, invoke_gethostbyname, (void *) td,
                     free_t_data);
        break;
    }
    /*
    ** XXX I guess we'll ignore everything else, let the caller hang.
    */
    fprintf(DEBUGIO, "exp1_read: done\r\n");
    return 0;
}
 int CompactBlockMessage::parse(char* data, int32_t len)
 {
   if (get_int32(&data, &len, &preserve_time_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&block_id_)) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_int32(&data, &len, static_cast<int32_t*> (&is_owner_)) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   return TFS_SUCCESS;
 }
Exemple #13
0
 T get( const field_desc_type *fld ) const
 {
     switch(fld->cpp_type( )) {
     case field_desc_type::CPPTYPE_INT32:
         return boost::lexical_cast<T>(get_int32(fld));
     case field_desc_type::CPPTYPE_INT64:
         return boost::lexical_cast<T>(get_int64(fld));
     case field_desc_type::CPPTYPE_UINT32:
         return boost::lexical_cast<T>(get_uint32(fld));
     case field_desc_type::CPPTYPE_UINT64:
         return boost::lexical_cast<T>(get_uint64(fld));
     case field_desc_type::CPPTYPE_FLOAT:
         return boost::lexical_cast<T>(get_float(fld));
     case field_desc_type::CPPTYPE_DOUBLE:
         return boost::lexical_cast<T>(get_double(fld));
     case field_desc_type::CPPTYPE_ENUM:
         return boost::lexical_cast<T>(get_enum(fld)->number());
     case field_desc_type::CPPTYPE_STRING:
         return boost::lexical_cast<T>(get_string(fld));
     case field_desc_type::CPPTYPE_BOOL:
         return boost::lexical_cast<T>(get_bool(fld));
     case field_desc_type::CPPTYPE_MESSAGE:
         throw std::bad_cast( );
     default:
         return T( );
     }
 }
Exemple #14
0
/* Receives a message from an Erlang socket.
 * If the message was a TICK it is immediately
 * answered. Returns: ERL_ERROR, ERL_TICK or
 * the number of bytes read.
 */
int ei_receive_tmo(int fd, unsigned char *bufp, int bufsize, unsigned ms) 
{
    int len;
    unsigned char fourbyte[4]={0,0,0,0};
    int res;
 
    if ((res = ei_read_fill_t(fd, (char *) bufp, 4, ms))  != 4) {
	erl_errno = (res == -2) ? ETIMEDOUT : EIO;
	return ERL_ERROR;
    }
    
    /* Tick handling */
    if ((len = get_int32(bufp)) == ERL_TICK) 
    {
	ei_write_fill_t(fd, (char *) fourbyte, 4, ms);
	/* FIXME ok to ignore error or timeout? */
	erl_errno = EAGAIN;
	return ERL_TICK;
    }
    else if (len > bufsize) 
    {
	/* FIXME: We should drain the message. */
	erl_errno = EMSGSIZE;
	return ERL_ERROR;
    }
    else if ((res = ei_read_fill_t(fd, (char *) bufp, len, ms)) != len)
    {
	erl_errno = (res == -2) ? ETIMEDOUT : EIO;
	return ERL_ERROR;
    }
    
    return len;
    
}
 int GetServerStatusMessage::parse(char* data, int32_t len)
 {
   if (get_int32(&data, &len, &status_type_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_int32(&data, &len, &from_row_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_int32(&data, &len, &return_row_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   return TFS_SUCCESS;
 }
Exemple #16
0
void Context::Init() {
  int rand_seed = get_int32("random_seed");
  if (rand_seed >= 0) {
    random_generator_ = new Random(rand_seed);
  } else {
    random_generator_ = new Random(time(NULL));
  }
}
static int stress_set_stream_index(const char *opt)
{
	uint32_t stream_index;

	stream_index = get_int32(opt);
	check_range("stream-index", stream_index, 0, 3);
	return set_setting("stream-index", TYPE_ID_UINT32, &stream_index);
}
 int ListBlockMessage::parse(char* data, int32_t len)
 {
   if (get_int32(&data, &len, &type_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   return TFS_SUCCESS;
 }
Exemple #19
0
int32 * mygetint32(const char *id)
{
	num32 address = 0;
	address = get_idHash(id);
	if(!address)
		return NULL;
	return get_int32(&int32my,address);
}
    int RespWriteDataMessage::parse(char* data, int32_t len)
    {
      if (get_int32(&data, &len, &length_) == TFS_ERROR)
      {
        return TFS_ERROR;
      }

      return TFS_SUCCESS;
    }
    int ResetBlockVersionMessage::parse(char* data, int32_t len)
    {
      if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&block_id_)) == TFS_ERROR)
      {
        return TFS_ERROR;
      }

      return TFS_SUCCESS;
    }
    int WriteInfoBatchMessage::parse(char* data, int32_t len)
    {
      if (get_object_copy(&data, &len, reinterpret_cast<void*>(&write_data_info_), sizeof(WriteDataInfo)) == TFS_ERROR)
      {
        return TFS_ERROR;
      }

      int32_t have_block = 0;
      if (get_int32(&data, &len, &have_block) == TFS_ERROR)
      {
        have_block = 0;
      }

      if (have_block > 0)
      {
        if (get_object(&data, &len, reinterpret_cast<void**>(&block_info_), BLOCKINFO_SIZE) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
      }

      int32_t size = 0;
      if (get_int32(&data, &len, &size) == TFS_ERROR)
      {
        return TFS_ERROR;
      }
      int32_t i = 0;
      for (i = 0; i < size; i++)
      {
        RawMeta raw_meta;
        if (get_object_copy(&data, &len, reinterpret_cast<void*> (&raw_meta), RAW_META_SIZE) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
        meta_list_.push_back(raw_meta);
      }

      if (get_int32(&data, &len, &cluster_) == TFS_ERROR)
      {
        return TFS_ERROR;
      }

      return TFS_SUCCESS;
    }
    int UpdateBlockInfoMessage::parse(char* data, int32_t len)
    {
      if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&block_id_)) == TFS_ERROR)
      {
        return TFS_ERROR;
      }

      if (get_int64(&data, &len, reinterpret_cast<int64_t*> (&server_id_)) == TFS_ERROR)
      {
        return TFS_ERROR;
      }

      int32_t have_block = 0;
      if (get_int32(&data, &len, &have_block) == TFS_ERROR)
      {
        have_block = 0;
      }
      if (have_block)
      {
        if (get_object(&data, &len, reinterpret_cast<void**> (&block_info_), BLOCKINFO_SIZE) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
      }
      if (get_int32(&data, &len, &repair_) == TFS_ERROR)
      {
        return TFS_ERROR;
      }
      int32_t have_sdbm = 0;
      if (get_int32(&data, &len, &have_sdbm) == TFS_ERROR)
      {
        have_sdbm = 0;
      }
      if (have_sdbm > 0)
      {
        if (get_object(&data, &len, reinterpret_cast<void**> (&db_stat_), sizeof(SdbmStat)) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
      }

      return TFS_SUCCESS;
    }
Exemple #24
0
SLsmg_Char_Type *decode_smg_char_type(char **buf)
{
    static SLsmg_Char_Type mbuf[256];
    int i;
    char *b = *buf;
    int len = get_int32(*buf); *buf+=4;
    for(i=0; i<len; i++) {
	mbuf[i++] =  get_int16(*buf); *buf+=2;
    }
    return mbuf;
}
    int SetServerStatusMessage::get_int_map(char** data, int32_t* len, std::set<uint32_t>* map)
    {
      int32_t i = 0;
      int32_t size = 0;
      uint32_t id;

      if (get_int32(data, len, &size) == TFS_ERROR)
      {
        return TFS_ERROR;
      }
      for (i = 0; i < size; i++)
      {
        if (get_int32(data, len, reinterpret_cast<int*> (&id)) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
        map->insert(id);
      }
      return TFS_SUCCESS;
    }
    int RespListBitMapMessage::parse(char* data, int32_t len)
    {
      if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&uuse_len_)) == TFS_ERROR)
      {
        return TFS_ERROR;
      }
      if (get_int32(&data, &len, reinterpret_cast<int32_t*> (&ubitmap_len_)) == TFS_ERROR)
      {
        return TFS_ERROR;
      }

      if (ubitmap_len_ > 0)
      {
        if (get_object(&data, &len, reinterpret_cast<void**> (&data_), ubitmap_len_) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
      }
      return TFS_SUCCESS;
    }
 int AccessStatInfoMessage::parse(char* data, int32_t len)
 {
   if (get_int32(&data, &len, &has_next_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_counter_map(&data, &len, stats_))
   {
     return TFS_ERROR;
   }
   return TFS_SUCCESS;
 }
    int AccessStatInfoMessage::get_counter_map(char** data, int32_t* len, COUNTER_TYPE & map)
    {
      int32_t i = 0;
      int32_t size = 0;
      uint32_t server_id = 0;
      Throughput count;

      if (get_int32(data, len, &size) == TFS_ERROR)
        return TFS_ERROR;
      for (i = 0; i < size; ++i)
      {
        if (get_int32(data, len, (int32_t*) &server_id) == TFS_ERROR)
          return TFS_ERROR;
        if (get_object_copy(data, len, reinterpret_cast<void*> (&count), sizeof(Throughput)) == TFS_ERROR)
        {
          return TFS_ERROR;
        }
        map.insert(COUNTER_TYPE::value_type(server_id, count));
      }
      return TFS_SUCCESS;
    }
Exemple #29
0
void
get_p32string_into(buffer *b, char *dest, int max_size)
{
	int size;

	size = get_int32(b);
	Assert(b->ptr + sizeof(uint32_t) + size <= b->fill_size);
	Assert(size + 1 <= max_size);
	memcpy(dest, (void*) BUFFER_POS(b), size);
	dest[size] = 0;
	b->ptr += size;
}
 int RespHeartMessage::parse(char* data, int32_t len)
 {
   if (get_int32(&data, &len, &status_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_int32(&data, &len, &sync_mirror_status_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_vint32(&data, &len, expire_blocks_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   if (get_vint32(&data, &len, new_blocks_) == TFS_ERROR)
   {
     return TFS_ERROR;
   }
   //	TBSYS_LOG(DEBUG,"heart status = %d,len = %d",status_,len);
   return TFS_SUCCESS;
 }