In full-duplex mode,sock->fd_used != 0 prevents a socket descriptor from being * released (and possibly reused) when used from more than one thread * (e.g. read-while-write or close-while-write, etc) * This function is called at the end of functions using (try)get_socket*(). */
| 374 | * This function is called at the end of functions using (try)get_socket*(). |
| 375 | */ |
| 376 | static void |
| 377 | done_socket(struct lwip_sock *sock) |
| 378 | { |
| 379 | int freed = 0; |
| 380 | int is_tcp = 0; |
| 381 | struct netconn *conn = NULL; |
| 382 | union lwip_sock_lastdata lastdata; |
| 383 | SYS_ARCH_DECL_PROTECT(lev); |
| 384 | LWIP_ASSERT("sock != NULL", sock != NULL); |
| 385 | |
| 386 | SYS_ARCH_PROTECT(lev); |
| 387 | LWIP_ASSERT("sock->fd_used > 0", sock->fd_used > 0); |
| 388 | if (--sock->fd_used == 0) { |
| 389 | if (sock->fd_free_pending) { |
| 390 | /* free the socket */ |
| 391 | sock->fd_used = 1; |
| 392 | is_tcp = sock->fd_free_pending & LWIP_SOCK_FD_FREE_TCP; |
| 393 | freed = free_socket_locked(sock, is_tcp, &conn, &lastdata); |
| 394 | } |
| 395 | } |
| 396 | SYS_ARCH_UNPROTECT(lev); |
| 397 | |
| 398 | if (freed) { |
| 399 | free_socket_free_elements(is_tcp, conn, &lastdata); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | #else /* LWIP_NETCONN_FULLDUPLEX */ |
| 404 | #define sock_inc_used(sock) 1 |
no test coverage detected