diff options
author | pommicket <pommicket@gmail.com> | 2023-09-08 19:16:37 -0400 |
---|---|---|
committer | pommicket <pommicket@gmail.com> | 2023-09-08 19:16:37 -0400 |
commit | f86b0aa1e843646056c08a91fcc759aa0d8a57ba (patch) | |
tree | 49a48c14c167df8614996d0c5b8d026fc99fc627 /lsp.c | |
parent | 100859239a28c2709bb3e2cdce347300a2b763e2 (diff) |
better LSP over TCP
Diffstat (limited to 'lsp.c')
-rw-r--r-- | lsp.c | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -400,10 +400,21 @@ static bool lsp_receive(LSP *lsp, size_t max_size) { long long bytes_read = lsp->socket ? socket_read(lsp->socket, lsp->received_data + received_so_far, max_size) : process_read(lsp->process, lsp->received_data + received_so_far, max_size); - if (bytes_read <= 0) { + + if (bytes_read == -1) { // no data return true; } + if (bytes_read == 0) { + lsp_set_error(lsp, "LSP server closed connection unexpectedly."); + return false; + } + if (bytes_read < 0) { + if (lsp->log) + fprintf(lsp->log, "Error reading from server (errno = %d).\n", errno); + return true; + } + received_so_far += (size_t)bytes_read; // kind of a hack. this is needed because arr_set_len zeroes the data. arr_hdr_(lsp->received_data)->len = (u32)received_so_far; @@ -704,7 +715,7 @@ void lsp_free(LSP *lsp) { SDL_DestroyMutex(lsp->error_mutex); SDL_DestroySemaphore(lsp->quit_sem); process_kill(&lsp->process); - + socket_close(&lsp->socket); arr_free(lsp->received_data); str_hash_table_clear(&lsp->document_ids); |