Example #1
0
/* <string> <index> <int> put - */
static int
zput(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr op1 = op - 1;
    os_ptr op2 = op1 - 1;
    byte *sdata;
    uint ssize;

    switch (r_type(op2)) {
	case t_dictionary:
	    if (i_ctx_p->in_superexec == 0)
		check_dict_write(*op2);
	    {
		int code = idict_put(op2, op1, op);

		if (code < 0)
		    return code;	/* error */
	    }
	    break;
	case t_array:
	    check_write(*op2);
	    check_int_ltu(*op1, r_size(op2));
	    store_check_dest(op2, op);
	    {
		ref *eltp = op2->value.refs + (uint) op1->value.intval;

		ref_assign_old(op2, eltp, op, "put");
	    }
	    break;
	case t_mixedarray:	/* packed arrays are read-only */
	case t_shortarray:
	    return_error(e_invalidaccess);
	case t_string:
	    sdata = op2->value.bytes;
	    ssize = r_size(op2);
str:	    check_write(*op2);
	    check_int_ltu(*op1, ssize);
	    check_int_leu(*op, 0xff);
	    sdata[(uint)op1->value.intval] = (byte)op->value.intval;
	    break;
	case t_astruct:
	    if (gs_object_type(imemory, op2->value.pstruct) != &st_bytes)
		return_error(e_typecheck);
	    sdata = r_ptr(op2, byte);
	    ssize = gs_object_size(imemory, op2->value.pstruct);
	    goto str;
	default:
	    return_op_typecheck(op2);
    }
    pop(3);
    return 0;
}
Example #2
0
void LLVOCache::writeCacheHeader()
{
	if (!mEnabled)
	{
		llwarns << "Not writing cache header: Cache is currently disabled." << llendl;
		return;
	}

	if(mReadOnly)
	{
		llwarns << "Not writing cache header: Cache is currently in read-only mode." << llendl;
		return;
	}

	bool success = true ;
	{
		LLAPRFile apr_file(mHeaderFileName, APR_CREATE|APR_WRITE|APR_BINARY, mLocalAPRFilePoolp);

		//write the meta element
		success = check_write(&apr_file, &mMetaInfo, sizeof(HeaderMetaInfo)) ;


		mNumEntries = 0 ;	
		for(header_entry_queue_t::iterator iter = mHeaderEntryQueue.begin() ; success && iter != mHeaderEntryQueue.end(); ++iter)
		{
			(*iter)->mIndex = mNumEntries++ ;
			success = check_write(&apr_file, (void*)*iter, sizeof(HeaderEntryInfo));
		}
	
		mNumEntries = mHeaderEntryQueue.size() ;
		if(success && mNumEntries < MAX_NUM_OBJECT_ENTRIES)
		{
			HeaderEntryInfo* entry = new HeaderEntryInfo() ;
			entry->mTime = INVALID_TIME ;
			for(S32 i = mNumEntries ; success && i < MAX_NUM_OBJECT_ENTRIES ; i++)
			{
				//fill the cache with the default entry.
				success = check_write(&apr_file, entry, sizeof(HeaderEntryInfo)) ;			

			}
			delete entry ;
		}
	}

	if(!success)
	{
		clearCacheInMemory() ;
		mReadOnly = TRUE ; //disable the cache.
	}
	return ;
}
Example #3
0
/* <bytestring1> <index> <string2> putinterval - */
static int
zputinterval(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr opindex = op - 1;
    os_ptr opto = opindex - 1;
    int code;

    switch (r_type(opto)) {
	default:
            return_error(e_typecheck);
        case t__invalid:
            if (r_type(op) != t_array && r_type(op) != t_string && r_type(op) != t__invalid)
                return_error(e_typecheck); /* to match Distiller */
            else
                return_error(e_stackunderflow);
	case t_mixedarray:
	case t_shortarray:
	    return_error(e_invalidaccess);
	case t_array:
	case t_string:
	    check_write(*opto);
	    check_int_leu(*opindex, r_size(opto));
	    code = copy_interval(i_ctx_p, opto, (uint)(opindex->value.intval),
				 op, "putinterval");
	    break;
	case t_astruct: {
	    uint dsize, ssize, index;

	    check_write(*opto);
	    if (gs_object_type(imemory, opto->value.pstruct) != &st_bytes)
		return_error(e_typecheck);
	    dsize = gs_object_size(imemory, opto->value.pstruct);
	    check_int_leu(*opindex, dsize);
	    index = (uint)opindex->value.intval;
	    check_read_type(*op, t_string);
	    ssize = r_size(op);
	    if (ssize > dsize - index)
		return_error(e_rangecheck);
	    memcpy(r_ptr(opto, byte) + index, op->value.const_bytes, ssize);
	    code = 0;
	    break;
	}
    }
    if (code >= 0)
	pop(3);
    return code;
}
Example #4
0
static void read_cb(struct ev_loop *loop, struct ev_io *w, int revents)
{ 
	
	struct client *cli = (struct client *)w;
	int n = 0;
	char rbuff[5];
	assert(revents == EV_READ);
	for (;;) {
		n = check_read(cli->fd, rbuff, sizeof(rbuff));
		if (n <= 0) {
			break;
		} else {
			// echo
			int s_n = check_write(cli->fd, rbuff, n);
			if (s_n < n) {
				printf("send buffer full\n");
				break;
			}
			if (s_n < 0) {
				// something err
				break;
			}
		}
		//sleep(1);
	}
	printf("ECHO OVER\n");

	ev_io_stop(EV_A_ w);
 	close(cli->fd);
	free(cli);

	
}
Example #5
0
/* <gstate> currentgstate <gstate> */
int
zcurrentgstate(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    gs_state *pgs;
    int_gstate *pistate;
    int code;
    gs_memory_t *mem;

    check_stype(*op, st_igstate_obj);
    check_write(*op);
    code = gstate_unshare(i_ctx_p);
    if (code < 0)
	return code;
    pgs = igstate_ptr(op);
    pistate = gs_int_gstate(pgs);
    code = gstate_check_space(i_ctx_p, istate, r_space(op));
    if (code < 0)
	return code;
#define gsref_save(p) ref_save(op, p, "currentgstate")
    int_gstate_map_refs(pistate, gsref_save);
#undef gsref_save
    mem = gs_state_swap_memory(pgs, imemory);
    code = gs_currentgstate(pgs, igs);
    gs_state_swap_memory(pgs, mem);
    if (code < 0)
	return code;
    int_gstate_map_refs(pistate, ref_mark_new);
    return 0;
}
Example #6
0
TYPED_TEST_P(ChannelTest, write_Buffers) {
  auto_Object<Buffer> test_buffer = Buffer::copy(this->get_test_string());
  test_buffer->set_next_buffer(new Buffer(1));
  check_write(this->get_write_channel().write(*test_buffer));

  this->read();
}
Example #7
0
BOOL LLVOCache::updateEntry(const HeaderEntryInfo* entry)
{
	LLAPRFile apr_file(mHeaderFileName, APR_WRITE|APR_BINARY, mLocalAPRFilePoolp);
	apr_file.seek(APR_SET, entry->mIndex * sizeof(HeaderEntryInfo) + sizeof(HeaderMetaInfo)) ;

	return check_write(&apr_file, (void*)entry, sizeof(HeaderEntryInfo)) ;
}
Example #8
0
static int
push_execstack(i_ctx_t *i_ctx_p, os_ptr op1, bool include_marks,
               op_proc_t cont)
{
    uint size;
    /*
     * We can't do this directly, because the interpreter
     * might have cached some state.  To force the interpreter
     * to update the stored state, we push a continuation on
     * the exec stack; the continuation is executed immediately,
     * and does the actual transfer.
     */
    uint depth;

    if (!r_is_array(op1))
        return_op_typecheck(op1);
    /* Check the length before the write access per CET 28-03 */
    size = r_size(op1);
    depth = count_exec_stack(i_ctx_p, include_marks);
    if (depth > size)
        return_error(e_rangecheck);
    check_write(*op1);
    {
        int code = ref_stack_store_check(&e_stack, op1, size, 0);

        if (code < 0)
            return code;
    }
    check_estack(1);
    r_set_size(op1, depth);
    push_op_estack(cont);
    return o_push_estack;
}
Example #9
0
TYPED_TEST_P(ChannelTest, writev_one) {
  iovec iov;
  iov.iov_base = const_cast<char*>(this->get_test_string().data());
  iov.iov_len = this->get_test_string().size();
  check_write(this->get_write_channel().writev(&iov, 1));

  this->read();
}
Example #10
0
 void write() {
   check_write(
     get_write_channel().write(
       get_test_string().data(),
       get_test_string().size()
     )
   );
 }
