acl/app/wizard/tmpl/master/rpc_manager.cpp

39 lines
772 B
C++
Raw Normal View History

#include "stdafx.h"
2014-11-19 00:25:21 +08:00
#include "rpc_manager.h"
2019-07-20 16:41:23 +08:00
rpc_manager::rpc_manager(void)
2014-11-19 00:25:21 +08:00
: handle_(NULL)
{
}
2019-07-20 16:41:23 +08:00
rpc_manager::~rpc_manager(void)
2014-11-19 00:25:21 +08:00
{
delete service_;
2019-07-20 16:41:23 +08:00
if (handle_ != NULL) {
2014-11-19 00:25:21 +08:00
handle_->check();
2019-07-20 16:41:23 +08:00
}
2014-11-19 00:25:21 +08:00
logger("rpc service destroy ok!");
}
2015-09-16 21:03:02 +08:00
void rpc_manager::init(acl::aio_handle& handle, int max_threads /* = 10 */,
2014-11-19 00:25:21 +08:00
const char* addr /* = NULL */)
{
2015-09-16 21:03:02 +08:00
handle_ = &handle;
// <20><><EFBFBD><EFBFBD> rpc <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2014-11-19 00:25:21 +08:00
service_ = new acl::rpc_service(max_threads);
2015-09-16 21:03:02 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD>
2019-07-20 16:41:23 +08:00
if (!service_->open(handle_, addr && *addr ? addr : NULL)) {
2014-11-19 00:25:21 +08:00
logger_fatal("open service error: %s", acl::last_serror());
2019-07-20 16:41:23 +08:00
} else {
2015-09-16 21:03:02 +08:00
logger("open service ok, listen: %s", service_->get_addr());
2019-07-20 16:41:23 +08:00
}
2014-11-19 00:25:21 +08:00
}
void rpc_manager::fork(acl::rpc_request* req)
{
service_->rpc_fork(req);
}