From f86b0aa1e843646056c08a91fcc759aa0d8a57ba Mon Sep 17 00:00:00 2001 From: pommicket Date: Fri, 8 Sep 2023 19:16:37 -0400 Subject: better LSP over TCP --- lsp-write.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'lsp-write.c') diff --git a/lsp-write.c b/lsp-write.c index 9722a7b..17aef7f 100644 --- a/lsp-write.c +++ b/lsp-write.c @@ -334,10 +334,18 @@ static void message_writer_write_and_free(LSP *lsp, JSONWriter *o) { fprintf(lsp->log, "LSP MESSAGE FROM CLIENT TO SERVER\n%s\n\n", content + header_size); } - if (lsp->socket) - socket_write(lsp->socket, content, strlen(content)); - else - process_write(lsp->process, content, strlen(content)); + long long bytes_written = lsp->socket + ? socket_write(lsp->socket, content, strlen(content)) + : process_write(lsp->process, content, strlen(content)); + + if (bytes_written == -1) { + // we'll handle this properly next time we do a read. + if (lsp->log) fprintf(lsp->log, "LSP server closed connection unexpectedly\n"); + } else if (bytes_written < 0) { + if (lsp->log) fprintf(lsp->log, "Error writing to LSP server (errno = %d)\n", errno); + } else { + assert((size_t)bytes_written == strlen(content)); + } str_builder_free(&builder); } -- cgit v1.2.3