Skip to content

Commit

Permalink
protocol: do not show eof as error
Browse files Browse the repository at this point in the history
  • Loading branch information
tsl0922 committed Dec 27, 2020
1 parent 8fb50ab commit c14b1fe
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/protocol.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,15 @@ static void close_cb(uv_handle_t *handle) {

static void pty_proc_free(struct pty_proc *proc) {
uv_read_stop((uv_stream_t *)&proc->pipe);
uv_close((uv_handle_t *)&proc->pipe, close_cb);

close(proc->pty);

if (proc->pty_buffer != NULL) {
free(proc->pty_buffer);
proc->pty_buffer = NULL;
}

for (int i = 0; i < proc->argc; i++) {
free(proc->args[i]);
}
uv_close((uv_handle_t *)&proc->pipe, close_cb);
}

static void alloc_cb(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf) {
Expand All @@ -120,13 +117,15 @@ static void read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) {

uv_read_stop(stream);

if (nread <= 0) {
if (nread == UV_ENOBUFS || nread == 0) return;
proc->pty_buffer = NULL;
lwsl_err("read_cb: %s (%s)\n", uv_err_name(nread), uv_strerror(nread));
} else {
if (nread == UV_ENOBUFS || nread == 0) return;
if (nread > 0) {
proc->pty_buffer = xmalloc(LWS_PRE + 1 + (size_t)nread);
memcpy(proc->pty_buffer + LWS_PRE + 1, buf->base, (size_t)nread);
} else {
proc->pty_buffer = NULL;
if (nread != UV_EOF) {
lwsl_err("read_cb: %s (%s)\n", uv_err_name(nread), uv_strerror(nread));
}
}
free(buf->base);

Expand Down

0 comments on commit c14b1fe

Please sign in to comment.