Пример #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;
}
Пример #2
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;
}
Пример #3
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);
}
Пример #4
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);
}
Пример #5
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);
}
Пример #6
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;
  }
Пример #7
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;
}
Пример #8
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;
}
Пример #9
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;
  }