epoll 实际使用
int n, i;
n = epoll_wait(efd, _events, MAXEVENTS, -1);
for (i = 0; i < n; i++) {
if ((_events[i].events & EPOLLERR)
|| (_events[i].events & EPOLLHUP) || (!(_events[i].events
& EPOLLIN))) {
ALOGD(SYS_LOG_TAG " SysWatcher::EPOLLERR||EPOLLHUP||!EPOLLIN\n");
fprintf(stderr, "epoll error\n");
close(_events[i].data.fd);
continue;
} else if (dfd == _events[i].data.fd) {
ssize_t count;
memset(buf, 0, RECV_BUF_DEPTH);
/*
count = read(_events[i].data.fd, buf, RECV_BUF_DEPTH);
if (count == -1) {
// If errno == EAGAIN, that means we have read all data. So go back to the main loop.
if (errno != EAGAIN) {
perror("read");
done = 1;
ALOGD(SYS_LOG_TAG " SysWatcher:: errno != EAGAIN\n");
}
ALOGD(SYS_LOG_TAG " SysWatcher:: errno == EAGAIN\n");
break;
} else if (count == 0) { //��ʱ
// End of file. The remote has closed the connection.
done = 1;
ALOGD(SYS_LOG_TAG "SysWatcher::recv() DISCONNECTED.");
break;
}*/
message = string(buf);
ALOGD(SYS_LOG_TAG " SysWatcher Recive Data from BLEPare data=%s\n", buf);
bool dis_st = RouterSysWatcher::dispath(message);
message = "";
memset(buf, 0, RECV_BUF_DEPTH);
if (dis_st) {
ALOGD(SYS_LOG_TAG "dispath sucess! dis_ret =%d", dis_st);
} else {
ALOGD(SYS_LOG_TAG "dispath error! dis_ret =%d", dis_st);
continue;
}
ALOGD(SYS_LOG_TAG " Epoll test, buf = %s, count =%d", buf, count);
}
}
_data_router -> readInfoHw(&mInfo);
if (strlen(mInfo.BTMACaddr) > 0 and mac_st == false) {
mac_st = SysWatcher::instance()->setMacAddr(mInfo.BTMACaddr);
ALOGD(SYS_LOG_TAG "......readInfoHW: conn=%d, init=%d, numC=%d, MAC=%s",
mInfo.isBTConnected, mInfo.isBTInitialized, mInfo.numClient, mInfo.BTMACaddr);
}
}
free(_events);
_events = 0;
close(dfd);
}