运行时须把svc.conf和主程序放在同目录,jaws的默认端口是5432,在svc.conf中可以看到, jaws通过HTTP_Config_Info获得主目录、默认首页等相关信息,可通过设置环境变量改变:我的电脑--右键属性--高级--环境变量--系统变量。如JAWS_DOCUMENT_ROOT设为e:/webpages(或者e:/webpages).
jaws接受到客户端数据后调用下面函数
HTTP_Handler::read_complete (ACE_Message_Block &message_block)
{
switch (this->request_.parse_request (message_block))分析请求
...
this->response_.process_request ();处理请求
...
}
HTTP_Server::init (int argc, ACE_TCHAR *argv[])初始服务器
{
...
switch (this->strategy_)
{
case (JAWS::JAWS_POOL | JAWS::JAWS_ASYNCH) :
return this->asynch_thread_pool ();
case (JAWS::JAWS_PER_REQUEST | JAWS::JAWS_SYNCH) :
return this->thread_per_request (*factory.get ());
case (JAWS::JAWS_POOL | JAWS::JAWS_SYNCH) :
default:
return this->synch_thread_pool (*factory.get ());
}
...
}
int
HTTP_Server::synch_thread_pool (HTTP_Handler_Factory &factory)
{
// 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, ACE_TEXT ("%p/n"),
ACE_TEXT ("HTTP_Acceptor::open")), -1);
// Create a pool of threads to handle incoming connections.
Synch_Thread_Pool_Task t (this->acceptor_, this->tm_, this->threads_, factory);
this->tm_.wait ();
return 0;
}
Synch_Thread_Pool_Task::Synch_Thread_Pool_Task (HTTP_Acceptor &acceptor,
ACE_Thread_Manager &tm,
int threads,
HTTP_Handler_Factory &factory)
: ACE_Task<ACE_NULL_SYNCH> (&tm),
acceptor_ (acceptor),
factory_ (factory)
{
if (this->activate (THR_DETACHED | THR_NEW_LWP, threads) == -1)
ACE_ERROR ((LM_ERROR, ACE_TEXT ("%p/n"),
ACE_TEXT ("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, ACE_TEXT("%p/n"),
ACE_TEXT ("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 = this->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,
ACE_TEXT (" (%t) in Synch_Thread_Pool_Task::svc, recycling/n")));
}
ACE_NOTREACHED(return 0);
}
void
HTTP_Handler::open (ACE_HANDLE handle,
ACE_Message_Block &initial_data)
{
...
this->read_complete (initial_data);
...
}