Skip to content

Commit 54069b1

Browse files
committed
fixup! lwip: provide sock_async support
1 parent aaa644b commit 54069b1

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

pkg/lwip/contrib/sock/lwip_sock.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
#include "lwip/err.h"
2525
#include "lwip/ip.h"
26+
#include "lwip/tcp.h"
2627
#include "lwip/netif.h"
2728
#include "lwip/opt.h"
2829

@@ -262,7 +263,7 @@ static void _netconn_cb(struct netconn *conn, enum netconn_evt evt,
262263
{
263264
#if IS_ACTIVE(SOCK_HAS_ASYNC)
264265
lwip_sock_base_t *sock = netconn_get_callback_arg(conn);
265-
if (sock &&
266+
if (sock && conn->pcb.raw &&
266267
/* lwIP's TCP implementation initializes callback_arg.socket with -1
267268
* when not provided */
268269
(conn->callback_arg.socket != -1)) {
@@ -273,16 +274,21 @@ static void _netconn_cb(struct netconn *conn, enum netconn_evt evt,
273274
case NETCONN_EVT_RCVPLUS:
274275
if (LWIP_TCP && (conn->type & NETCONN_TCP)) {
275276
#if LWIP_TCP /* additional guard needed due to dependent member access */
276-
unsigned accepts = cib_avail(&conn->acceptmbox.mbox.cib);
277-
if (accepts) {
277+
switch (conn->pcb.tcp->state) {
278+
case CLOSED:
279+
case CLOSE_WAIT:
280+
case CLOSING:
281+
flags |= SOCK_ASYNC_CONN_FIN;
282+
break;
283+
default:
284+
break;
285+
}
286+
if (cib_avail(&conn->acceptmbox.mbox.cib)) {
278287
flags |= SOCK_ASYNC_CONN_RECV;
279288
}
280289
if (cib_avail(&conn->recvmbox.mbox.cib)) {
281290
flags |= SOCK_ASYNC_MSG_RECV;
282291
}
283-
else if ((len == 0) && (accepts == 0)) {
284-
flags |= SOCK_ASYNC_CONN_FIN;
285-
}
286292
#endif
287293
}
288294
else {
@@ -294,6 +300,7 @@ static void _netconn_cb(struct netconn *conn, enum netconn_evt evt,
294300
break;
295301
case NETCONN_EVT_ERROR:
296302
if (LWIP_TCP && (conn->type & NETCONN_TCP)) {
303+
/* try to report this */
297304
flags |= SOCK_ASYNC_CONN_FIN;
298305
}
299306
break;

0 commit comments

Comments
 (0)