| 1394 | } |
| 1395 | |
| 1396 | int MtFrame::WaitEvents(int fd, int events, int timeout) |
| 1397 | { |
| 1398 | MtFrame* mtframe = MtFrame::Instance(); |
| 1399 | utime64_t start = mtframe->GetLastClock(); |
| 1400 | MicroThread* thread = mtframe->GetActiveThread(); |
| 1401 | utime64_t now = 0; |
| 1402 | |
| 1403 | if (timeout <= -1) |
| 1404 | { |
| 1405 | timeout = 0x7fffffff; |
| 1406 | } |
| 1407 | |
| 1408 | while (true) |
| 1409 | { |
| 1410 | now = mtframe->GetLastClock(); |
| 1411 | if ((int)(now - start) > timeout) |
| 1412 | { |
| 1413 | errno = ETIME; |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
| 1417 | KqueuerObj epfd; |
| 1418 | epfd.SetOsfd(fd); |
| 1419 | if (events & KQ_EVENT_READ) |
| 1420 | { |
| 1421 | epfd.EnableInput(); |
| 1422 | } |
| 1423 | if (events & KQ_EVENT_WRITE) |
| 1424 | { |
| 1425 | epfd.EnableOutput(); |
| 1426 | } |
| 1427 | epfd.SetOwnerThread(thread); |
| 1428 | |
| 1429 | if (!mtframe->KqueueSchedule(NULL, &epfd, timeout)) |
| 1430 | { |
| 1431 | MTLOG_TRACE("epoll schedule failed, errno: %d", errno); |
| 1432 | return 0; |
| 1433 | } |
| 1434 | |
| 1435 | return epfd.GetRcvEvents(); |
| 1436 | } |
| 1437 | } |
no test coverage detected