Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

Commit

Permalink
[net] Mark socket as "closing" between EOF and close event
Browse files Browse the repository at this point in the history
Then check for this closing flag to know that write will fail and not
bother attempting it.

Fixes #1512 (the follow-on report of failure on A101 w/ Ethernet)

Signed-off-by: Geoff Gustafson <geoff@linux.intel.com>
  • Loading branch information
grgustaf committed Sep 8, 2017
1 parent ecf907e commit 3a434af
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/zjs_net.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ typedef struct sock_handle {
u8_t paused;
u8_t *rbuf;
u8_t timer_started;
u8_t closing;
u8_t closed;
} sock_handle_t;

Expand Down Expand Up @@ -511,6 +512,7 @@ static void tcp_received(struct net_context *context,
DBG_PRINT("socket=%p\n", (void *)handle->socket);
// NOTE: we're not really releasing anything but release_close will
// just ignore the 0 args, so we can reuse the function
handle->closing = 1;
zjs_defer_emit_event(handle->socket, "close", NULL, 0, NULL,
release_close);
}
Expand Down Expand Up @@ -587,7 +589,7 @@ static ZJS_DECL_FUNC(socket_write)
GET_SOCK_HANDLE_JS(this, handle);

// FIXME: these other error cases should maybe call "error" event too
if (handle->closed) {
if (handle->closing || handle->closed) {
ERR_PRINT("socket already closed\n");
return jerry_create_boolean(false);
}
Expand Down Expand Up @@ -628,7 +630,7 @@ static ZJS_DECL_FUNC(socket_write)
error_desc_t desc = create_error_desc(ERROR_WRITE_SOCKET, this,
function_obj);
zjs_defer_emit_event(handle->socket, "error", &desc, sizeof(desc),
handle_error_arg, release_close);
handle_error_arg, zjs_release_args);
return jerry_create_boolean(false);
}

Expand Down

0 comments on commit 3a434af

Please sign in to comment.