Crypto++  5.6.5
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  virtual ~WindowsHandle();
20 
21  WindowsHandle(HANDLE h = INVALID_HANDLE_VALUE, bool own=false);
22  WindowsHandle(const WindowsHandle &h) : m_h(h.m_h), m_own(false) {}
23 
24  bool GetOwnership() const {return m_own;}
25  void SetOwnership(bool own) {m_own = own;}
26 
27  operator HANDLE() const {return m_h;}
28  HANDLE GetHandle() const {return m_h;}
29  bool HandleValid() const;
30  void AttachHandle(HANDLE h, bool own=false);
31  HANDLE DetachHandle();
32  void CloseHandle();
33 
34 protected:
35  virtual void HandleChanged() {}
36 
37  HANDLE m_h;
38  bool m_own;
39 };
40 
41 //! \brief Windows Pipe
43 {
44 public:
45  class Err : public OS_Error
46  {
47  public:
48  Err(HANDLE h, const std::string& operation, int error);
49  HANDLE GetHandle() const {return m_h;}
50 
51  private:
52  HANDLE m_h;
53  };
54 
55 protected:
56  virtual HANDLE GetHandle() const =0;
57  virtual void HandleError(const char *operation) const;
58  void CheckAndHandleError(const char *operation, BOOL result) const
59  {if (!result) HandleError(operation);}
60 };
61 
62 //! \brief Pipe-based implementation of NetworkReceiver
64 {
65 public:
67 
68  bool MustWaitForResult() {return true;}
69  bool Receive(byte* buf, size_t bufLen);
70  unsigned int GetReceiveResult();
71  bool EofReceived() const {return m_eofReceived;}
72 
73  HANDLE GetHandle() const {return m_event;}
74  unsigned int GetMaxWaitObjectCount() const {return 1;}
75  void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack);
76 
77 private:
78  WindowsHandle m_event;
79  OVERLAPPED m_overlapped;
80  DWORD m_lastResult;
81  bool m_resultPending;
82  bool m_eofReceived;
83 };
84 
85 //! \brief Pipe-based implementation of NetworkSender
87 {
88 public:
90 
91  bool MustWaitForResult() {return true;}
92  void Send(const byte* buf, size_t bufLen);
93  unsigned int GetSendResult();
94  bool MustWaitForEof() { return false; }
95  void SendEof() {}
96 
97  HANDLE GetHandle() const {return m_event;}
98  unsigned int GetMaxWaitObjectCount() const {return 1;}
99  void GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack);
100 
101 private:
102  WindowsHandle m_event;
103  OVERLAPPED m_overlapped;
104  DWORD m_lastResult;
105  bool m_resultPending;
106 };
107 
108 //! \brief Windows Pipe Source
110 {
111 public:
112  WindowsPipeSource(HANDLE h=INVALID_HANDLE_VALUE, bool pumpAll=false, BufferedTransformation *attachment=NULL)
113  : WindowsHandle(h), NetworkSource(attachment)
114  {
115  if (pumpAll)
116  PumpAll();
117  }
118 
121 
122 private:
123  HANDLE GetHandle() const {return WindowsHandle::GetHandle();}
124  NetworkReceiver & AccessReceiver() {return *this;}
125 };
126 
127 //! \brief Windows Pipe Sink
129 {
130 public:
131  WindowsPipeSink(HANDLE h=INVALID_HANDLE_VALUE, unsigned int maxBufferSize=0, unsigned int autoFlushBound=16*1024)
132  : WindowsHandle(h), NetworkSink(maxBufferSize, autoFlushBound) {}
133 
136 
137 private:
138  HANDLE GetHandle() const {return WindowsHandle::GetHandle();}
139  NetworkSender & AccessSender() {return *this;}
140 };
141 
142 NAMESPACE_END
143 
144 #endif // WINDOWS_PIPES_AVAILABLE
145 
146 #endif
Network Source.
Definition: network.h:164
container of wait objects
Definition: wait.h:169
The operating system reported an error.
Definition: cryptlib.h:219
unsigned int GetMaxWaitObjectCount() const
Maximum number of wait objects that this object can return.
Definition: winpipes.h:98
void PumpAll()
Pump all data to attached transformation.
Definition: filters.h:1270
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:74
Library configuration file.
Pipe-based implementation of NetworkReceiver.
Definition: winpipes.h:63
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: network.cpp:246
Windows Pipe Source.
Definition: winpipes.h:109
Interface for buffered transformations.
Definition: cryptlib.h:1352
Windows Pipe.
Definition: winpipes.h:42
unsigned int GetMaxWaitObjectCount() const
Retrieves the maximum number of waitable objects.
Definition: network.cpp:405
Pipe-based implementation of NetworkSender.
Definition: winpipes.h:86
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: winpipes.cpp:200
Classes for an unlimited queue to store bytes.
void GetWaitObjects(WaitObjectContainer &container, CallStack const &callStack)
Retrieves waitable objects.
Definition: winpipes.cpp:130
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:128
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