Crypto++  5.6.3
Free C++ class library of cryptographic schemes
winpipes.h
1 #ifndef CRYPTOPP_WINPIPES_H
2 #define CRYPTOPP_WINPIPES_H
3 
4 #include "config.h"
5 
6 #if !defined(NO_OS_DEPENDENCE) && defined(WINDOWS_PIPES_AVAILABLE)
7 
8 #include "cryptlib.h"
9 #include "network.h"
10 #include "queue.h"
11 #include <winsock2.h>
12 
13 NAMESPACE_BEGIN(CryptoPP)
14 
15 //! \brief Windows Handle
17 {
18 public:
19  WindowsHandle(HANDLE h = INVALID_HANDLE_VALUE, bool own=false);
20  WindowsHandle(const WindowsHandle &h) : m_h(h.m_h), m_own(false) {}
21  virtual ~WindowsHandle();
22 
23  bool GetOwnership() const {return m_own;}
24  void SetOwnership(bool own) {m_own = own;}
25 
26  operator HANDLE() const {return m_h;}
27  HANDLE GetHandle() const {return m_h;}
28  bool HandleValid() const;
29  void AttachHandle(HANDLE h, bool own=false);
30  HANDLE DetachHandle();
31  void CloseHandle();
32 
33 protected:
34  virtual void HandleChanged() {}
35 
36  HANDLE m_h;
37  bool m_own;
38 };
39 
40 //! \brief Windows Pipe
42 {
43 public:
44  class Err : public OS_Error
45  {
46  public:
47  Err(HANDLE h, const std::string& operation, int error);
48  HANDLE GetHandle() const {return m_h;}
49 
50  private:
51  HANDLE m_h;
52  };
53 
54 protected:
55  virtual HANDLE GetHandle() const =0;
56  virtual void HandleError(const char *operation) const;
57  void CheckAndHandleError(const char *operation, BOOL result) const
58  {assert(result==TRUE || result==FALSE); if (!result) HandleError(operation);}
59 };
60 
61 //! \brief Pipe-based implementation of NetworkReceiver
63 {
64 public:
66 
67  bool MustWaitForResult() {return true;}
68  bool Receive(byte* buf, size_t bufLen);
69  unsigned int GetReceiveResult();
70  bool EofReceived() const {return m_eofReceived;}
71 
72  HANDLE GetHandle() const {return m_event;}
73  unsigned int GetMaxWaitObjectCount() const {return 1;}
74  void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack);
75 
76 private:
77  WindowsHandle m_event;
78  OVERLAPPED m_overlapped;
79  bool m_resultPending;
80  DWORD m_lastResult;
81  bool m_eofReceived;
82 };
83 
84 //! \brief Pipe-based implementation of NetworkSender
86 {
87 public:
89 
90  bool MustWaitForResult() {return true;}
91  void Send(const byte* buf, size_t bufLen);
92  unsigned int GetSendResult();
93  bool MustWaitForEof() { return false; }
94  void SendEof() {}
95 
96  HANDLE GetHandle() const {return m_event;}
97  unsigned int GetMaxWaitObjectCount() const {return 1;}
98  void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack);
99 
100 private:
101  WindowsHandle m_event;
102  OVERLAPPED m_overlapped;
103  bool m_resultPending;
104  DWORD m_lastResult;
105 };
106 
107 //! \brief Windows Pipe Source
109 {
110 public:
111  WindowsPipeSource(HANDLE h=INVALID_HANDLE_VALUE, bool pumpAll=false, BufferedTransformation *attachment=NULL)
112  : WindowsHandle(h), NetworkSource(attachment)
113  {
114  if (pumpAll)
115  PumpAll();
116  }
117 
120 
121 private:
122  HANDLE GetHandle() const {return WindowsHandle::GetHandle();}
123  NetworkReceiver & AccessReceiver() {return *this;}
124 };
125 
126 //! \brief Windows Pipe Sink
128 {
129 public:
130  WindowsPipeSink(HANDLE h=INVALID_HANDLE_VALUE, unsigned int maxBufferSize=0, unsigned int autoFlushBound=16*1024)
131  : WindowsHandle(h), NetworkSink(maxBufferSize, autoFlushBound) {}
132 
135 
136 private:
137  HANDLE GetHandle() const {return WindowsHandle::GetHandle();}
138  NetworkSender & AccessSender() {return *this;}
139 };
140 
141 NAMESPACE_END
142 
143 #endif // WINDOWS_PIPES_AVAILABLE
144 
145 #endif
Network Source.
Definition: network.h:164
container of wait objects
Definition: wait.h:169
The operating system reported an error.
Definition: cryptlib.h:217
unsigned int GetMaxWaitObjectCount() const
Maximum number of wait objects that this object can return.
Definition: winpipes.h:97
void PumpAll()
Pump all data to attached transformation.
Definition: filters.h:1181
Abstract base classes that provide a uniform interface to this library.
unsigned int GetMaxWaitObjectCount() const
Maximum number of wait objects that this object can return.
Definition: winpipes.h:73
Library configuration file.
Pipe-based implementation of NetworkReceiver.
Definition: winpipes.h:62
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: network.cpp:246
Windows Pipe Source.
Definition: winpipes.h:108
Interface for buffered transformations.
Definition: cryptlib.h:1352
Windows Pipe.
Definition: winpipes.h:41
unsigned int GetMaxWaitObjectCount() const
Retrieves the maximum number of waitable objects.
Definition: network.cpp:405
Pipe-based implementation of NetworkSender.
Definition: winpipes.h:85
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: winpipes.cpp:198
Classes for an unlimited queue to store bytes.
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: winpipes.cpp:129
bool Receive(byte *buf, size_t bufLen)
receive data from network source, returns whether result is immediately available ...
Definition: winpipes.cpp:100
Windows Pipe Sink.
Definition: winpipes.h:127
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: network.cpp:410
unsigned int GetMaxWaitObjectCount() const
Retrieves the maximum number of waitable objects.
Definition: network.cpp:239
Crypto++ library namespace.
Windows Handle.
Definition: winpipes.h:16
Network Receiver.
Definition: network.h:93
Network Sink.
Definition: network.h:187
Network Sender.
Definition: network.h:151