本文整理汇总了C++中Connection::Init方法的典型用法代码示例。如果您正苦于以下问题:C++ Connection::Init方法的具体用法?C++ Connection::Init怎么用?C++ Connection::Init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection::Init方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
// CreateConnection
status_t
ConnectionFactory::CreateConnection(const char* type, const char* parameters,
Connection** _connection)
{
if (!type)
return B_BAD_VALUE;
// create the connection
Connection* connection = NULL;
if (strcmp(type, "insecure") == 0)
connection = new(nothrow) InsecureConnection;
else if (strcmp(type, "port") == 0)
connection = new(nothrow) PortConnection;
else
return B_BAD_VALUE;
if (!connection)
return B_NO_MEMORY;
// init it
status_t error = connection->Init(parameters);
if (error != B_OK) {
delete connection;
return error;
}
*_connection = connection;
return B_OK;
}
示例2: DoTcpAccept
void EventModule::DoTcpAccept(int listen_fd, void* arg)
{
Epoller* epoller_ = (Epoller*)arg;
struct sockaddr_in sin;
socklen_t len = sizeof(sin);
ConfigModule* conf_module = FindModule<ConfigModule>(App::GetInstance());
int32_t max_connection = conf_module->config().conn_pool_size();
ConnMgrModule* conn_mgr_module = FindModule<ConnMgrModule>(App::GetInstance());
int32_t cur_conn_map_size = conn_mgr_module->GetCurConnMapSize();
if (cur_conn_map_size >= max_connection)
return;
int32_t conn_fd = accept(listen_fd, (struct sockaddr*)&sin, &len);
if (conn_fd < 0) {
if (errno != EAGAIN && errno != ECONNABORTED
&& errno != EPROTO && errno != EINTR) {
PLOG(ERROR) << "accept";
}
return;
}
Epoller::SetNonBlock(conn_fd);
Epoller::SetSocketOpt(conn_fd);
Connection* conn = conn_mgr_module->CreateConn(conn_fd);
conn->Init();
if (conn == NULL) {
LOG(ERROR) << "CreateConn error!";
return;
}
LOG(INFO)
<< "accept ip[" << sin.sin_addr.s_addr
<< "] port[" << sin.sin_port
<< "] conn_fd[" << conn_fd
<< "]";
int ret = epoller_->AddEvent(conn_fd, EVENT_READ, EventModule::DoTcpRead, (void*)epoller_);
if (ret < 0)
LOG(ERROR) << "epoller_->AddEvent error!";
conn->set_conn_fd(conn_fd);
}