本文整理汇总了C++中Slave::connected方法的典型用法代码示例。如果您正苦于以下问题:C++ Slave::connected方法的具体用法?C++ Slave::connected怎么用?C++ Slave::connected使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slave
的用法示例。
在下文中一共展示了Slave::connected方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _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;;
}