示例#1
0
void
dhashclient::retrievecb (cb_cret cb, bigint key, 
			 ref<dhash_retrieve_res> res, 
			 clnt_stat err)
{
  str errstr;
  dhash_stat ret (res->status);
  if (err) {
    errstr = strbuf () << "rpc error " << err;
    ret    = DHASH_RPCERR;
  }
  else if (res->status != DHASH_OK)
    errstr = dhasherr2str (res->status);
  else {
    str block_data (res->resok->block.base (), res->resok->block.size ());

    if (!verify (key, block_data, res->resok->ctype)) {
      errstr = strbuf () << "data did not verify. ctype " << res->resok->ctype;
      ret = DHASH_RETRIEVE_NOVERIFY;
    } else {
      // success
      vec<str> contents = get_block_contents (block_data, res->resok->ctype);

      ptr<dhash_block> blk;
      if (contents.size () == 1)
	blk = New refcounted<dhash_block> (contents[0],
					   res->resok->ctype);
      else {
	//assert (contents.size () > 0);
	if (contents.size() == 0) {
		vec<chordID> p;
  	(*cb) (DHASH_DBERR, NULL, p);
  }
	blk = New refcounted<dhash_block> (str (""),
					   res->resok->ctype);
	blk->vData = contents;
      }
	
      blk->hops = res->resok->hops;
      blk->errors = res->resok->errors;
      blk->retries = res->resok->retries;
      for (u_int i = 0; i < res->resok->times.size (); i++)
	blk->times.push_back (res->resok->times[i]);
  
      vec<chordID> path;
      for (u_int i = 0; i < res->resok->path.size (); i++)
	path.push_back (res->resok->path[i]);
  
      (*cb) (DHASH_OK, blk, path);
      return;
    } 
  }

  warn << "dhashclient::retrieve failed: " << key << ": " << errstr << "\n";
  vec<chordID> e_path;
  (*cb) (ret, NULL, e_path); 
}
示例#2
0
void* malloc(size_t s){
    // check for 0 size
    if(s == 0)
        return null;
    // add size of size_t as we need to save size of memory block
    s += sizeof(size_t);
    // find suitable memory size
    size_t ns = find_optimal_memory_size(s);

    // if size is greater than or equals MMAP_SIZE we are going to use mmap
    if(ns >= MMAP_SIZE){
        void* m = mmap(NULL,s,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0);    
        if(m == MAP_FAILED)
            return null;
        memory_block* b = (memory_block*)m;
        b->size = s;
        lock
        mmap_size += s;
        unlock
        return block_data(b);
    }