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 UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_PIPE
00048 #define UNIXSTL_INCL_UNIXSTL_FILESYSTEM_HPP_PIPE
00049
00050 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00051 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_PIPE_MAJOR 4
00052 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_PIPE_MINOR 1
00053 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_PIPE_REVISION 1
00054 # define UNIXSTL_VER_UNIXSTL_FILESYSTEM_HPP_PIPE_EDIT 43
00055 #endif
00056
00057
00058
00059
00060
00061 #ifndef UNIXSTL_INCL_UNIXSTL_H_UNIXSTL
00062 # include <unixstl/unixstl.h>
00063 #endif
00064 #ifndef UNIXSTL_INCL_UNIXSTL_HPP_ERROR_UNIX_EXCEPTIONS
00065 # include <unixstl/error/exceptions.hpp>
00066 #endif
00067
00068
00069
00070
00071
00072 #ifndef _UNIXSTL_NO_NAMESPACE
00073 # if defined(_STLSOFT_NO_NAMESPACE) || \
00074 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00075
00076 namespace unixstl
00077 {
00078 # else
00079
00080
00081 namespace stlsoft
00082 {
00083
00084 namespace unixstl_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 unixstl::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 unix_exception_policy exception_policy_type;
00112
00115 public:
00116 pipe()
00117 {
00118 #if defined(_WIN32) && \
00119 ( defined(_MSC_VER) || \
00120 defined(STLSOFT_COMPILER_IS_DMC))
00121 if(0 != ::_pipe(&m_handles[0], 10240, _O_TEXT))
00122 #else
00123 if(0 != ::pipe(&m_handles[0]))
00124 #endif
00125 {
00126 exception_policy_type()(errno);
00127
00128 m_handles[0] = -1;
00129 m_handles[1] = -1;
00130 }
00131 }
00132
00133 ~pipe() stlsoft_throw_0()
00134 {
00135 if(-1 != read_handle())
00136 {
00137 ::close(m_handles[0]);
00138 }
00139 if(-1 != write_handle())
00140 {
00141 ::close(m_handles[1]);
00142 }
00143 }
00145
00148 public:
00150 int read_handle() const
00151 {
00152 return m_handles[0];
00153 }
00154 int write_handle() const
00155 {
00156 return m_handles[1];
00157 }
00159
00162 public:
00164 void close_read()
00165 {
00166 if(-1 != read_handle())
00167 {
00168 ::close(m_handles[0]);
00169 m_handles[0] = -1;
00170 }
00171 }
00173 void close_write()
00174 {
00175 if(-1 != write_handle())
00176 {
00177 ::close(m_handles[1]);
00178 m_handles[1] = -1;
00179 }
00180 }
00182 void close()
00183 {
00184 close_read();
00185 close_write();
00186 }
00188
00191 private:
00192 int m_handles[2];
00194
00197 private:
00198 pipe(class_type const&);
00199 class_type& operator =(class_type const&);
00201 };
00202
00204
00205
00206 #ifdef STLSOFT_UNITTEST
00207 # include "./unittest/pipe_unittest_.h"
00208 #endif
00209
00210
00211
00212 #ifndef _UNIXSTL_NO_NAMESPACE
00213 # if defined(_STLSOFT_NO_NAMESPACE) || \
00214 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00215 }
00216 # else
00217 }
00218 }
00219 # endif
00220 #endif
00221
00222
00223
00224 #endif
00225
00226