3 #ifndef CRYPTOPP_WAIT_H 4 #define CRYPTOPP_WAIT_H 8 #if !defined(NO_OS_DEPENDENCE) && (defined(SOCKETS_AVAILABLE) || defined(WINDOWS_PIPES_AVAILABLE)) 14 #ifdef USE_WINDOWS_STYLE_SOCKETS 17 #include <sys/types.h> 18 #include <sys/select.h> 22 #if defined(CRYPTOPP_WIN32_AVAILABLE) 23 #define WIN32_LEAN_AND_MEAN 29 #if defined(__has_feature) 30 # if __has_feature(memory_sanitizer) 31 # define CRYPTOPP_MSAN 1 37 #if CRYPTOPP_MSC_VERSION == 1900 38 # pragma warning(push) 39 # pragma warning(disable: 4589) 47 Tracer(
unsigned int level) : m_level(level) {}
52 virtual void Trace(
unsigned int n, std::string
const& s) = 0;
58 virtual bool UsingDefaults()
const {
return true; }
63 void TraceIf(
unsigned int n, std::string
const&s)
64 {
if (n)
Trace(n, s); }
70 unsigned int Tracing(
unsigned int nr,
unsigned int minLevel)
const 71 {
return (UsingDefaults() && m_level >= minLevel) ? nr : 0; }
80 #define CRYPTOPP_TRACER_CONSTRUCTOR(DERIVED) \ 81 public: DERIVED(unsigned int level = 0) : Tracer(level) {} 83 #define CRYPTOPP_BEGIN_TRACER_CLASS_1(DERIVED, BASE1) \ 84 class DERIVED : virtual public BASE1, public NotCopyable { CRYPTOPP_TRACER_CONSTRUCTOR(DERIVED) 86 #define CRYPTOPP_BEGIN_TRACER_CLASS_2(DERIVED, BASE1, BASE2) \ 87 class DERIVED : virtual public BASE1, virtual public BASE2, public NotCopyable { CRYPTOPP_TRACER_CONSTRUCTOR(DERIVED) 89 #define CRYPTOPP_END_TRACER_CLASS }; 94 #define CRYPTOPP_BEGIN_TRACER_EVENTS(UNIQUENR) enum { EVENTBASE = UNIQUENR, 95 #define CRYPTOPP_TRACER_EVENT(EVENTNAME) EventNr_##EVENTNAME, 96 #define CRYPTOPP_END_TRACER_EVENTS }; 108 #define CRYPTOPP_TRACER_EVENT_METHODS(EVENTNAME, LOGLEVEL) \ 109 virtual unsigned int Trace##EVENTNAME() const { return Tracing(EventNr_##EVENTNAME, LOGLEVEL); } \ 110 virtual void Trace##EVENTNAME(std::string const& s) { TraceIf(Trace##EVENTNAME(), s); } 128 CallStack const* Prev()
const {
return m_prev; }
129 virtual std::string
Format()
const;
141 std::string
Format()
const;
148 class CallStackWithStr :
public CallStack 151 CallStackWithStr(
char const* i,
char const*
z,
CallStack const* p) :
CallStack(i, p), m_z(z) {}
152 std::string
Format()
const;
159 CRYPTOPP_BEGIN_TRACER_CLASS_1(WaitObjectsTracer, Tracer)
160 CRYPTOPP_BEGIN_TRACER_EVENTS(0x48752841)
161 CRYPTOPP_TRACER_EVENT(NoWaitLoop)
162 CRYPTOPP_END_TRACER_EVENTS
163 CRYPTOPP_TRACER_EVENT_METHODS(NoWaitLoop, 1)
164 CRYPTOPP_END_TRACER_CLASS
166 struct WaitingThreadData;
176 Err(
const std::string& s) :
Exception(IO_ERROR, s) {}
179 static unsigned int MaxWaitObjects();
184 void SetNoWait(
CallStack const& callStack);
185 void ScheduleEvent(
double milliseconds,
CallStack const& callStack);
187 bool Wait(
unsigned long milliseconds);
189 #ifdef USE_WINDOWS_STYLE_SOCKETS 191 void AddHandle(HANDLE handle,
CallStack const& callStack);
193 void AddReadFd(
int fd,
CallStack const& callStack);
194 void AddWriteFd(
int fd,
CallStack const& callStack);
198 WaitObjectsTracer* m_tracer;
200 #ifdef USE_WINDOWS_STYLE_SOCKETS 201 void CreateThreads(
unsigned int count);
202 std::vector<HANDLE> m_handles;
203 std::vector<WaitingThreadData *> m_threads;
204 HANDLE m_startWaiting;
205 HANDLE m_stopWaiting;
207 fd_set m_readfds, m_writefds;
210 double m_firstEventTime;
214 #ifdef USE_WINDOWS_STYLE_SOCKETS 215 typedef size_t LastResultType;
217 typedef int LastResultType;
219 enum { LASTRESULT_NOWAIT = -1, LASTRESULT_SCHEDULED = -2, LASTRESULT_TIMEOUT = -3 };
220 LastResultType m_lastResult;
221 unsigned int m_sameResultCount;
223 void SetLastResult(LastResultType result);
224 void DetectNoWait(LastResultType result,
CallStack const& callStack);
229 #if CRYPTOPP_MSC_VERSION == 1900 230 # pragma warning(pop) 233 #endif // NO_OS_DEPENDENCE 235 #endif // CRYPTOPP_WAIT_H Base class for all exceptions thrown by the library.
Utility functions for the Crypto++ library.
#define NAMESPACE_BEGIN(x)
Abstract base classes that provide a uniform interface to this library.
Library configuration file.
Ensures an object is not copyable.