示例#1
0
 virtual void run()
 {
   VHttpProxy* proxy = (VHttpProxy*)owner;
   LOG_DEBUG("stt"); // gilgil temp 2013.10.19
   while (true)
   {
     QByteArray msg;
     int readLen = outClient->tcpSession->read(msg);
     if (readLen == VERR_FAIL) break;
     emit proxy->beforeResponse(msg, outClient, inSession);
     int writeLen = inSession->write(msg);
     if (writeLen == VERR_FAIL) break;
    }
   inSession->close();
   outClient->close();
   LOG_DEBUG("end"); // gilgil temp 2013.10.19
 }
示例#2
0
bool VTcpServer::doClose()
{
  threadTag = 1011; // gilgil temp 2014.04.04
  VLock lock(stateCloseCs); // gilgil temp 2014.03.14
  threadTag = 1012; // gilgil temp 2014.04.04

  // ------------------------------------------------------------------------
  // Close acceptSession and thread
  // ------------------------------------------------------------------------
  acceptSession->close();
  runThread().close();


  threadTag = 1016; // gilgil temp 2014.04.04
  threadList.lock();
  // ------------------------------------------------------------------------
  // Close all connected socket
  // ------------------------------------------------------------------------
  for (VTcpSessionThreadList::iterator it = threadList.begin(); it != threadList.end(); it++)
  {
    VTcpSessionThread* thread = *it;
    // ----- by gilgil 2012.12.07 -----
    // When TcpServer is active, session thread is deleted automatically,
    // while, when TcpServer is closing state, session thread is deleted manually.
    // thread->freeOnTerminate = false; // gilgil temp 2012.12.07 // gilgil temp 2014.04.04
    // --------------------------------
    VTcpSession* tcpSession = thread->tcpSession;
    tcpSession->close();
  }
  threadList.unlock();
  threadTag = 1018; // gilgil temp 2014.04.04

  // ------------------------------------------------------------------------
  // Wait until all connection is disconnected
  // ------------------------------------------------------------------------
  VTick beg = tick();
  while (true)
  {
    msleep(1);
    threadList.lock();
    int count = threadList.count();
    threadList.unlock();
    if (count == 0) break;
    VTick now = tick();
    if (now - beg > vd::DEFAULT_TIMEOUT * 2) // gilgil temp 2014.04.04
    {
      LOG_FATAL("timeout session count=%d", threadList.count());
      // break; // gilgil temp 2012.11.27
    }
  }
  /*
  threadList.lock();
  int count = threadList.count();
  threaddList.un
  for (VTcpSessionThreadList::iterator it = threadList.begin(); it != threadList.end(); it++)
  {
    threadTag = 1020; // gilgil temp 2014.04.04
    VTcpSessionThread* thread = *it;
    threadTag = 1022; // gilgil temp 2014.04.04
    thread->wait(vd::DEFAULT_TIMEOUT + 2000); // gilgil temp 2014.04.04
    threadTag = 1023; // gilgil temp 2014.04.04
    delete thread;
    threadTag = 1024; // gilgil temp 2014.04.04
    VTick now = tick();
    if (now - beg > vd::DEFAULT_TIMEOUT * 2) // gilgil temp 2014.04.04
    {
      LOG_FATAL("timeout session count=%d", threadList.count());
      // break; // gilgil temp 2012.11.27
    }
    threadTag = 1025; // gilgil temp 2014.04.04
  }
  threadList.clear();
  threadList.unlock();
  threadTag = 1026; // gilgil temp 2014.04.04
  */

  return true;
}