?? request_handler.cpp
字號:
#include "ace/OS.h"
#include "ace/Message_Block.h"
#include "ace/Thread_Manager.h"
#include "ace/Svc_Handler.h"
#include "ace/SOCK_Stream.h"
#include "ace/Synch.h"
#include "ace/Reactor.h"
#include "Server.h"
namespace ACE_Server
{
Task_Manager Request_Handler::task_mgr;
Request_Handler::Request_Handler(const ACE_INET_Addr &local_addr)
: endpoint_ (local_addr)
{
//this->reactor(ACE_Reactor::instance());
task_mgr.activate();
}
ACE_HANDLE Request_Handler::get_handle (void) const
{
return this->endpoint_.get_handle ();
}
int Request_Handler::handle_close (ACE_HANDLE handle,
ACE_Reactor_Mask)
{
ACE_UNUSED_ARG (handle);
ACE_DEBUG ((LM_DEBUG, "(%P|%t) handle_close\n"));
this->endpoint_.close ();
delete this;
return 0;
}
int Request_Handler::handle_timeout (const ACE_Time_Value &,
const void *)
{
ACE_DEBUG ((LM_DEBUG, "(%P|%t) timed out for endpoint\n"));
return 0;
}
int Request_Handler::handle_input(ACE_HANDLE fd)
{
char buf[BUFSIZ];
ACE_INET_Addr from_addr;
ACE_DEBUG ((LM_DEBUG, "(%P|%t) activity occurred on handle %d!\n", this->endpoint_.get_handle ()));
ssize_t n = this->endpoint_.recv (buf, sizeof buf, from_addr);
if (n == -1)
ACE_ERROR ((LM_ERROR, "%p\n", "handle_input"));
else
{
ACE_DEBUG ((LM_DEBUG, "(%P|%t) buf of size %d = %*s\n", n, n, &buf[4]));//字符串跳過了四個字節的長度數據
ACE_Message_Block *mb = NULL;
ACE_NEW_RETURN(mb, ACE_Message_Block(n, ACE_Message_Block::MB_DATA, 0, buf), -1);
mb->wr_ptr(n);
task_mgr.putq(mb);
}
return 0;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -