本文整理汇总了C++中DBClientReplicaSet::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ DBClientReplicaSet::connect方法的具体用法?C++ DBClientReplicaSet::connect怎么用?C++ DBClientReplicaSet::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBClientReplicaSet
的用法示例。
在下文中一共展示了DBClientReplicaSet::connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: replicaset_connect
/*
* ok,err = replicaset:connect()
*/
static int replicaset_connect(lua_State *L) {
DBClientReplicaSet *replicaset = userdata_to_replicaset(L, 1);
try {
replicaset->connect();
} catch (std::exception &e) {
lua_pushnil(L);
lua_pushfstring(L, LUAMONGO_ERR_CONNECT_FAILED, LUAMONGO_REPLICASET, e.what());
return 2;
}
lua_pushboolean(L, 1);
return 1;
}
示例2: connect
DBClientBase* ConnectionString::connect( string& errmsg, double socketTimeout ) const {
switch ( _type ) {
case MASTER: {
DBClientConnection * c = new DBClientConnection(true);
c->setSoTimeout( socketTimeout );
log(1) << "creating new connection to:" << _servers[0] << endl;
if ( ! c->connect( _servers[0] , errmsg ) ) {
delete c;
return 0;
}
log(1) << "connected connection!" << endl;
return c;
}
case PAIR:
case SET: {
DBClientReplicaSet * set = new DBClientReplicaSet( _setName , _servers , socketTimeout );
if( ! set->connect() ) {
delete set;
errmsg = "connect failed to set ";
errmsg += toString();
return 0;
}
return set;
}
case SYNC: {
// TODO , don't copy
list<HostAndPort> l;
for ( unsigned i=0; i<_servers.size(); i++ )
l.push_back( _servers[i] );
SyncClusterConnection* c = new SyncClusterConnection( l, socketTimeout );
return c;
}
case INVALID:
throw UserException( 13421 , "trying to connect to invalid ConnectionString" );
break;
}
assert( 0 );
return 0;
}
示例3: connect
DBClientBase* ConnectionString::connect( std::string& errmsg, double socketTimeout ) const {
switch ( _type ) {
case MASTER: {
DBClientConnection * c = new DBClientConnection(true);
c->setSoTimeout( socketTimeout );
LOG(1) << "creating new connection to:" << _servers[0];
if ( ! c->connect( _servers[0] , errmsg ) ) {
delete c;
return 0;
}
LOG(1) << "connected connection!";
return c;
}
case PAIR:
case SET: {
DBClientReplicaSet * set = new DBClientReplicaSet( _setName , _servers , socketTimeout );
if( ! set->connect() ) {
delete set;
errmsg = "connect failed to replica set ";
errmsg += toString();
return 0;
}
return set;
}
case SYNC: {
// TODO , don't copy
std::list<HostAndPort> l;
for ( unsigned i=0; i<_servers.size(); i++ )
l.push_back( _servers[i] );
SyncClusterConnection* c = new SyncClusterConnection( l, socketTimeout );
return c;
}
case CUSTOM: {
// Lock in case other things are modifying this at the same time
boost::lock_guard<boost::mutex> lk( _connectHookMutex );
// Allow the replacement of connections with other connections - useful for testing.
uassert( 16335, "custom connection to " + this->toString() +
" specified with no connection hook", _connectHook );
// Double-checked lock, since this will never be active during normal operation
DBClientBase* replacementConn = _connectHook->connect( *this, errmsg, socketTimeout );
log() << "replacing connection to " << this->toString() << " with "
<< ( replacementConn ? replacementConn->getServerAddress() : "(empty)" );
return replacementConn;
}
case INVALID:
throw UserException( 13421 , "trying to connect to invalid ConnectionString" );
break;
}
verify( 0 );
return 0;
}