Skip to content

Commit

Permalink
test: don't close connection on write error
Browse files Browse the repository at this point in the history
The echo server shouldn't close the connection when there's an error on
write. Instead simply echo the error message and allow the other side to
close the connection.

Also do a partial revert of 4d905fb where after_shutdown was removed.

Fixes: 4d905fb "test: close stream immediately on error"
Signed-off-by: Trevor Norris <[email protected]>
Signed-off-by: Saúl Ibarra Corretgé <[email protected]>
  • Loading branch information
trevnorris authored and saghul committed Sep 10, 2014
1 parent 54ce3f6 commit 3d38eae
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions test/echo-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,21 @@ static void after_write(uv_write_t* req, int status) {
/* Free the read/write buffer and the request */
wr = (write_req_t*) req;
free(wr->buf.base);
free(wr);

if (status == 0) {
free(wr);
if (status == 0)
return;
}

fprintf(stderr,
"uv_write error: %s - %s\n",
uv_err_name(status),
uv_strerror(status));
}

if (!uv_is_closing((uv_handle_t*) req->handle))
uv_close((uv_handle_t*) req->handle, on_close);
free(wr);

static void after_shutdown(uv_shutdown_t* req, int status) {
uv_close((uv_handle_t*) req->handle, on_close);
free(req);
}


Expand All @@ -73,16 +74,15 @@ static void after_read(uv_stream_t* handle,
const uv_buf_t* buf) {
int i;
write_req_t *wr;
uv_shutdown_t* sreq;

if (nread < 0) {
/* Error or EOF */
ASSERT(nread == UV_EOF);

if (buf->base) {
free(buf->base);
}

uv_close((uv_handle_t*) handle, on_close);
free(buf->base);
sreq = malloc(sizeof* sreq);
ASSERT(0 == uv_shutdown(sreq, handle, after_shutdown));
return;
}

Expand Down

0 comments on commit 3d38eae

Please sign in to comment.