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.ISBTI Nitialized, 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.btmaca), ..... ....... DDR) > 0) { Mac_st = Syswatcher::instance ()->setmacaddr (MINFO.BTMACADDR); } int DFD = _DATA_ROUTER->GETREADFD (); struct epoll_event event; struct Epoll_eve NT * _events; int efd = epoll_create1 (0);nbsp 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) { &NB Sp Perror ("Epoll_ctl"); abort (); } _events = (epoll_event *) call OC (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 had 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::d ispath (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);}
Epoll actual use