Beispiel #1
0
ssize_t proto_h16::calc_size(MessageBlock& mb) const
{
	uint32_t sz;
	if (mb.size() < sizeof(sz)) {
		size_t left = sizeof(sz) - mb.size();
		memcpy(&sz, mb.rptr(), mb.size());

		MessageBlock* cont = mb.cont();
		if (cont != NULL && cont->size() >= left) {
			memcpy((byte *)&sz + mb.size(), cont->rptr(), left);
		}
		else {
			return 0;
		}
	}
	else {
		memcpy(&sz, mb.rptr(), sizeof(sz));
	}

	if (sz >= head_size() && sz >= min_ && sz <= max_)
		return sz;

	errno = EINVAL;
	return -1;
}
Beispiel #2
0
int Connection::split_block(size_t msize)
{
	//MessageRequest* sub;
	int retval = -1;
#if 1
	assert(0);
#else
	// TODO: need it?
	if (mreq_->size() > msize) {
		sub = mreq_->extract(msize);		
	}
	else {
		sub = mreq_;
		MessageBlock* mb = sub->cont();
		size_t left = msize - mreq_->size();
		while (left > 0) {
			if (left < mb->size()) {
				mreq_ = new MessageRequest(mb->dblock_);
				break;
			}
			else if (left == mb->size()) {
				mreq_ = new MessageRequest(mb->cont());
				mb->cont(NULL);
			}
			else {
				left -= mb->size();
				continue;
			}
		}
	}
	

	if (sub != NULL) {
		if ((retval = sched_->on_message(sub)) < 0) {
			SYSLOG_ERROR("%s drop sub message(len=%d, data=%s)",
				name(), (unsigned long)sub->tsize(),
				beyondy::toString((unsigned char *)sub->rptr(), std::min(16, sub->tsize())).c_str(),
				errno);
		}
	}
	else {
		retval = -1;
		SYSLOG_ERROR("%s extract sub message failed: %d", name(), errno);
	}
#endif
	return retval;
}
Beispiel #3
0
int
Simple_Tester::initiate_read_file (void)
{
    // Create Message_Block
    MessageBlock *mb = 0;
    ACE_NEW_RETURN (mb, MessageBlock (100 * 1024 + 1), -1);

    // Inititiate an asynchronous read from the file
    if (this->rf_.read (*mb,
                        mb->size () - 1) == -1)
        ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Asynch_Read_File::read"), -1);

    ACE_DEBUG ((LM_DEBUG,
                "Simple_Tester:initiate_read_file: Asynch Read File issued sucessfully\n"));

    return 0;
}