diff options
author | Thomas Preud'homme <robotux@celest.fr> | 2020-08-11 22:35:12 +0100 |
---|---|---|
committer | Thomas Preud'homme <robotux@celest.fr> | 2020-08-11 22:35:12 +0100 |
commit | 3ac113857071fc1f225b2e1b42547269e568c6b7 (patch) | |
tree | 8b28dd9c44a0d3c7ab8187cd8d8f19d47591d813 /plugins/CopyEngine/Ultracopier-Spec/EventLoop.cpp | |
parent | 9b10c21f5cad0e2ec27d23c59e65af7141a226f3 (diff) |
New upstream version 2.2.4.4
Diffstat (limited to 'plugins/CopyEngine/Ultracopier-Spec/EventLoop.cpp')
-rwxr-xr-x | plugins/CopyEngine/Ultracopier-Spec/EventLoop.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/plugins/CopyEngine/Ultracopier-Spec/EventLoop.cpp b/plugins/CopyEngine/Ultracopier-Spec/EventLoop.cpp new file mode 100755 index 0000000..c2e237a --- /dev/null +++ b/plugins/CopyEngine/Ultracopier-Spec/EventLoop.cpp @@ -0,0 +1,71 @@ +#include "EventLoop.h" +#include "CallBackEventLoop.h" + +#ifdef ASYNCFILEMANIP + +#ifdef Q_OS_LINUX +#include <sys/epoll.h> +#include <signal.h> +#endif + +EventLoop EventLoop::eventLoop; + +EventLoop::EventLoop() +{ + int efd = epoll_create1(0); + if(efd==-1) + { + fprintf(stderr,"%s, errno %i\n", strerror(errno), errno); + abort(); + } + //start();->put cpu at 100% + stopIt=false; +} + +EventLoop::~EventLoop() +{ + stop(); + QThread::wait(); +} + +void EventLoop::stop() +{ + stopIt=true; +} + +void EventLoop::run() +{ + while(!stopIt) + { + int number_of_events = epoll_wait(efd, events, MAXEVENTS, -1); + if (-1 == number_of_events && EINTR == errno) + return; + for(int i = 0; i < number_of_events; i++) + static_cast<CallBackEventLoop *>(events[i].data.ptr)->callBack(); + } +} + +void EventLoop::watchSource(CallBackEventLoop * const object,const int &fd) +{ + epoll_event event; + event.events = EPOLLIN | EPOLLPRI | EPOLLERR | EPOLLET; + event.data.ptr = object; + if(epoll_ctl(efd, EPOLL_CTL_ADD, fd, &event)!=0) + { + printf("%s, errno %i\n", strerror(errno), errno); + //abort(); + } +} + +void EventLoop::watchDestination(CallBackEventLoop * const object,const int &fd) +{ + epoll_event event; + event.events = EPOLLOUT | EPOLLPRI | EPOLLERR | EPOLLET; + event.data.ptr = object; + if(epoll_ctl(efd, EPOLL_CTL_ADD, fd, &event)!=0) + { + printf("%s, errno %i\n", strerror(errno), errno); + //abort(); + } +} +#endif |