00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00047 #ifndef WINSTL_INCL_WINSTL_FILESYSTEM_HPP_PIPE
00048 #define WINSTL_INCL_WINSTL_FILESYSTEM_HPP_PIPE
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_PIPE_MAJOR 4
00052 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_PIPE_MINOR 1
00053 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_PIPE_REVISION 2
00054 # define WINSTL_VER_WINSTL_FILESYSTEM_HPP_PIPE_EDIT 36
00055 #endif
00056
00057
00058
00059
00060
00061 #ifndef WINSTL_INCL_WINSTL_H_WINSTL
00062 # include <winstl/winstl.h>
00063 #endif
00064 #ifndef WINSTL_INCL_WINSTL_ERROR_HPP_WINDOWS_EXCEPTIONS
00065 # include <winstl/error/exceptions.hpp>
00066 #endif
00067
00068
00069
00070
00071
00072 #ifndef _WINSTL_NO_NAMESPACE
00073 # if defined(_STLSOFT_NO_NAMESPACE) || \
00074 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00075
00076 namespace winstl
00077 {
00078 # else
00079
00080
00081 namespace stlsoft
00082 {
00083
00084 namespace winstl_project
00085 {
00086
00087 # endif
00088 #endif
00089
00090
00091
00092
00093
00094 #ifdef __SYNSOFT_DBS_COMPILER_SUPPORTS_PRAGMA_MESSAGE
00095 # pragma message(_sscomp_fileline_message("This needs to be parameterised with a winstl::system_resource_policy, which would control whether to throw if MX create fails"))
00096 #endif
00097
00102 class pipe
00103 {
00106 public:
00108 typedef pipe class_type;
00110 typedef windows_exception_policy exception_policy_type;
00112
00115 public:
00116 ss_explicit_k pipe(ws_uint32_t size = 0, ws_bool_t bInheritHandles = true)
00117 : m_hReadHandle(NULL)
00118 , m_hWriteHandle(NULL)
00119 {
00120 SECURITY_ATTRIBUTES sa;
00121
00122 sa.nLength = sizeof(sa);
00123 sa.lpSecurityDescriptor = NULL;
00124 sa.bInheritHandle = bInheritHandles;
00125
00126 if(!::CreatePipe(&m_hReadHandle, &m_hWriteHandle, &sa, size))
00127 {
00128 exception_policy_type()(::GetLastError());
00129 }
00130 }
00131
00132 ~pipe() stlsoft_throw_0()
00133 {
00134 if(NULL != m_hReadHandle)
00135 {
00136 ::CloseHandle(m_hReadHandle);
00137 }
00138 if(NULL != m_hWriteHandle)
00139 {
00140 ::CloseHandle(m_hWriteHandle);
00141 }
00142 }
00144
00147 public:
00149 HANDLE read_handle() const
00150 {
00151 return m_hReadHandle;
00152 }
00153 HANDLE write_handle() const
00154 {
00155 return m_hWriteHandle;
00156 }
00158
00161 public:
00163 void close_read()
00164 {
00165 if(NULL != m_hReadHandle)
00166 {
00167 ::CloseHandle(m_hReadHandle);
00168
00169 m_hReadHandle = NULL;
00170 }
00171 }
00173 void close_write()
00174 {
00175 if(NULL != m_hWriteHandle)
00176 {
00177 ::CloseHandle(m_hWriteHandle);
00178
00179 m_hReadHandle = NULL;
00180 }
00181 }
00183 void close()
00184 {
00185 close_read();
00186 close_write();
00187 }
00189
00192 private:
00193 HANDLE m_hReadHandle;
00194 HANDLE m_hWriteHandle;
00196
00199 private:
00200 pipe(class_type const&);
00201 class_type& operator =(class_type const&);
00203 };
00204
00206
00207
00208 #ifdef STLSOFT_UNITTEST
00209 # include "./unittest/pipe_unittest_.h"
00210 #endif
00211
00212
00213
00214 #ifndef _WINSTL_NO_NAMESPACE
00215 # if defined(_STLSOFT_NO_NAMESPACE) || \
00216 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00217 }
00218 # else
00219 }
00220 }
00221 # endif
00222 #endif
00223
00224
00225
00226 #endif
00227
00228