summaryrefslogtreecommitdiff
path: root/winpipes.h
diff options
context:
space:
mode:
authorweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-04 17:31:41 +0000
committerweidai <weidai@57ff6487-cd31-0410-9ec3-f628ee90f5f0>2002-10-04 17:31:41 +0000
commitb21162cf8e06f40baa1f58be6a8c17435cebc34d (patch)
tree8b045309c238226c32a563b1df6b9c30a2f0e0b3 /winpipes.h
downloadcryptopp-b21162cf8e06f40baa1f58be6a8c17435cebc34d.tar.gz
Initial revision
git-svn-id: svn://svn.code.sf.net/p/cryptopp/code/trunk/c5@2 57ff6487-cd31-0410-9ec3-f628ee90f5f0
Diffstat (limited to 'winpipes.h')
-rw-r--r--winpipes.h141
1 files changed, 141 insertions, 0 deletions
diff --git a/winpipes.h b/winpipes.h
new file mode 100644
index 0000000..3260e19
--- /dev/null
+++ b/winpipes.h
@@ -0,0 +1,141 @@
+#ifndef CRYPTOPP_WINPIPES_H
+#define CRYPTOPP_WINPIPES_H
+
+#include "config.h"
+
+#ifdef WINDOWS_PIPES_AVAILABLE
+
+#include "network.h"
+#include "queue.h"
+#include <windows.h>
+
+NAMESPACE_BEGIN(CryptoPP)
+
+//! Windows Handle
+class WindowsHandle
+{
+public:
+ WindowsHandle(HANDLE h = INVALID_HANDLE_VALUE, bool own=false);
+ WindowsHandle(const WindowsHandle &h) : m_h(h.m_h), m_own(false) {}
+ virtual ~WindowsHandle();
+
+ bool GetOwnership() const {return m_own;}
+ void SetOwnership(bool own) {m_own = own;}
+
+ operator HANDLE() {return m_h;}
+ HANDLE GetHandle() const {return m_h;}
+ bool HandleValid() const;
+ void AttachHandle(HANDLE h, bool own=false);
+ HANDLE DetachHandle();
+ void CloseHandle();
+
+protected:
+ virtual void HandleChanged() {}
+
+ HANDLE m_h;
+ bool m_own;
+};
+
+//! Windows Pipe
+class WindowsPipe
+{
+public:
+ class Err : public OS_Error
+ {
+ public:
+ Err(HANDLE h, const std::string& operation, int error);
+ HANDLE GetHandle() const {return m_h;}
+
+ private:
+ HANDLE m_h;
+ };
+
+protected:
+ virtual HANDLE GetHandle() const =0;
+ virtual void HandleError(const char *operation) const;
+ void CheckAndHandleError(const char *operation, BOOL result) const
+ {assert(result==TRUE || result==FALSE); if (!result) HandleError(operation);}
+};
+
+//! .
+class WindowsPipeReceiver : public WindowsPipe, public NetworkReceiver
+{
+public:
+ WindowsPipeReceiver();
+
+ bool MustWaitForResult() {return true;}
+ void Receive(byte* buf, unsigned int bufLen);
+ unsigned int GetReceiveResult();
+ bool EofReceived() const {return m_eofReceived;}
+
+ unsigned int GetMaxWaitObjectCount() const {return 1;}
+ void GetWaitObjects(WaitObjectContainer &container);
+
+private:
+ WindowsHandle m_event;
+ OVERLAPPED m_overlapped;
+ bool m_resultPending;
+ DWORD m_lastResult;
+ bool m_eofReceived;
+};
+
+//! .
+class WindowsPipeSender : public WindowsPipe, public NetworkSender
+{
+public:
+ WindowsPipeSender();
+
+ bool MustWaitForResult() {return true;}
+ void Send(const byte* buf, unsigned int bufLen);
+ unsigned int GetSendResult();
+ void SendEof() {}
+
+ unsigned int GetMaxWaitObjectCount() const {return 1;}
+ void GetWaitObjects(WaitObjectContainer &container);
+
+private:
+ WindowsHandle m_event;
+ OVERLAPPED m_overlapped;
+ bool m_resultPending;
+ DWORD m_lastResult;
+};
+
+//! Windows Pipe Source
+class WindowsPipeSource : public WindowsHandle, public NetworkSource, public WindowsPipeReceiver
+{
+public:
+ WindowsPipeSource(HANDLE h=INVALID_HANDLE_VALUE, bool pumpAll=false, BufferedTransformation *attachment=NULL)
+ : WindowsHandle(h), NetworkSource(attachment)
+ {
+ if (pumpAll)
+ PumpAll();
+ }
+
+ NetworkSource::GetMaxWaitObjectCount;
+ NetworkSource::GetWaitObjects;
+
+private:
+ HANDLE GetHandle() const {return WindowsHandle::GetHandle();}
+ NetworkReceiver & AccessReceiver() {return *this;}
+};
+
+//! Windows Pipe Sink
+class WindowsPipeSink : public WindowsHandle, public NetworkSink, public WindowsPipeSender
+{
+public:
+ WindowsPipeSink(HANDLE h=INVALID_HANDLE_VALUE, unsigned int maxBufferSize=0, bool autoFlush=false)
+ : WindowsHandle(h), NetworkSink(maxBufferSize, autoFlush) {}
+
+ NetworkSink::GetMaxWaitObjectCount;
+ NetworkSink::GetWaitObjects;
+
+private:
+ HANDLE GetHandle() const {return WindowsHandle::GetHandle();}
+ NetworkSender & AccessSender() {return *this;}
+};
+
+NAMESPACE_END
+
+#endif
+
+#endif