Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
JSelectReader.hh
Go to the documentation of this file.
1#ifndef __JNET__JSELECTREADER__
2#define __JNET__JSELECTREADER__
3
4#include <sys/select.h>
5#include <limits>
6#include <errno.h>
7
8#include "JLang/JException.hh"
11#include "JLang/JTimeval.hh"
12
13
14/**
15 * \author mdejong
16 */
17
18namespace JNET {}
19namespace JPP { using namespace JNET; }
20
21namespace JNET {
22
26 using JLANG::JTimeval;
27
28
29 /**
30 * Wrapper class for select call.
31 */
33 public:
34 /**
35 * Default constructor.
36 */
39
40
41 /**
42 * Get reader mask.
43 *
44 * \return mask
45 */
50
51
52 /**
53 * Set reader mask.
54 *
55 * \param file file
56 */
57 void setReaderMask(const JAbstractFile& file)
58 {
59 readerMask.set(file);
60 }
61
62
63 /**
64 * Has reader file.
65 *
66 * \param file file
67 * \return true if file set; else false
68 */
69 bool hasReaderMask(const JAbstractFile& file) const
70 {
71 return readerMask.has(file);
72 }
73
74
75 /**
76 * Reset.
77 */
78 void reset()
79 {
80 readerMask.reset(true); // hard reset
81 }
82
83
84 /**
85 * Select call.
86 *
87 * \param timeout timeout
88 * \return number of valid file descriptors
89 */
90 bool operator()(JTimeval timeout)
91 {
92 return this->operator()(&timeout);
93 }
94
95
96 /**
97 * Select call.
98 *
99 * \param timeout timeout
100 * \return number of valid file descriptors
101 */
102 int operator()(timeval* timeout = NULL)
103 {
105
106 nfds += 1;
107 nfds = ::select(nfds, &readerMask, NULL, NULL, timeout);
108
109 if (nfds != 0) {
110
111 if (nfds < 0) {
112 if (errno != EINTR) {
113 THROW(JSelectException, "JSelectReader(..) failed.");
114 }
115 }
116
117 } else {
118
119 readerMask.reset(false); // soft reset
120 }
121
122 return nfds;
123 }
124
125
126 protected:
128 };
129}
130
131#endif
Exceptions.
#define THROW(JException_t, A)
Marco for throwing exception with std::ostream compatible message.
The JAbstractFile class encapsulates the c-style file descriptor.
Auxiliary class for method select.
void set(const int file_descriptor)
Set file descriptor.
void reset(const bool option=true)
Reset mask.
bool has(const int file_descriptor) const
Has file descriptor.
int getNumberOfFileDescriptors() const
Get number of file descriptors.
Exception for select call.
Auxiliary class for time values.
Definition JTimeval.hh:29
Wrapper class for select call.
int operator()(timeval *timeout=NULL)
Select call.
bool operator()(JTimeval timeout)
Select call.
void setReaderMask(const JAbstractFile &file)
Set reader mask.
JFileDescriptorMask readerMask
bool hasReaderMask(const JAbstractFile &file) const
Has reader file.
JFileDescriptorMask & getReaderMask()
Get reader mask.
JSelectReader()
Default constructor.
bool select(const Trk &trk, const Evt &evt)
Event selection.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).