本文整理汇总了C++中Slave::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ Slave::connect方法的具体用法?C++ Slave::connect怎么用?C++ Slave::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slave
的用法示例。
在下文中一共展示了Slave::connect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
cout << SectorVersionString << endl;
SlaveConf global_conf;
CmdLineParser clp;
clp.parse(argc, argv);
for (map<string, string>::const_iterator i = clp.m_mDFlags.begin(); i != clp.m_mDFlags.end(); ++ i)
{
if (i->first == "mh")
global_conf.m_strMasterHost = i->second;
else if (i->first == "mp")
global_conf.m_iMasterPort = atoi(i->second.c_str());
else if (i->first == "h")
{
global_conf.m_strHomeDir = i->second;
}
else if (i->first == "ds")
global_conf.m_llMaxDataSize = atoll(i->second.c_str()) * 1024 * 1024;
else if (i->first == "log")
global_conf.m_iLogLevel = atoi(i->second.c_str());
else
{
cout << "warning: unrecognized flag " << i->first << endl;
help();
}
}
string base = "";
if (clp.m_vParams.size() == 1)
base = clp.m_vParams.front();
else if (clp.m_vParams.size() > 1)
cout << "warning: wrong parameters ignored.\n";
Slave s;
if (s.init(&base, &global_conf) < 0)
{
cout << "error: failed to initialize the slave. check slave configurations.\n";
return-1;
}
if (s.connect() < 0)
{
cout << "error: failed to connect to the master, or the connection request is rejected.\n";
return -1;
}
s.run();
s.close();
return 0;
}
示例2: main
int main(int argc, char** argv)
{
Slave s;
int res;
if (argc > 1)
res = s.init(argv[1]);
else
res = s.init();
if (res < 0)
return -1;
if (s.connect() < 0)
return -1;
s.run();
return 1;
}
示例3: _run_thread
void* Slave::_run_thread(void *arg){
Slave *slave = (Slave *)arg;
const std::vector<Bytes> *req;
Fdevents select;
const Fdevents::events_t *events;
int idle = 0;
bool reconnect = false;
#define RECV_TIMEOUT 200
#define MAX_RECV_TIMEOUT 300 * 1000
#define MAX_RECV_IDLE MAX_RECV_TIMEOUT/RECV_TIMEOUT
while(!slave->thread_quit){
if(reconnect){
slave->status = DISCONNECTED;
reconnect = false;
select.del(slave->link->fd());
delete slave->link;
slave->link = NULL;
sleep(1);
}
if(!slave->connected()){
if(slave->connect() != 1){
usleep(100 * 1000);
}else{
select.set(slave->link->fd(), FDEVENT_IN, 0, NULL);
}
continue;
}
events = select.wait(RECV_TIMEOUT);
if(events == NULL){
log_error("events.wait error: %s", strerror(errno));
sleep(1);
continue;
}else if(events->empty()){
if(idle++ >= MAX_RECV_IDLE){
log_error("the master hasn't responsed for awhile, reconnect...");
idle = 0;
reconnect = true;
}
continue;
}
idle = 0;
if(slave->link->read() <= 0){
log_error("link.read error: %s, reconnecting to master", strerror(errno));
reconnect = true;
continue;
}
while(1){
req = slave->link->recv();
if(req == NULL){
log_error("link.recv error: %s, reconnecting to master", strerror(errno));
reconnect = true;
break;
}else if(req->empty()){
break;
}else if(req->at(0) == "noauth"){
log_error("authentication required");
reconnect = true;
sleep(1);
break;
}else{
if(slave->proc(*req) == -1){
goto err;
}
}
}
} // end while
log_info("Slave thread quit");
return (void *)NULL;
err:
log_fatal("Slave thread exit unexpectedly");
exit(0);
return (void *)NULL;;
}