diff options
-rw-r--r-- | build.c | 4 | ||||
-rw-r--r-- | lsp.c | 18 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | os-posix.c | 4 | ||||
-rw-r--r-- | os-win.c | 6 | ||||
-rw-r--r-- | os.h | 8 |
6 files changed, 14 insertions, 28 deletions
@@ -357,10 +357,10 @@ void build_frame(Ted *ted, float x1, float y1, float x2, float y2) { ted_error(ted, "Error reading command output: %s.", process_geterr(ted->build_process)); build_stop(ted); break; - } else if (bytes_read == -1) { + } else if (bytes_read == 0) { // no data right now. break; - } else if (bytes_read == 0) { + } else if (bytes_read == -1) { // end of file break; } else { @@ -424,11 +424,11 @@ static bool lsp_receive(LSP *lsp, size_t max_size) { ? 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 == -1) { + if (bytes_read == 0) { // no data return true; } - if (bytes_read == 0) { + if (bytes_read == -1) { lsp_set_error(lsp, "LSP server closed connection unexpectedly."); return false; } @@ -613,20 +613,6 @@ static int lsp_communication_thread(void *data) { // response, but who gives a fuck write_request(lsp, &shutdown); write_request(lsp, &exit); - - #if 0 - char buf[1024]={0}; - long long n = process_read(&lsp->process, buf, sizeof buf); - if (n>0) { - buf[n]=0; - printf("%s\n",buf); - } - n = process_read_stderr(&lsp->process, buf, sizeof buf); - if (n>0) { - buf[n]=0; - printf("\x1b[1m%s\x1b[0m\n",buf); - } - #endif } return 0; } @@ -1,4 +1,6 @@ /* +TODO: +- put exact match first in selector FUTURE FEATURES: - autodetect indentation (tabs vs spaces) - custom file/build command associations @@ -285,10 +285,8 @@ static long long read_fd(int fd, char *error, size_t error_size, char *data, siz ssize_t bytes_read = read(fd, data + so_far, size - so_far); if (bytes_read > 0) { so_far += (size_t)bytes_read; - } else if (bytes_read == 0) { + } else if (bytes_read == 0 || errno == EAGAIN || errno == EWOULDBLOCK) { return (long long)so_far; - } else if (errno == EAGAIN || errno == EWOULDBLOCK) { - return so_far == 0 ? -1 : (long long)so_far; } else if (errno == EPIPE) { return -1; } else { @@ -302,7 +302,7 @@ static long long process_read_handle(Process *process, HANDLE pipe, char *data, DWORD bytes_read = 0, bytes_avail = 0, bytes_left = 0; if (PeekNamedPipe(pipe, data, (DWORD)size, &bytes_read, &bytes_avail, &bytes_left)) { if (bytes_read == 0) { - return -1; + return 0; } else { ReadFile(pipe, data, (DWORD)size, &bytes_read, NULL); // make sure data is removed from pipe return bytes_read; @@ -490,9 +490,9 @@ long long socket_read(Socket *s, char *data, size_t size) { } else { int err = WSAGetLastError(); if (err == WSAEWOULDBLOCK) { - return so_far == 0 ? -1 : (long long)so_far; + return (long long)so_far; } else if (err == WSAECONNRESET) { - return 0; + return -1; } else { strbuf_printf(s->error, "recv failed (error code %d)", err); return -2; @@ -136,8 +136,8 @@ long long process_write(Process *process, const char *data, size_t size); /// /// \returns /// -2 on error\n -/// -1 if no data is available right now\n -/// 0 on end of file\n +/// -1 on end of file\n +/// 0 if no data is available right now\n /// or a positive number indicating the number of bytes read to `data` (at most `size`)\n /// This does a nonblocking read. long long process_read(Process *process, char *data, size_t size); @@ -177,8 +177,8 @@ const char *socket_get_error(Socket *socket); /// /// \returns /// -2 on error\n -/// -1 if no data is available right now\n -/// 0 on end of file\n +/// -1 on end of file\n +/// 0 if no data is available right now\n /// or a positive number indicating the number of bytes read to `data` (at most `size`)\n /// This does a nonblocking read. long long socket_read(Socket *socket, char *data, size_t size); |