refactor(io): separate types for read and write streams

This is a structural refactor with no logical changes, yet. Done in
preparation for simplifying rstream/rbuffer which will require more
state inline in RStream.

The initial idea was to have RStream and WStream as sub-types
symetrically but that doesn't work, as sockets are both reading and
writing. Also there is very little write-specific state to start with,
so the benefit of a separate WStream struct is a lot smaller. Just
document what fields in `Stream` are write specific.
This commit is contained in:
bfredl
2024-05-30 12:59:02 +02:00
parent 6566a59b3a
commit c13c50b752
18 changed files with 158 additions and 132 deletions

View File

@@ -30,7 +30,7 @@ struct Channel {
Process proc;
LibuvProcess uv;
PtyProcess pty;
Stream socket;
RStream socket;
StdioPair stdio;
StderrState err;
InternalState internal;
@@ -73,7 +73,7 @@ static inline Stream *channel_instream(Channel *chan)
return &chan->stream.proc.in;
case kChannelStreamSocket:
return &chan->stream.socket;
return &chan->stream.socket.s;
case kChannelStreamStdio:
return &chan->stream.stdio.out;
@@ -85,10 +85,10 @@ static inline Stream *channel_instream(Channel *chan)
abort();
}
static inline Stream *channel_outstream(Channel *chan)
static inline RStream *channel_outstream(Channel *chan)
REAL_FATTR_NONNULL_ALL;
static inline Stream *channel_outstream(Channel *chan)
static inline RStream *channel_outstream(Channel *chan)
{
switch (chan->streamtype) {
case kChannelStreamProc: