void DataHandle::recv() {
    sleep(2);
    _data_router -> readInfoHw(&mInfo);
    ALOGD(SYS_LOG_TAG "readInfoHW: conn=%d, init=%d, numC=%d, MAC=%s",
            mInfo.isBTConnected, mInfo.isBTInitialized, mInfo.numClient, mInfo.BTMACaddr);
    ALOGD(SYS_LOG_TAG "readInfoHW: sentP=%lld, recvP=%lld, dropP=%lld, sentB=%lld, recvB=%lld",
            mInfo.sentPacket, mInfo.recvPacket, mInfo.dropPacket,
            mInfo.sentByte, mInfo.recvByte);
    ALOGD(SYS_LOG_TAG "before begin recv.........................");
    bool mac_st = false;
    if (strlen(mInfo.BTMACaddr) > 0) {
        mac_st = SysWatcher::instance()->setMacAddr(mInfo.BTMACaddr);
    }
    int dfd = _data_router->getReadFd();
    struct epoll_event event;
    struct epoll_event * _events;
    int efd = epoll_create1(0);
    if (efd == -1) {
        perror("epoll_create");
        abort();
    }
    event.data.fd = dfd;
    event.events = EPOLLIN | EPOLLET;
    int s = epoll_ctl(efd, EPOLL_CTL_ADD, dfd, &event);
    if (s == -1) {
        perror("epoll_ctl");
        abort();
    }
    _events = (epoll_event *) calloc(MAXEVENTS, sizeof(event));
    int done;
    string message;
    const int RECV_BUF_DEPTH = 200;
    char buf[RECV_BUF_DEPTH] = { 0 };
    while (1) {

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);

}

最新文章

  1. Leetcode 35 Search Insert Position 二分查找(二分下标)
  2. Visual Studio常用插件
  3. JUnit + Spring + Hibernate 集成测试,无法通过的问题
  4. JS 提示框 alert()、confirm()、prompt()的三者的区别
  5. ios中Raw文件系统常用文件夹
  6. 大神眼中的React Native--备用
  7. javascript设计模式——Observer
  8. UC浏览器插件开发
  9. css 弹出框
  10. JavaScript基础知识(二)
  11. [转] 扩展微信小程序框架功能
  12. GDAL——命令使用专题——gdalinfo命令
  13. zabbix3.4使用外部邮件报警
  14. BZOJ1006:[HNOI2008]神奇的国度(弦图染色)
  15. IDC Digital Transition Annual Festival(2018.10.19)
  16. ajax上传文件及进度显示
  17. mysql读写分离[高可用]
  18. 3G 4G 5G中的网络安全问题——文献汇总
  19. UVa 122 Trees on the level(链式二叉树的建立和层次遍历)
  20. MVC layout 命名空间引用问题

热门文章

  1. Loadrunner模拟JSON接口请求进行测试
  2. try-catch 示例
  3. Marvelous Mazes
  4. 多功能扫描打印读卡一体手持POS终端
  5. 简单几何(相对运动距离最值) UVA 11796 Dog Distance
  6. HDU2588 GCD(欧拉函数)
  7. 【SPOJ】375. Query on a tree(树链剖分)
  8. Ubuntu 12.04 下安装 VirtualBox 及虚拟机winxp的安装
  9. opengl画圆
  10. mysql时该如何估算内存的消耗,公式如何计算?