w11 - cpp 0.794
Backend server for Rlink and w11
Loading...
Searching...
No Matches
ReventFd.cpp
Go to the documentation of this file.
1// $Id: ReventFd.cpp 1185 2019-07-12 17:29:12Z mueller $
2// SPDX-License-Identifier: GPL-3.0-or-later
3// Copyright 2013-2019 by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
4//
5// Revision History:
6// Date Rev Version Comment
7// 2019-06-08 1161 1.1 derive from Rfd, inherit Fd
8// 2018-12-18 1089 1.0.1 use c++ style casts
9// 2013-01-14 475 1.0 Initial version
10// 2013-01-11 473 0.5 First draft
11// ---------------------------------------------------------------------------
12
17#include <errno.h>
18#include <unistd.h>
19#include <sys/eventfd.h>
20
21#include "ReventFd.hpp"
22
23#include "Rexception.hpp"
24
25using namespace std;
26
32// all method definitions in namespace Retro
33namespace Retro {
34
35//------------------------------------------+-----------------------------------
37
39 : ReventFd("ReventFd::")
40{}
41
42//------------------------------------------+-----------------------------------
44
45ReventFd::ReventFd(const char* cnam)
46 : Rfd(cnam)
47{
48 fFd = ::eventfd(0,0); // ini value = 0; no flags
49 if (fFd < 0)
50 throw Rexception(fCnam+"ctor", "eventfd() failed: ", errno);
51}
52
53//------------------------------------------+-----------------------------------
55
56void ReventFd::Signal(uint64_t val)
57{
58 int irc = ::write(fFd, &val, sizeof(val));
59 if (irc < 0) {
60 throw Rexception(fCnam+"Signal()", "write() failed: ", errno);
61 }
62 return;
63}
64
65//------------------------------------------+-----------------------------------
67
69{
70 uint64_t buf;
71 int irc = ::read(fFd, &buf, sizeof(buf));
72 if (irc < 0) {
73 if (errno == EAGAIN) return 0;
74 throw Rexception(fCnam+"Wait()", "read() failed: ", errno);
75 }
76 return buf;
77}
78
79} // end namespace Retro
FIXME_docs.
Definition: ReventFd.hpp:25
uint64_t Wait()
FIXME_docs.
Definition: ReventFd.cpp:68
void Signal(uint64_t val=1)
FIXME_docs.
Definition: ReventFd.cpp:56
ReventFd()
FIXME_docs.
Definition: ReventFd.cpp:38
FIXME_docs.
Definition: Rexception.hpp:29
FIXME_docs.
Definition: Rfd.hpp:25
int fFd
Definition: Rfd.hpp:48
std::string fCnam
Definition: Rfd.hpp:49
Declaration of class ReventLoop.
Definition: ReventLoop.cpp:47