I thought about something like that too, but then I wondered if it's really necessary. In Windows we need to open a named pipe internally even when the user requests anonymous pipe, because a named pipe is the only way to achieve something like select. So that would make that scenario really awkward.<br><div><br></div><div>It seems like we can do the same thing as you've suggested but without the inheritance. </div><div><br></div><div>Error Create(llvm::StringRef name); // name is optional</div><div><span style="line-height:19.7999992370605px">Error OpenReader(llvm::StringRef name); // name is required</span><br></div><div><span style="line-height:19.7999992370605px">Error OpenWriter(llvm::StringRef name); // name is required</span></div><div><br></div><div>Error Read(buf, size, bytes_read);</div><div>Error ReadWithTimeout(buf, size, timeout, bytes_read);</div><div><br></div><div>I would prefer not having to specify the non-blocking option. The reason is that if user doesn't specify nonblocking, then ReadWithTimeout is an invalid method to call. And if they do specify non-blocking, the implementation of Read() changes.</div><div><br></div><div>But we can always support both methods if we always open the pipe nonblocking. In read you just implement the block yourself even though the pipe is opened with O_NONBLOCK</div><br><div class="gmail_quote">On Thu Dec 04 2014 at 2:15:18 PM Oleksiy Vyalov <<a href="mailto:ovyalov@google.com">ovyalov@google.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm thinking about having Pipe class as a base class with derived AnonymousPipe and NamedPipe.<br>
<br>
AnonymousPipe will be almost replica of existing Pipe class with custom Open(OpenOptions opts) method.<br>
NamedPipe will have following own methods:<br>
<br>
enum OpenOptions<br>
{<br>
eOpenOptionNonBlocking = (1u << 0), // Non-blocking reads<br>
eOpenChildProcessesInherit = (1u << 1) // Child processes inherit<br>
};<br>
<br>
<br>
```<br>
explicit NamedPipe(const char* name);<br>
<br>
bool Create(); //mkfifo<br>
bool Delete(); //Close() & unlink<br>
<br>
bool OpenReader(OpenOptions opts);<br>
bool OpenWriter(OpenOptions opts);<br>
```<br>
<br>
For named pipes we don't need to have both reader & writer opened in the same processes - so, that's why I think we may need separate open methods.<br>
In order to read with timeout pipe should be opened in non-blocking mode - on Windows you may use PIPE_NOWAIT if such option is set.<br>
<br>
<a href="http://reviews.llvm.org/D6538" target="_blank">http://reviews.llvm.org/D6538</a><br>
<br>
<br>
</blockquote></div>