aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/event/socket.c
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-05-30 12:59:02 +0200
committerbfredl <bjorn.linse@gmail.com>2024-05-31 15:01:13 +0200
commitc13c50b752dca322a5ec77dea6188c9e3694549b (patch)
tree048342b08d13f6df0b9c29b9b0b5d470322e6a0c /src/nvim/event/socket.c
parent6566a59b3a6c8dabfa40f8debd0de96d875825e9 (diff)
downloadrneovim-c13c50b752dca322a5ec77dea6188c9e3694549b.tar.gz
rneovim-c13c50b752dca322a5ec77dea6188c9e3694549b.tar.bz2
rneovim-c13c50b752dca322a5ec77dea6188c9e3694549b.zip
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.
Diffstat (limited to 'src/nvim/event/socket.c')
-rw-r--r--src/nvim/event/socket.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/nvim/event/socket.c b/src/nvim/event/socket.c
index 4e878a2ecf..017f159fa1 100644
--- a/src/nvim/event/socket.c
+++ b/src/nvim/event/socket.c
@@ -135,17 +135,17 @@ int socket_watcher_start(SocketWatcher *watcher, int backlog, socket_cb cb)
return 0;
}
-int socket_watcher_accept(SocketWatcher *watcher, Stream *stream)
+int socket_watcher_accept(SocketWatcher *watcher, RStream *stream)
FUNC_ATTR_NONNULL_ARG(1) FUNC_ATTR_NONNULL_ARG(2)
{
uv_stream_t *client;
if (watcher->stream->type == UV_TCP) {
- client = (uv_stream_t *)(&stream->uv.tcp);
+ client = (uv_stream_t *)(&stream->s.uv.tcp);
uv_tcp_init(watcher->uv.tcp.handle.loop, (uv_tcp_t *)client);
uv_tcp_nodelay((uv_tcp_t *)client, true);
} else {
- client = (uv_stream_t *)&stream->uv.pipe;
+ client = (uv_stream_t *)&stream->s.uv.pipe;
uv_pipe_init(watcher->uv.pipe.handle.loop, (uv_pipe_t *)client, 0);
}
@@ -156,7 +156,7 @@ int socket_watcher_accept(SocketWatcher *watcher, Stream *stream)
return result;
}
- stream_init(NULL, stream, -1, client);
+ stream_init(NULL, &stream->s, -1, client);
return 0;
}
@@ -197,7 +197,7 @@ static void connect_cb(uv_connect_t *req, int status)
}
}
-bool socket_connect(Loop *loop, Stream *stream, bool is_tcp, const char *address, int timeout,
+bool socket_connect(Loop *loop, RStream *stream, bool is_tcp, const char *address, int timeout,
const char **error)
{
bool success = false;
@@ -206,7 +206,7 @@ bool socket_connect(Loop *loop, Stream *stream, bool is_tcp, const char *address
req.data = &status;
uv_stream_t *uv_stream;
- uv_tcp_t *tcp = &stream->uv.tcp;
+ uv_tcp_t *tcp = &stream->s.uv.tcp;
uv_getaddrinfo_t addr_req;
addr_req.addrinfo = NULL;
const struct addrinfo *addrinfo = NULL;
@@ -237,7 +237,7 @@ tcp_retry:
uv_tcp_connect(&req, tcp, addrinfo->ai_addr, connect_cb);
uv_stream = (uv_stream_t *)tcp;
} else {
- uv_pipe_t *pipe = &stream->uv.pipe;
+ uv_pipe_t *pipe = &stream->s.uv.pipe;
uv_pipe_init(&loop->uv, pipe, 0);
uv_pipe_connect(&req, pipe, address, connect_cb);
uv_stream = (uv_stream_t *)pipe;
@@ -245,7 +245,7 @@ tcp_retry:
status = 1;
LOOP_PROCESS_EVENTS_UNTIL(&main_loop, NULL, timeout, status != 1);
if (status == 0) {
- stream_init(NULL, stream, -1, uv_stream);
+ stream_init(NULL, &stream->s, -1, uv_stream);
success = true;
} else if (is_tcp && addrinfo->ai_next) {
addrinfo = addrinfo->ai_next;