]>
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)
8 // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org>
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_UNIX_PIPE_H_
13 #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 // return TRUE if we were created successfully
56 bool IsOk() const { return m_fds
[Read
] != INVALID_FD
; }
58 // return the descriptor for one of the pipe ends
59 int operator[](Direction which
) const
61 wxASSERT_MSG( which
>= 0 && (size_t)which
< WXSIZEOF(m_fds
),
62 _T("invalid pipe index") );
67 // detach a descriptor, meaning that the pipe dtor won't close it, and
69 int Detach(Direction which
)
71 wxASSERT_MSG( which
>= 0 && (size_t)which
< WXSIZEOF(m_fds
),
72 _T("invalid pipe index") );
74 int fd
= m_fds
[which
];
75 m_fds
[which
] = INVALID_FD
;
80 // close the pipe descriptors
83 for ( size_t n
= 0; n
< WXSIZEOF(m_fds
); n
++ )
85 if ( m_fds
[n
] != INVALID_FD
)
90 // dtor closes the pipe descriptors
91 ~wxPipe() { Close(); }
99 #include "wx/wfstream.h"
101 // ----------------------------------------------------------------------------
102 // wxPipeInputStream: stream for reading from a pipe
103 // ----------------------------------------------------------------------------
105 class wxPipeInputStream
: public wxFileInputStream
108 wxPipeInputStream(int fd
) : wxFileInputStream(fd
) { }
110 // return TRUE if the pipe is still opened
111 bool IsOpened() const { return !Eof(); }
113 // return TRUE if we have anything to read, don't block
114 virtual bool CanRead() const;
117 #endif // wxUSE_STREAMS
119 #endif // _WX_UNIX_PIPE_H_