acl/lib_acl_cpp/samples/connect_manager/mymonitor.cpp

75 lines
1.8 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "check_sync.h"
#include "check_async.h"
2015-04-04 15:25:29 +08:00
#include "mymonitor.h"
mymonitor::mymonitor(acl::connect_manager& manager, const acl::string& proto)
: connect_monitor(manager)
, proto_(proto)
{
}
mymonitor::~mymonitor(void)
{
}
//////////////////////////////////////////////////////////////////////////////
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ijһ<C4B3><D2BB><EFBFBD><EFBFBD><EFBFBD>߳̿ռ<CCBF><D5BC><EFBFBD>
2015-04-04 15:25:29 +08:00
void mymonitor::sio_check(acl::check_client& checker,
acl::socket_stream& conn)
{
// ͬ<><CDAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
check_sync check;
2015-04-04 15:25:29 +08:00
if (proto_ == "http")
check.sio_check_http(checker, conn);
2015-04-04 15:25:29 +08:00
else if (proto_ == "pop3")
check.sio_check_pop3(checker, conn);
2015-04-04 15:25:29 +08:00
else
{
printf("unknown protocol: %s\r\n", proto_.c_str());
checker.set_alive(true);
}
}
/////////////////////////////////////////////////////////////////////////////
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̣<EFBFBD><CCA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><DABC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵߳Ŀռ<C4BF><D5BC><EFBFBD>
2015-04-04 15:25:29 +08:00
void mymonitor::nio_check(acl::check_client& checker,
acl::aio_socket_stream& conn)
{
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><ECB2BD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
check_async* callback = new check_async(checker);
2015-04-04 15:25:29 +08:00
// ע<><D7A2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> IO <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>̵Ļص<C4BB><D8B5><EFBFBD><EFBFBD><EFBFBD>
conn.add_close_callback(callback);
conn.add_read_callback(callback);
conn.add_timeout_callback(callback);
2015-04-04 15:25:29 +08:00
int timeout = 10;
// <20><EFBFBD><ECB2BD>ȡһ<C8A1><D2BB><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD>ͬʱҪ<CAB1>󲻱<EFBFBD><F3B2BBB1><EFBFBD> \r\n
2015-04-04 15:25:29 +08:00
conn.gets(timeout);
}
/////////////////////////////////////////////////////////////////////////////
void mymonitor::on_connected(const acl::check_client& checker, double cost)
{
printf("addr=%s, connected, cost=%.2f\r\n",
checker.get_addr(), cost);
}
void mymonitor::on_refuse(const acl::check_client& checker, double cost)
{
printf("addr=%s, connection refused, cost=%.2f\r\n",
checker.get_addr(), cost);
}
void mymonitor::on_timeout(const acl::check_client& checker, double cost)
{
printf("addr=%s, connection timeout, cost=%.2f\r\n",
checker.get_addr(), cost);
}