亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? http_server.cpp

?? 一個開源的網絡開發庫ACE
?? CPP
字號:
// HTTP_Server.cpp,v 1.41 2001/12/26 15:46:24 schmidt Exp

#define ACE_BUILD_SVC_DLL

#include "ace/Get_Opt.h"
#include "ace/Asynch_Acceptor.h"
#include "ace/LOCK_SOCK_Acceptor.h"
#include "ace/Proactor.h"

#include "IO.h"
#include "HTTP_Server.h"

ACE_RCSID(server, HTTP_Server, "HTTP_Server.cpp,v 1.41 2001/12/26 15:46:24 schmidt Exp")

// class is overkill
class JAWS
{
public:
  enum
  {
    POOL = 0,
    PER_REQUEST = 1
  };

  enum
  {
    SYNCH = 0,
    ASYNCH = 2
  };
};

void
HTTP_Server::parse_args (int argc,
			 char *argv[])
{
  int c;
  int thr_strategy = 0;
  int io_strategy = 0;
  const char *prog = argc > 0 ? argv[0] : "HTTP_Server";

  // Set some defaults
  this->port_ = 0;
  this->threads_ = 0;
  this->backlog_ = 0;
  this->throttle_ = 0;

  ACE_Get_Opt get_opt (argc, argv, "p:n:t:i:b:");

  while ((c = get_opt ()) != -1)
    switch (c)
      {
      case 'p':
	this->port_ = ACE_OS::atoi (get_opt.opt_arg ());
	break;
      case 'n':
	this->threads_ = ACE_OS::atoi (get_opt.opt_arg ());
	break;
      case 't':
	// POOL        -> thread pool
	// PER_REQUEST -> thread per request
	// THROTTLE    -> thread per request with throttling
        if (ACE_OS::strcmp (get_opt.opt_arg (), "POOL") == 0)
          thr_strategy = JAWS::POOL;
        else if (ACE_OS::strcmp (get_opt.opt_arg (), "PER_REQUEST") == 0)
          {
            thr_strategy = JAWS::PER_REQUEST;
            this->throttle_ = 0;
          }
        else if (ACE_OS::strcmp (get_opt.opt_arg (), "THROTTLE") == 0)
          {
            thr_strategy = JAWS::PER_REQUEST;
            this->throttle_ = 1;
          }
	break;
      case 'f':
        if (ACE_OS::strcmp (get_opt.opt_arg (), "THR_BOUND") == 0)
          {
            // What happened here?
          }
        else if (ACE_OS::strcmp (get_opt.opt_arg (), "THR_DAEMON") == 0)
          {
          }
        else if (ACE_OS::strcmp (get_opt.opt_arg (), "THR_DETACHED") == 0)
          {
          }
      case 'i':
	// SYNCH  -> synchronous I/O
	// ASYNCH -> asynchronous I/O
        if (ACE_OS::strcmp (get_opt.opt_arg (), "SYNCH") == 0)
          io_strategy = JAWS::SYNCH;
        else if (ACE_OS::strcmp (get_opt.opt_arg (), "ASYNCH") == 0)
          io_strategy = JAWS::ASYNCH;
	break;
      case 'b':
	this->backlog_ = ACE_OS::atoi (get_opt.opt_arg ());
	break;
      default:
	break;
      }

  // No magic numbers.
  if (this->port_ <= 0)
    this->port_ = 5432;
  if (this->threads_ <= 0)
    this->threads_ = 5;
  // Don't use number of threads as default
  if (this->backlog_ <= 0)
    this->backlog_ = this->threads_;

  this->strategy_ = thr_strategy | io_strategy;

  ACE_UNUSED_ARG (prog);
  ACE_DEBUG ((LM_DEBUG,
              "in HTTP_Server::init, %s port = %d, number of threads = %d\n",
              prog, this->port_, this->threads_));
}

int
HTTP_Server::init (int argc, char *argv[])
  // Document this function
{
  // Ignore signals generated when a connection is broken unexpectedly.
  ACE_Sig_Action sig ((ACE_SignalHandler) SIG_IGN, SIGPIPE);
  ACE_UNUSED_ARG (sig);

  // Parse arguments which sets the initial state.
  this->parse_args (argc, argv);

  // Choose what concurrency strategy to run.
  switch (this->strategy_)
    {
    case (JAWS::POOL | JAWS::ASYNCH) :
      return this->asynch_thread_pool ();

    case (JAWS::PER_REQUEST | JAWS::SYNCH) :
      return this->thread_per_request ();

    case (JAWS::POOL | JAWS::SYNCH) :
    default:
      return this->synch_thread_pool ();
    }

  ACE_NOTREACHED (return 0);
}

int
HTTP_Server::fini (void)
{
  this->tm_.close ();
  return 0;
}


int
HTTP_Server::synch_thread_pool (void)
{
  // Main thread opens the acceptor
  if (this->acceptor_.open (ACE_INET_Addr (this->port_), 1,
                            PF_INET, this->backlog_) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "HTTP_Acceptor::open"), -1);

  // Create a pool of threads to handle incoming connections.
  Synch_Thread_Pool_Task t (this->acceptor_, this->tm_, this->threads_);

  this->tm_.wait ();
  return 0;
}

Synch_Thread_Pool_Task::Synch_Thread_Pool_Task (HTTP_Acceptor &acceptor,
                                                ACE_Thread_Manager &tm,
                                                int threads)
  : ACE_Task<ACE_NULL_SYNCH> (&tm),
    acceptor_ (acceptor)
{
  if (this->activate (THR_DETACHED | THR_NEW_LWP, threads) == -1)
    ACE_ERROR ((LM_ERROR, "%p\n", "Synch_Thread_Pool_Task::open"));
}

int
Synch_Thread_Pool_Task::svc (void)
{
  // Creates a factory of HTTP_Handlers binding to synchronous I/O strategy
  Synch_HTTP_Handler_Factory factory;

  for (;;)
    {
      ACE_SOCK_Stream stream;

      // Lock in this accept.  When it returns, we have a connection.
      if (this->acceptor_.accept (stream) == -1)
	ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "HTTP_Acceptor::accept"), -1);

      ACE_Message_Block *mb;
      ACE_NEW_RETURN (mb,
                      ACE_Message_Block (HTTP_Handler::MAX_REQUEST_SIZE + 1),
                      -1);

      // Create an HTTP Handler to handle this request
      HTTP_Handler *handler = factory.create_http_handler ();
      handler->open (stream.get_handle (), *mb);
      // Handler is destroyed when the I/O puts the Handler into the
      // done state.

      mb->release ();
      ACE_DEBUG ((LM_DEBUG,
                  " (%t) in Synch_Thread_Pool_Task::svc, recycling\n"));
    }

  ACE_NOTREACHED(return 0);
}

int
HTTP_Server::thread_per_request (void)
{
  int grp_id = -1;

  // thread per request
  // Main thread opens the acceptor
  if (this->acceptor_.open (ACE_INET_Addr (this->port_), 1,
                            PF_INET, this->backlog_) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "HTTP_Acceptor::open"), -1);

  ACE_SOCK_Stream stream;

  // When we are throttling, this is the amount of time to wait before
  // checking for runnability again.
  const ACE_Time_Value wait_time (0, 10);

  for (;;)
    {
      if (this->acceptor_.accept (stream) == -1)
	ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "HTTP_Acceptor::accept"), -1);

      Thread_Per_Request_Task *t;
      // Pass grp_id as a constructor param instead of into open.
      ACE_NEW_RETURN (t, Thread_Per_Request_Task (stream.get_handle (),
                                                  this->tm_,
                                                  grp_id),
                      -1);


      if (t->open () != 0)
	ACE_ERROR_RETURN ((LM_ERROR,
                           "%p\n", "Thread_Per_Request_Task::open"),
                          -1);

      // Throttling is not allowing too many threads to run away.
      // Should really use some sort of condition variable here.
      if (!this->throttle_)
	continue;

      // This works because each task has only one thread.
      while (this->tm_.num_tasks_in_group (grp_id) > this->threads_)
	this->tm_.wait (&wait_time);
    }

  ACE_NOTREACHED(return 0);
}

Thread_Per_Request_Task::Thread_Per_Request_Task (ACE_HANDLE handle,
						  ACE_Thread_Manager &tm,
                                                  int &grp_id)
  : ACE_Task<ACE_NULL_SYNCH> (&tm),
    handle_ (handle),
    grp_id_ (grp_id)
{
}


// HEY!  Add a method to the thread_manager to return total number of
// threads managed in all the tasks.

int
Thread_Per_Request_Task::open (void *)
{
  int status = -1;

  if (this->grp_id_ == -1)
    status = this->grp_id_ = this->activate (THR_DETACHED | THR_NEW_LWP);
  else
    status = this->activate (THR_DETACHED | THR_NEW_LWP,
                             1, 0, -1, this->grp_id_, 0);

  if (status == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "Thread_Per_Request_Task::open"),
                      -1);
  return 0;
}

int
Thread_Per_Request_Task::svc (void)
{
  ACE_Message_Block *mb;
  ACE_NEW_RETURN (mb, ACE_Message_Block (HTTP_Handler::MAX_REQUEST_SIZE + 1),
                  -1);
  Synch_HTTP_Handler_Factory factory;
  HTTP_Handler *handler = factory.create_http_handler ();
  handler->open (this->handle_, *mb);
  mb->release ();
  return 0;
}

