Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

wait.h

00001 #ifndef CRYPTOPP_WAIT_H
00002 #define CRYPTOPP_WAIT_H
00003 
00004 #include "cryptopp_config.h"
00005 
00006 #ifdef SOCKETS_AVAILABLE
00007 
00008 #include "cryptlib.h"
00009 #include <vector>
00010 
00011 #ifdef USE_WINDOWS_STYLE_SOCKETS
00012 #include <winsock2.h>
00013 #else
00014 #include <sys/types.h>
00015 #endif
00016 
00017 #ifdef NDEBUG
00018 #define CRYPTOPP_DETECT_NO_WAIT 0
00019 #else
00020 #define CRYPTOPP_DETECT_NO_WAIT 1
00021 #endif
00022 
00023 #if CRYPTOPP_DETECT_NO_WAIT
00024 #include "hrtimer.h"
00025 #endif
00026 
00027 NAMESPACE_BEGIN(CryptoPP)
00028 
00029 struct WaitingThreadData;
00030 
00031 //! container of wait objects
00032 class WaitObjectContainer
00033 {
00034 public:
00035         //! exception thrown by WaitObjectContainer
00036         class Err : public Exception
00037         {
00038         public:
00039                 Err(const std::string& s) : Exception(IO_ERROR, s) {}
00040         };
00041 
00042         static unsigned int MaxWaitObjects();
00043 
00044         WaitObjectContainer();
00045 
00046         void Clear();
00047         void SetNoWait();
00048         bool Wait(unsigned long milliseconds);
00049 
00050 #ifdef USE_WINDOWS_STYLE_SOCKETS
00051         ~WaitObjectContainer();
00052         void AddHandle(HANDLE handle);
00053 #else
00054         void AddReadFd(int fd);
00055         void AddWriteFd(int fd);
00056 #endif
00057 
00058 private:
00059 #ifdef USE_WINDOWS_STYLE_SOCKETS
00060         void CreateThreads(unsigned int count);
00061         std::vector<HANDLE> m_handles;
00062         std::vector<WaitingThreadData *> m_threads;
00063         HANDLE m_startWaiting;
00064         HANDLE m_stopWaiting;
00065 #else
00066         fd_set m_readfds, m_writefds;
00067         int m_maxFd;
00068 #endif
00069         bool m_noWait;
00070 
00071 #if CRYPTOPP_DETECT_NO_WAIT
00072 #ifdef USE_WINDOWS_STYLE_SOCKETS
00073         DWORD m_lastResult;
00074 #else
00075         int m_lastResult;
00076 #endif
00077         unsigned int m_sameResultCount;
00078         Timer m_timer;
00079 #endif
00080 };
00081 
00082 NAMESPACE_END
00083 
00084 #endif
00085 
00086 #endif

Generated on Tue Oct 26 18:51:41 2004 for Crypto++ by  doxygen 1.3.9.1