Example #1
0
int demo::DelayResponse::svc() {

  while (1) {
    MessageBlock* mb;
    if (this->getq(mb) == -1)
      return -1;

    HelloContext* context = (HelloContext*) mb->base();
    static int i = 1;
    OS::sleep(++i % 5);
    //OS::sleep(10);

    string msg = context->msg;
    Short u = context->u;
    demo::AMH_MyHello_sayHello* cb = context->cb;

    std::string ret = "return from ";
    ret += msg;
    u++;
    cout << "responsing, ret = " << ret << ", u = " << u << endl;
    cb->response(ret, u);

    delete context;
    delete mb;
  }

  return 0;
}
Example #2
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;
}
Example #3
0
int demo::DelayResponse::svc() {

  while (1) {
    MessageBlock* mb;
    if (this->getq(mb) == -1)
      return -1;

    Context* context = (Context*) mb->base();
    OS::sleep(15);

    string msg = context->msg;
    Short u = context->u;
    demo::AMH_MyHello_sayBye* cb = context->cb;

    std::cout << "recv msg:" << msg << std::endl;
    std::cout << "u:" << u << std::endl;

    std::string ret = "return from ";
    ret += msg;
    u++;
    cb->response(ret, u);

    delete context;
  }

  return 0;
}
Example #4
0
void demo::AmhMyHelloI::testCompound_async(demo::AMH_MyHello_testCompound* cb, const ::demo::TestReqCom& req) {
  TestComContext* context = new TestComContext;
  context->req = req;
  context->cb = cb;

  MessageBlock* mb = new MessageBlock;
  mb->base((char*) context, sizeof(HelloContext*));
  delayResponse->putq(mb);
}
Example #5
0
void demo::AmhMyHelloI::sayBye_async(demo::AMH_MyHello_sayBye* cb, const ::std::string& msg, Short u) {
  Context* context = new Context;
  context->msg = msg;
  context->u = u;
  context->cb = cb;

  MessageBlock* mb = new MessageBlock;
  mb->base((char*) context, sizeof(Context*));
  delayResponse->putq(mb);
}
Example #6
0
void demo::AmhMyHelloI::sayHello_async(demo::AMH_MyHello_sayHello* cb, const ::std::string& msg, Short u) {
  std::cout << "recv msg:" << msg << std::endl;
  std::cout << "u:" << u << std::endl;

  HelloContext* context = new HelloContext;
  context->msg = msg;
  context->u = u;
  context->cb = cb;

  MessageBlock* mb = new MessageBlock;
  mb->base((char*) context, sizeof(HelloContext*));
  delayResponse->putq(mb);
}
Example #7
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;
}
Example #8
0
  virtual int svc (void)
  {
    while (1) {
      MessageBlock* mb;
      if(this->getq (mb) == -1)
        break;

      const char *db = mb->base ();
      int m = *((int *)db);
      //cout << "recv data: " << m << endl;
      LogMsg << "recv data: " << m << endl;

      delete db;
      delete mb;
    }

    return 0;
  }