int
Thread_Per_Request_Task::close (u_long)
{
  ACE_DEBUG ((LM_DEBUG,
	      " (%t) Thread_Per_Request_Task::svc, dying\n"));
  delete this;
  return 0;
}

// Understanding the code below requires understanding of the
// WindowsNT asynchronous completion notification mechanism and the
// Proactor Pattern.

// (1) The application submits an asynchronous I/O request to the
//     operating system and a special handle with it (Asynchronous
//     Completion Token).
// (2) The operating system commits to performing the I/O request,
//     while application does its own thing.
// (3) Operating system finishes the I/O request and places ACT onto
//     the I/O Completion Port, which is a queue of finished
//     asynchronous requests.
// (4) The application eventually checks to see if the I/O request
//     is done by checking the I/O Completion Port, and retrieves the
//     ACT.

int
HTTP_Server::asynch_thread_pool (void)
{
// This only works on Win32
#if defined (ACE_WIN32)
  // Create the appropriate acceptor for this concurrency strategy and
  // an appropriate handler for this I/O strategy
  ACE_Asynch_Acceptor<Asynch_HTTP_Handler_Factory> acceptor;

  // Tell the acceptor to listen on this->port_, which makes an
  // asynchronous I/O request to the OS.
  if (acceptor.open (ACE_INET_Addr (this->port_),
		     HTTP_Handler::MAX_REQUEST_SIZE + 1) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "%p\n",
                       "ACE_Asynch_Acceptor::open"), -1);

  // Create the thread pool.
  // Register threads with the proactor and thread manager.
  Asynch_Thread_Pool_Task t (*ACE_Proactor::instance (),
                             this->tm_);

  // The proactor threads are waiting on the I/O Completion Port.

  // Wait for the threads to finish.
  return this->tm_.wait ();
#endif /* ACE_WIN32 */
  return -1;
}

// This only works on Win32
#if defined (ACE_WIN32)

Asynch_Thread_Pool_Task::Asynch_Thread_Pool_Task (ACE_Proactor &proactor,
                                                  ACE_Thread_Manager &tm)
  : ACE_Task<ACE_NULL_SYNCH> (&tm),
    proactor_ (proactor)
{
  if (this->activate () == -1)
    ACE_ERROR ((LM_ERROR, "%p\n", "Asynch_Thread_Pool_Task::open"));
}

int
Asynch_Thread_Pool_Task::svc (void)
{
  for (;;)
    if (this->proactor_.handle_events () == -1)
      ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Proactor::handle_events"),
                        -1);

  return 0;
}

#endif /* ACE_WIN32 */

// Define the factory function.
ACE_SVC_FACTORY_DEFINE (HTTP_Server)

