Skip to content

Commit

Permalink
net/usrsock: Clear usockid when USRSOCK_EVENT_ABORT is received
Browse files Browse the repository at this point in the history
When usrsock receives a USRSOCK_EVENT_ABORT, it determines that
the usrsock daemon's socket is closed. Then usrsock clears the usockid.
  • Loading branch information
SPRESENSE authored and xiaoxiang781216 committed Sep 24, 2024
1 parent e13d255 commit 6a825f1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions net/usrsock/usrsock.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
#define USRSOCK_EVENT_INTERNAL_MASK (USRSOCK_EVENT_CONNECT_READY | \
USRSOCK_EVENT_REQ_COMPLETE)

#define USRSOCK_USOCKID_INVALID (-1)

/****************************************************************************
* Public Type Definitions
****************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion net/usrsock/usrsock_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int usrsock_close(FAR struct usrsock_conn_s *conn)

close_out:
conn->state = USRSOCK_CONN_STATE_UNINITIALIZED;
conn->usockid = -1;
conn->usockid = USRSOCK_USOCKID_INVALID;

errout:
net_unlock();
Expand Down
4 changes: 2 additions & 2 deletions net/usrsock/usrsock_conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ FAR struct usrsock_conn_s *usrsock_alloc(void)
/* Make sure that the connection is marked as uninitialized */

nxsem_init(&conn->resp.sem, 0, 1);
conn->usockid = -1;
conn->usockid = USRSOCK_USOCKID_INVALID;
conn->state = USRSOCK_CONN_STATE_UNINITIALIZED;

/* Enqueue the connection into the active list */
Expand Down Expand Up @@ -344,7 +344,7 @@ void usrsock_initialize(void)

/* Mark the connection closed and move it to the free list */

conn->usockid = -1;
conn->usockid = USRSOCK_USOCKID_INVALID;
conn->state = USRSOCK_CONN_STATE_UNINITIALIZED;
dq_addlast(&conn->sconn.node, &g_free_usrsock_connections);
}
Expand Down
1 change: 1 addition & 0 deletions net/usrsock/usrsock_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ int usrsock_event(FAR struct usrsock_conn_s *conn)
if (events & USRSOCK_EVENT_ABORT)
{
conn->state = USRSOCK_CONN_STATE_ABORTED;
conn->usockid = USRSOCK_USOCKID_INVALID;
}

if ((conn->state == USRSOCK_CONN_STATE_READY ||
Expand Down

0 comments on commit 6a825f1

Please sign in to comment.