]>
git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/pipe.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/pipe.h
3 // Purpose: wxPipe class
4 // Author: Vadim Zeitlin
6 // Created: 24.06.2003 (extracted from src/unix/utilsunx.cpp)
7 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwidgets.org>
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_UNIX_PIPE_H_
12 #define _WX_UNIX_PIPE_H_
20 // ----------------------------------------------------------------------------
21 // wxPipe: this class encapsulates pipe() system call
22 // ----------------------------------------------------------------------------
27 // the symbolic names for the pipe ends
39 // default ctor doesn't do anything
40 wxPipe() { m_fds
[Read
] = m_fds
[Write
] = INVALID_FD
; }
42 // create the pipe, return TRUE if ok, FALSE on error
45 if ( pipe(m_fds
) == -1 )
47 wxLogSysError(_("Pipe creation failed"));
55 // switch the given end of the pipe to non-blocking IO
56 bool MakeNonBlocking(Direction which
)
58 const int flags
= fcntl(m_fds
[which
], F_GETFL
, 0);
62 return fcntl(m_fds
[which
], F_SETFL
, flags
| O_NONBLOCK
) == 0;
65 // return TRUE if we were created successfully
66 bool IsOk() const { return m_fds
[Read
] != INVALID_FD
; }
68 // return the descriptor for one of the pipe ends
69 int operator[](Direction which
) const { return m_fds
[which
]; }
71 // detach a descriptor, meaning that the pipe dtor won't close it, and
73 int Detach(Direction which
)
75 int fd
= m_fds
[which
];
76 m_fds
[which
] = INVALID_FD
;
81 // close the pipe descriptors
84 for ( size_t n
= 0; n
< WXSIZEOF(m_fds
); n
++ )
86 if ( m_fds
[n
] != INVALID_FD
)
89 m_fds
[n
] = INVALID_FD
;
94 // dtor closes the pipe descriptors
95 ~wxPipe() { Close(); }
101 #endif // _WX_UNIX_PIPE_H_