// Define the object that describes the service.
ACE_STATIC_SVC_DEFINE (HTTP_Server, "HTTP_Server", ACE_SVC_OBJ_T,
                       &ACE_SVC_NAME (HTTP_Server),
                       ACE_Service_Type::DELETE_THIS
                       | ACE_Service_Type::DELETE_OBJ, 0)

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
template class ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_MUTEX>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_LOCK_SOCK_Acceptor<ACE_SYNCH_MUTEX>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲精品高清视频在线观看| 99国产精品99久久久久久| 国产精品一区二区三区网站| 92精品国产成人观看免费| 日韩三级免费观看| 亚洲男人电影天堂| 国产91富婆露脸刺激对白| 欧美欧美欧美欧美| 亚洲激情自拍偷拍| 国产福利不卡视频| 欧美三级韩国三级日本一级| 国产欧美视频一区二区| 蜜臀av性久久久久蜜臀aⅴ流畅| 91在线视频官网| 日本一区二区三区四区| 麻豆精品一区二区综合av| 精品视频一区三区九区| 亚洲欧美日韩综合aⅴ视频| 成人亚洲精品久久久久软件| 亚洲精品在线观| 日本不卡一二三| 欧美视频一区在线| 亚洲欧美激情一区二区| 99久久精品国产网站| 中文在线一区二区| 国产激情91久久精品导航| 日韩视频免费观看高清完整版| 亚洲国产精品久久一线不卡| 91蝌蚪porny| 亚洲男人天堂av| 色天天综合久久久久综合片| 国产亚洲视频系列| 国产精品影视网| 国产午夜精品一区二区三区四区| 国产精品自拍毛片| 国产人妖乱国产精品人妖| 国产高清在线观看免费不卡| 国产亚洲一区二区在线观看| 国产激情一区二区三区| 国产精品女人毛片| 91色.com| 亚洲成在人线在线播放| 777色狠狠一区二区三区| 蜜桃精品视频在线观看| 久久色成人在线| 成人av手机在线观看| 亚洲人成网站影音先锋播放| 色婷婷激情一区二区三区| 亚洲影院理伦片| 日韩欧美色电影| 国产成人亚洲精品青草天美| 亚洲欧洲国产专区| 欧美色老头old∨ideo| 日日夜夜精品免费视频| 精品欧美久久久| 95精品视频在线| 日本在线不卡视频一二三区| 久久先锋影音av鲁色资源网| 波多野结衣精品在线| 亚洲成在线观看| 久久精品亚洲国产奇米99| 成人深夜在线观看| 三级欧美韩日大片在线看| 欧美精品一区二区三区视频| 成人免费看片app下载| 亚洲午夜久久久| 久久男人中文字幕资源站| 成人污视频在线观看| 手机精品视频在线观看| 26uuu亚洲综合色欧美| 99热99精品| 韩国三级中文字幕hd久久精品| 亚洲丝袜制服诱惑| 亚洲精品一区二区三区福利| 在线一区二区三区四区五区| 精品一区二区三区的国产在线播放| 欧美高清一级片在线观看| 欧美日韩精品欧美日韩精品| 国产成人aaa| 视频一区国产视频| 亚洲色图制服诱惑| 国产亚洲人成网站| 666欧美在线视频| 在线免费视频一区二区| 国产精品一区2区| 免费av网站大全久久| 亚洲乱码国产乱码精品精小说 | 成人动漫一区二区三区| 午夜激情久久久| 国产精品国产精品国产专区不蜜 | 国产一区二区在线视频| 夜夜揉揉日日人人青青一国产精品| 精品国产免费视频| 91麻豆精品久久久久蜜臀| 91免费观看国产| 成人激情视频网站| 国内外精品视频| 精品一区二区三区免费视频| 午夜av一区二区三区| 亚洲品质自拍视频网站| 国产精品久线在线观看| 亚洲国产高清在线观看视频| 日韩欧美成人一区二区| 69p69国产精品| 欧美三级午夜理伦三级中视频| 91美女精品福利| 99视频一区二区| 91网站最新网址| 色网综合在线观看| 色呦呦一区二区三区| 91伊人久久大香线蕉| 成人激情av网| av亚洲精华国产精华精| 成人午夜av在线| 99re这里都是精品| 日本高清不卡一区| 91久久香蕉国产日韩欧美9色| 日本精品视频一区二区三区| 91视频在线观看免费| 91天堂素人约啪| 色伊人久久综合中文字幕| 日本韩国欧美一区| 欧美亚洲日本国产| 欧美精品视频www在线观看| 在线观看国产一区二区| 欧美性xxxxxxxx| 在线成人av影院| 精品成人免费观看| 日本一区二区在线不卡| 亚洲视频免费在线| 亚洲国产另类av| 精品一区二区免费视频| 国产美女精品在线| kk眼镜猥琐国模调教系列一区二区 | 伊人婷婷欧美激情| 亚洲动漫第一页| 另类的小说在线视频另类成人小视频在线| 麻豆成人av在线| 成人av网址在线| 欧美肥胖老妇做爰| 国产亚洲欧美在线| 亚洲图片欧美视频| 精品一区中文字幕| 成人av在线资源网站| 欧美日韩综合不卡| 2020国产成人综合网| 一区在线观看视频| 免费成人小视频| 91在线播放网址| 欧美精品一区二区三| 亚洲美女视频一区| 喷水一区二区三区| www.日韩在线| 精品国产髙清在线看国产毛片| 中文字幕亚洲成人| 激情深爱一区二区| 日本乱人伦一区| 久久精品人人爽人人爽| 亚洲成av人影院在线观看网| 国产一区二区三区四| 精品视频在线视频| 成人免费一区二区三区视频 | 欧美精品一区二区三区蜜桃| 综合久久久久久| 国产一区二区主播在线| 欧美日韩综合色| 亚洲视频一区在线| 丁香啪啪综合成人亚洲小说| 欧美日韩在线观看一区二区| 久久日一线二线三线suv| 亚洲bt欧美bt精品777| www.日韩av| 国产欧美视频一区二区三区| 日韩电影免费在线观看网站| 91浏览器打开| 国产精品国产三级国产专播品爱网| 蜜桃视频一区二区三区在线观看| 在线观看日韩电影| 自拍偷拍亚洲激情| 成人免费视频网站在线观看| 精品久久久久久久久久久久久久久| 香蕉成人伊视频在线观看| 色中色一区二区| 中文字幕一区二区不卡| 国产黄人亚洲片| 久久久99久久| 国产一区不卡视频| 精品国产免费视频| 国产综合成人久久大片91| 91精品国产综合久久香蕉麻豆| 一区二区三区蜜桃| 欧美性大战xxxxx久久久| 亚洲精品久久嫩草网站秘色| 99久久精品免费精品国产| 国产精品久久久久永久免费观看| 国产在线一区二区综合免费视频| 日韩视频中午一区| 黄色成人免费在线| 久久精品在线观看| 国产福利不卡视频|