libzypp 17.37.10

wakeup.cpp
Go to the documentation of this file.
1#include "wakeup.h"
2
3#include <zypp-core/zyppng/base/private/linuxhelpers_p.h>
4#include <zypp-core/zyppng/base/SocketNotifier>
5
6#include <unistd.h>
7#include <fcntl.h>
8
9 namespace zyppng {
10
11 Wakeup::Wakeup()
12 {
13 ::pipe ( _wakeupPipe );
14 ::fcntl( _wakeupPipe[0], F_SETFL, O_NONBLOCK );
15 }
16
17 Wakeup::~Wakeup()
18 {
19 ::close (_wakeupPipe[0]);
20 ::close (_wakeupPipe[1]);
21 }
22
23 void Wakeup::notify()
24 {
25 eintrSafeCall( ::write, _wakeupPipe[1], "\n", 1);
26 }
27
28 void Wakeup::ack()
29 {
30 char dummy = 0;
31 while ( eintrSafeCall( ::read, _wakeupPipe[0], &dummy, 1 ) > 0 ) { continue; }
32 }
33
34 int Wakeup::pollfd() const
35 {
36 return _wakeupPipe[0];
37 }
38
39 std::shared_ptr<SocketNotifier> Wakeup::makeNotifier( const bool enabled ) const
40 {
41 return SocketNotifier::create( _wakeupPipe[0], zyppng::SocketNotifier::Read, enabled );
42 }
43
44}
zyppng::AbstractEventSource::Read
@ Read
Definition abstracteventsource.h:47
zyppng::SocketNotifier::create
static Ptr create(int socket, int evTypes, bool enable=true)
Definition socketnotifier.cc:33
zyppng::Wakeup::Wakeup
Wakeup()
Definition wakeup.cpp:11
zyppng::Wakeup::makeNotifier
std::shared_ptr< SocketNotifier > makeNotifier(const bool enabled=true) const
Definition wakeup.cpp:39
zyppng::Wakeup::notify
void notify()
Definition wakeup.cpp:23
zyppng::Wakeup::pollfd
int pollfd() const
Definition wakeup.cpp:34
zyppng::Wakeup::_wakeupPipe
int _wakeupPipe[2]
Definition wakeup.h:51
zyppng::Wakeup::ack
void ack()
Definition wakeup.cpp:28
zyppng::Wakeup::~Wakeup
~Wakeup()
Definition wakeup.cpp:17
linuxhelpers_p.h
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::eintrSafeCall
auto eintrSafeCall(Fun &&function, Args &&... args)
Definition linuxhelpers_p.h:50
wakeup.h