BVB Source Codes

uWebSockets Show Epoll.cpp Source code

Return Download uWebSockets: download Epoll.cpp Source code - Download uWebSockets Source code - Type:.cpp
  1. #include "Backend.h"
  2.  
  3. #ifdef USE_EPOLL
  4.  
  5. // todo: remove this mutex, have callbacks set at program start
  6. std::recursive_mutex cbMutex;
  7. void (*callbacks[16])(Poll *, int, int);
  8. int cbHead = 0;
  9.  
  10. void Loop::run() {
  11.     timepoint = std::chrono::system_clock::now();
  12.     while (numPolls) {
  13.         for (std::pair<Poll *, void (*)(Poll *)> c : closing) {
  14.             numPolls--;
  15.  
  16.             c.second(c.first);
  17.  
  18.             if (!numPolls) {
  19.                 closing.clear();
  20.                 return;
  21.             }
  22.         }
  23.         closing.clear();
  24.  
  25.         int numFdReady = epoll_wait(epfd, readyEvents, 1024, delay);
  26.         timepoint = std::chrono::system_clock::now();
  27.  
  28.         if (preCb) {
  29.             preCb(preCbData);
  30.         }
  31.  
  32.         for (int i = 0; i < numFdReady; i++) {
  33.             Poll *poll = (Poll *) readyEvents[i].data.ptr;
  34.             int status = -bool(readyEvents[i].events & EPOLLERR);
  35.             callbacks[poll->state.cbIndex](poll, status, readyEvents[i].events);
  36.         }
  37.  
  38.         while (timers.size() && timers[0].timepoint < timepoint) {
  39.             Timer *timer = timers[0].timer;
  40.             cancelledLastTimer = false;
  41.             timers[0].cb(timers[0].timer);
  42.  
  43.             if (cancelledLastTimer) {
  44.                 continue;
  45.             }
  46.  
  47.             int repeat = timers[0].nextDelay;
  48.             auto cb = timers[0].cb;
  49.             timers.erase(timers.begin());
  50.             if (repeat) {
  51.                 timer->start(cb, repeat, repeat);
  52.             }
  53.         }
  54.  
  55.         if (postCb) {
  56.             postCb(postCbData);
  57.         }
  58.     }
  59. }
  60. #endif
  61.  
downloadEpoll.cpp Source code - Download uWebSockets Source code
Related Source Codes/Software:
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11

 Back to top