Example #11
0
Status LocalDBWriter::file_write(const uint64_t& key, const Slice& value) {
    char* a = "xxxxxxxxxxxxxxxx";
    // 为了内存对齐,一个内存页应该放多少个内存索引key,仅仅想计算一次
    static uint64_t ssd_align_key = PAGESIZE / (sizeof(key_t) + sizeof(ssd_value_t));
    static uint64_t mem_align_key = PAGESIZE / (sizeof(key_t) + 
                                                sizeof(mem_value_t)) * ssd_align_key;
    if (_key_num != 0 && _key_num % mem_align_key == 0) {
    //    //printf("1_key%lu mem_align_key:%lu\n", key, mem_align_key);
        check_write(_mem_index_fd, a, 
                    PAGESIZE % (sizeof(key_t) + sizeof(mem_value_t)), _mem_file_off);
    }
    if (_key_num % ssd_align_key == 0) {
        // 知道为0,省去
        check_write(_mem_index_fd, &key, sizeof(key), _mem_file_off);
        uint32_t ssd_page_num = _key_num / ssd_align_key;
        check_write(_mem_index_fd, &ssd_page_num, sizeof(ssd_page_num), _mem_file_off);
    }
    check_write(_ssd_index_fd, &key, sizeof(key), _ssd_file_off);
    check_write(_ssd_index_fd, &_data_file_off, sizeof(_data_file_off), _ssd_file_off);
//    //printf("data off:%lu ssd off:%lu \n", _data_file_off, _ssd_file_off);

    uint32_t value_len = value.size();
    check_write(_data_file_fd, &value_len, sizeof(value_len), _data_file_off);
    check_write(_data_file_fd, value.data(), value_len, _data_file_off);
  //  //printf("data off:%lu \n", _data_file_off);

    return OK;
}
Example #12
0
BOOL LLVOCacheEntry::writeToFile(LLAPRFile* apr_file) const
{
	BOOL success;
	success = check_write(apr_file, (void*)&mLocalID, sizeof(U32));
	if(success)
	{
		success = check_write(apr_file, (void*)&mCRC, sizeof(U32));
	}
	if(success)
	{
		success = check_write(apr_file, (void*)&mHitCount, sizeof(S32));
	}
	if(success)
	{
		success = check_write(apr_file, (void*)&mDupeCount, sizeof(S32));
	}
	if(success)
	{
		success = check_write(apr_file, (void*)&mCRCChangeCount, sizeof(S32));
	}
	if(success)
	{
		S32 size = mDP.getBufferSize();
		success = check_write(apr_file, (void*)&size, sizeof(S32));
	
		if(success)
		{
			success = check_write(apr_file, (void*)mBuffer, size);
		}
	}

	return success ;
}
Example #13
0
 void _ByteArray::writeBytes(unsigned char *val, std::size_t size, std::size_t offset)
 {
     if(size==0) size=strlen((const char*)val);
     check_write(size);
     unsigned char *desByte = _bytes;
     desByte+=wPos;
     memcpy(desByte, val+offset, size);
     wPos += size;
 }
