@sehe async_pipe doesn't do what I want from both ends, anyways. Client gets a "file already exists" error when trying to construct an async_pipe with the name given to it from the server.
@sehe Doing IPC through stdout/stdin just seems so weird to me. And prone to issues; any code anywhere in the program can write to stdout or read from stdin at any time (although the latter is admittedly unlikely).
@sehe I spent what coding time I had since posting the question adjusting my code with the conditional compilation stuff I mentioned above. It is compiling now but giving me runtime errors I haven't been able to diagnose yet. So I don't know for sure yet, but I expect it will work based on what I know of FIFO (and async_pipe wraps FIFO, does it not?)
Some kind of conditional compilation + typedef magic, where I use async_pipe on linux and stream_handle on Windows seems like my next-likeliest option, but the stream_handle is giving me the issue I described in my question.
So to level set, what I want is: * FIFO on linux * Named Pipes on Windows Wrapped up in a cross-platform way, preferably using native async APIs (e.g. overlapped I/O APIs on Windows)
@sehe Right, it's more "native" now. Unix Domain Sockets are my next point of investigation, but I'm more wary of them for backwards compatibility purposes. Unfortunately I think some of my ultimate end users are still on older versions of Windows.
As my example code implies, I want to use named pipes for IPC. Typical IPC with named pipes (on Windows, at least) involves a "server" and a "client" which use different APIs; the "server" creates the named pipe and then waits for a connection from a client. The "client" connects to an already extant named pipe. This is the kind of behavior I'm looking for (a parent process spawning a child process) and is essentially what my code in this question does using stream_handles. And it mostly works! Except for the read on the server side.
Also, async_read_some is not swallowing errors. Perhaps not, but when I try to Peek at the contents of the pipe while waiting for my async read operation to complete, I get a "pipe closed" error and my async read operation times out before completing or giving me any error.
@sehe async_pipe ... saves you all the trouble of setting up the pipes This was part of the problem, I think. It sets the pipes up to be used a certain way, which was not the way I wanted. I looked at the code, and it does not match any of the examples of how to set up named pipes in Windows that I could find. There is also no way in the async_pipe API to distinguish between read-only access, write-only access, or duplex acces; not to mention server vs. client. I think it was designed to be used in a very specific way, and that way is not the way I wanted.
Hey sehe, thanks for stopping by. All the code in this question is using boost::asio::windows::stream_handle and calling the async_*_some APIs. I understand the confusion, since I included the async_pipe.hpp header (will edit that out) but you will note that I am not actually using them in the code (I was using them in place of stream_handle in my first try, but they didn't work at all). What I am trying to achieve is use named pipes asynchronously on Windows (and eventually Unix) without writing the low-level code myself. boost::asio is the first thing I am trying.
I suspect that async_read_some is swallowing errors. When I try to peek at the pipe from another thread while waiting for the read to time out, I get "pipe closed" errors. But async_read_some claims that it will surface any errors it gets from the APIs. Why isn't it telling me that the pipe is closed? Under the hypothesis that maybe the synchronous API would give me the errors, I wrote the code in my "answer" and then it turned out that code worked, which didn't get me any closer to finding out why the async API isn't working.
What I have read about microservices is that the best route to them is to first write a monolith, and then refactor bits of it into separate services as necessary.