summaryrefslogtreecommitdiff
path: root/wait.h
blob: c1435221e6553bf102f11d2ac2e867adf4027e68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef CRYPTOPP_WAIT_H
#define CRYPTOPP_WAIT_H

#include "config.h"

#ifdef SOCKETS_AVAILABLE

#include "cryptlib.h"
#include <vector>

#ifdef USE_WINDOWS_STYLE_SOCKETS
#include <windows.h>
#else
#include <sys/types.h>
#endif

NAMESPACE_BEGIN(CryptoPP)

struct WaitingThreadData;

//! container of wait objects
class WaitObjectContainer
{
public:
	//! exception thrown by WaitObjectContainer
	class Err : public Exception
	{
	public:
		Err(const std::string& s) : Exception(IO_ERROR, s) {}
	};

	static unsigned int MaxWaitObjects();

	WaitObjectContainer();

	void Clear();
	void SetNoWait() {m_noWait = true;}
	bool Wait(unsigned long milliseconds);

#ifdef USE_WINDOWS_STYLE_SOCKETS
	~WaitObjectContainer();
	void AddHandle(HANDLE handle);
#else
	void AddReadFd(int fd);
	void AddWriteFd(int fd);
#endif

private:
#ifdef USE_WINDOWS_STYLE_SOCKETS
	void CreateThreads(unsigned int count);
	std::vector<HANDLE> m_handles;
	std::vector<WaitingThreadData *> m_threads;
	HANDLE m_startWaiting;
	HANDLE m_stopWaiting;
#else
	fd_set m_readfds, m_writefds;
	int m_maxFd;
#endif
	bool m_noWait;
};

NAMESPACE_END

#endif

#endif