Example #14
0
TYPED_TEST_P(ChannelTest, writev_two) {
  iovec iov[2];
  iov[0].iov_base = const_cast<char*>(this->get_test_string().data());
  iov[0].iov_len = 4;
  iov[1].iov_base = const_cast<char*>(this->get_test_string().data()) + 4;
  iov[1].iov_len = this->get_test_string().size() - 4;
  check_write(this->get_write_channel().writev(iov, 2));

  this->read();
}
Example #15
0
bool check_write(int fd, void* data, ssize_t size) {
  if (write(fd, data, size) == size)
    return true;
  else {
    if (errno == EINTR)
      return check_write(fd, data, size);
    else
      return false;
  }
}
Example #16
0
void zmq::pipe_t::gap ()
{
    if (!check_write ()) {
        delayed_gap = true;
        return;
    }
    raw_message_t msg;
    raw_message_init_notification (&msg, raw_message_t::gap_tag);
    write (&msg);
    flush ();
}
Example #17
0
bool zmq::writer_t::write (zmq_msg_t *msg_)
{
    if (unlikely (!check_write (msg_)))
        return false;

    pipe->write (*msg_, msg_->flags & ZMQ_MSG_MORE);
    if (!(msg_->flags & ZMQ_MSG_MORE))
        msgs_written++;

    return true;
}
Example #18
0
BOOL LLVOCache::checkWrite(LLAPRFile* apr_file, void* src, S32 n_bytes) 
{
	if(!check_write(apr_file, src, n_bytes))
	{
		delete apr_file ;
		removeCache() ;
		return FALSE ;
	}

	return TRUE ;
}
Example #19
0
bool zmq::pipe_t::write (msg_t *msg_)
{
    if (unlikely (!check_write ()))
        return false;

    bool more = msg_->flags () & msg_t::more ? true : false;
    outpipe->write (*msg_, more);
    if (!more)
        msgs_written++;

    return true;
}
Example #20
0
static int
array_new_indexed_plist_write(dict_param_list * plist, ref * parray,
			      const ref * pwanted, gs_ref_memory_t *imem)
{
    check_array(*parray);
    check_write(*parray);
    plist->u.w.write = array_new_indexed_param_write;
    ref_param_write_init((iparam_list *) plist, pwanted, imem);
    plist->dict = *parray;
    plist->int_keys = true;
    return 0;
}
Example #21
0
bool zmq::pipe_t::write (msg_t *msg_)
{
    if (unlikely (!check_write ()))
        return false;

    const bool more = (msg_->flags () & msg_t::more) != 0;
    const bool is_routing_id = msg_->is_routing_id ();
    _out_pipe->write (*msg_, more);
    if (!more && !is_routing_id)
        _msgs_written++;

    return true;
}
Example #22
0
bool zmq::pipe_t::write (msg_t *msg_)
{
    if (unlikely (!check_write ()))
        return false;

    bool more = msg_->flags () & msg_t::more ? true : false;
    const bool is_identity = msg_->is_identity ();
    outpipe->write (*msg_, more);
    if (!more && !is_identity)
        msgs_written++;

    return true;
}
Example #23
0
void* stdin_loop(void* arg) {
  unsigned char buf[4096];
  bool loop_running = true;

  sigset_t mask;
  sigfillset(&mask);
  sigdelset(&mask, SIGUSR2);
  sigdelset(&mask, SIGTTIN);
  sigdelset(&mask, SIGTERM);
  sigdelset(&mask, SIGQUIT);
  pthread_sigmask(SIG_SETMASK, &mask, NULL);

  int unused;
  pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &unused);
  pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &unused);

  while (loop_running) {
    if (!safe_read(control_read, buf, 1))
      break;

    if (buf[0] != 'X')
      fatal_error("stdin_loop: bad data on control fd", buf[0]);

    for (;;) {
      /* If we fep, the parent thread will grab stdin_mutex and send us
         SIGUSR2 to interrupt the read() call. */
      pthread_mutex_lock(&stdin_mutex);
      pthread_mutex_unlock(&stdin_mutex);
      ssize_t bytes = read(0, buf, sizeof(buf));
      if (bytes < 0) {
        if (errno == EINTR)
          continue;
        else {
          loop_running = false;
          break;
        }
      } else if (bytes >= 0) {
        safe_write(size_write, &bytes, sizeof(bytes));

        if (!check_write(stdin_write, buf, bytes))
          loop_running = false;
        break;
      }
    }
  }

  safe_close(stdin_write);
  safe_close(control_read);

  return NULL;
}
Example #24
0
/* its length; nothing else has been checked. */
static int
copy_interval(i_ctx_t *i_ctx_p /* for ref_assign_old */, os_ptr prto,
	      uint index, os_ptr prfrom, client_name_t cname)
{
    int fromtype = r_type(prfrom);
    uint fromsize = r_size(prfrom);

    if (!(fromtype == r_type(prto) ||
	  ((fromtype == t_shortarray || fromtype == t_mixedarray) &&
	   r_type(prto) == t_array))
	)
	return_op_typecheck(prfrom);
    check_read(*prfrom);
    check_write(*prto);
    if (fromsize > r_size(prto) - index)
	return_error(e_rangecheck);
    switch (fromtype) {
	case t_array:
	    {			/* We have to worry about aliasing, */
		/* but refcpy_to_old takes care of it for us. */
		return refcpy_to_old(prto, index, prfrom->value.refs,
				     fromsize, idmemory, cname);
	    }
	case t_string:
	    {	/* memmove takes care of aliasing. */
		memmove(prto->value.bytes + index, prfrom->value.bytes,
			fromsize);
	    }
	    break;
	case t_mixedarray:
	case t_shortarray:
	    {	/* We don't have to worry about aliasing, because */
		/* packed arrays are read-only and hence the destination */
		/* can't be a packed array. */
		uint i;
		const ref_packed *packed = prfrom->value.packed;
		ref *pdest = prto->value.refs + index;
		ref elt;

		for (i = 0; i < fromsize; i++, pdest++) {
		    packed_get(imemory, packed, &elt);
		    ref_assign_old(prto, pdest, &elt, cname);
		    packed = packed_next(packed);
		}
	    }
	    break;
    }
    return 0;
}
Example #25
0
void zmq::pipe_t::set_head (uint64_t position_)
{
    //  This may cause the next write to succeed.
    in_core_msg_cnt -= position_ - last_head_position;
    last_head_position = position_;

    //  Transfer messages from the data dam into the main memory.
    if (swapping && in_core_msg_cnt < (size_t) lwm)
        swap_in ();

    //  If there's a gap notification waiting, push it into the queue.
    if (delayed_gap && check_write ()) {
        raw_message_t msg;
        raw_message_init_notification (&msg, raw_message_t::gap_tag);
        write (&msg);
        delayed_gap = false;
    }
}
Example #26
0
bool zmq::writer_t::write (zmq_msg_t *msg_)
{
    if (unlikely (!check_write (msg_)))
        return false;

    if (unlikely (swapping)) {
        bool stored = swap->store (msg_);
        zmq_assert (stored);
        if (!(msg_->flags & ZMQ_MSG_MORE))
            swap->commit ();
        return true;
    }

    pipe->write (*msg_, msg_->flags & ZMQ_MSG_MORE);
    if (!(msg_->flags & ZMQ_MSG_MORE))
        msgs_written++;

    return true;
}
Example #27
0
void *stdin_loop(void *arg)
{
	unsigned char buf[4096];
	bool loop_running = true;

	while(loop_running)
	{
		if(!safe_read(control_read,buf,1))
			break;

		if(buf[0] != 'X')
			fatal_error("stdin_loop: bad data on control fd",buf[0]);

		for(;;)
		{
			ssize_t bytes = read(0,buf,sizeof(buf));
			if(bytes < 0)
			{
				if(errno == EINTR)
					continue;
				else
				{
					loop_running = false;
					break;
				}
			}
			else if(bytes >= 0)
			{
				safe_write(size_write,&bytes,sizeof(bytes));

				if(!check_write(stdin_write,buf,bytes))
					loop_running = false;
				break;
			}
		}
	}

	safe_close(stdin_write);
	safe_close(control_read);

	return NULL;
}
Example #28
0
void zmq::writer_t::rollback ()
{
    if (extra_msg_flag && extra_msg.flags & ZMQ_MSG_MORE) {
        zmq_msg_close (&extra_msg);
        extra_msg_flag = false;
    }

    if (msg_store != NULL)
        msg_store->rollback ();

    zmq_msg_t msg;
    //  Remove all incomplete messages from the pipe.
    while (pipe->unwrite (&msg)) {
        zmq_assert (msg.flags & ZMQ_MSG_MORE);
        zmq_msg_close (&msg);
    }

    if (stalled && endpoint != NULL && check_write ()) {
        stalled = false;
        endpoint->revive (this);
    }
}
Example #29
0
bool zmq::writer_t::write (zmq_msg_t *msg_)
{
    if (!check_write ())
        return false;

    if (pipe_full ()) {
        if (msg_store->store (msg_)) {
            if (!(msg_->flags & ZMQ_MSG_MORE))
                msg_store->commit ();
        } else {
            extra_msg = *msg_;
            extra_msg_flag = true;
        }
    }
    else {
        pipe->write (*msg_, msg_->flags & ZMQ_MSG_MORE);
        if (!(msg_->flags & ZMQ_MSG_MORE))
            msgs_written++;
    }

    return true;
}
Example #30
0
/* copy for gstates */
int
zcopy_gstate(i_ctx_t *i_ctx_p)
{
    os_ptr op = osp;
    os_ptr op1 = op - 1;
    gs_state *pgs;
    gs_state *pgs1;
    int_gstate *pistate;
    gs_memory_t *mem;
    int code;

    check_stype(*op, st_igstate_obj);
    check_stype(*op1, st_igstate_obj);
    check_write(*op);
    code = gstate_unshare(i_ctx_p);
    if (code < 0)
	return code;
    pgs = igstate_ptr(op);
    pgs1 = igstate_ptr(op1);
    pistate = gs_int_gstate(pgs);
    code = gstate_check_space(i_ctx_p, gs_int_gstate(pgs1), r_space(op));
    if (code < 0)
	return code;
#define gsref_save(p) ref_save(op, p, "copygstate")
    int_gstate_map_refs(pistate, gsref_save);
#undef gsref_save
    mem = gs_state_swap_memory(pgs, imemory);
    code = gs_copygstate(pgs, pgs1);
    gs_state_swap_memory(pgs, mem);
    if (code < 0)
	return code;
    int_gstate_map_refs(pistate, ref_mark_new);
    *op1 = *op;
    pop(1);
    return 0;
}