Example #9
0
int demo::DelayResponse::svc() {

  while (1) {
    MessageBlock* mb;
    if (this->getq(mb) == -1)
      return -1;

//    OS::sleep(3);

    Context* context = (Context*) mb->base();
    HelloContext* helloContext = dynamic_cast<HelloContext*>(context);
    TestSequenceContext* testSequenceContext = dynamic_cast<TestSequenceContext*>(context);
    TestDictContext* testDictContext = dynamic_cast<TestDictContext*>(context);
    TestComContext* testComContext = dynamic_cast<TestComContext*>(context);
    if(helloContext != 0) {
      string msg = helloContext->msg;
      Short u = helloContext->u;
      demo::AMH_MyHello_sayHello* cb = helloContext->cb;

      std::cout << "recv msg:" << msg << std::endl;
      std::cout << "u:" << u << std::endl;

      std::string ret = "return from ";
      ret += msg;
      u++;
      cb->response(ret, u);
    } else if(testSequenceContext != 0) {
      testSequenceContext->cb->response(testSequenceContext->req.toString());
    } else if(testDictContext != 0) {
      testDictContext->cb->response(testDictContext->req.toString());
    } else if(testComContext != 0) {
      testComContext->cb->response(testComContext->req.toString());
    } else {
      assert(false);
    }

    delete context;
    delete mb;
  }

  return 0;
}
Example #10
0
int main(int argc, char* argv[]) {
  char buf[512];
  memset(buf,1,512);
  InputStream is(buf,512);
  is.grow(20);

  int i = 123;
  is.read_int(i);

  //std::string str = "abc";
  //is.read_string(str);

  //OutputStream* os = new OutputStream((MessageBlock*)is.start());
  MessageBlock* mb = (MessageBlock*)is.start();
  mb->rdPtr(mb->base());

  OutputStream* os = new OutputStream(mb);

  return 0;
}
Example #11
0
  virtual int svc (void)
  {
/*
    char *buffer = new char[64];
    memset (buffer, 0, 64);
    strcpy (buffer, "hello,world");

    MessageBlock *mb = new MessageBlock;
    mb->setDataBlock (buffer);
    this->peerTask.putq (mb);
*/
    for (int i = 1000; i < 1020; i++) {
      int* m = new int;
      *m = i;
      MessageBlock *mb = new MessageBlock;
      mb->base ((char *)m, sizeof(int));
      this->peerTask.putq (mb);
      LogMsg << "send data: " << i << endl;
      OS::sleep (1);
    }

    return 0;
  }
Example #12
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;
}
Example #13
0
bool PMSource::getNextMessageBlock(MessageBlock& mBlock)
{
  std::streamsize bytesRead = 0;
  switch (m_Status)
  {
    case psUnpadded:
         m_BufStream.read((char*) &(mBlock.words[0]), 64);
         bytesRead = m_BufStream.gcount();
         if (bytesRead==64)
         {
           m_BitsRead += 512;
           mBlock.reverseBlock();
           return true;
         }
         //not full block read
         m_BitsRead += (bytesRead * 8);
         //close file, we are done here with reading from file anyway
         //m_BufStream.close(); // no close, since this will take care of itself in destructor
         //add 1-bit (start of message padding)
         ((uint8_t*) &(mBlock.words[0]))[bytesRead] = 0x80;
         //zero out rest of message block
         memset(&(((uint8_t*) &(mBlock.words[0]))[bytesRead+1]), 0, 64 - (bytesRead+1));
         //pad size value in there, too, if possible
         if (bytesRead+1<=56)
         {
           #if BYTE_ORDER == LITTLE_ENDIAN
           reverse64(m_BitsRead, m_BitsRead);
           #endif
           memcpy(&(mBlock.words[14]), &m_BitsRead, 8);
           m_Status = psPaddedAndAllRead;
           mBlock.reverseBlock();
           return true;
         }
         m_Status = psPadded1024And512Read;
         mBlock.reverseBlock();
         return true;
         break;
    case psPadded1024And512Read:
         //fill all with zeros (padding)
         memset(&(mBlock.words[0]), 0, 64);
         //pad size value in there, too
         #if BYTE_ORDER == LITTLE_ENDIAN
         reverse64(m_BitsRead, m_BitsRead);
         #endif
         memcpy(&(mBlock.words[14]), &m_BitsRead, 8);
         m_Status = psPaddedAndAllRead;
         mBlock.reverseBlock();
         return true;
         break;
    case psPaddedAndAllRead:
         return false;
         break;
    case psPadded512:
    case psPadded1024:
         //We should never get to this point!
         throw std::logic_error("PMSource::getNextMessageBlock(): Code execution should never get to this point!");
         return false;
         break;
  }//swi
  //We should never get to this point either!
  throw std::logic_error("PMSource::getNextMessageBlock(): Code execution should never get to this point either!");
  return false;
}