Skip to content

Commit 8ba5990

Browse files
rluboscarlescufi
authored andcommitted
net: sockets: Implement POLLOUT for stream sockets
Implement POLLOUT for stream sockets, based on newly introduced tx_sem functionality of the TCP stack. Signed-off-by: Robert Lubos <[email protected]>
1 parent 86105fb commit 8ba5990

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

subsys/net/lib/sockets/sockets.c

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,21 @@ static int zsock_poll_prepare_ctx(struct net_context *ctx,
14331433
}
14341434

14351435
if (pfd->events & ZSOCK_POLLOUT) {
1436-
return -EALREADY;
1436+
if (IS_ENABLED(CONFIG_NET_NATIVE_TCP) &&
1437+
net_context_get_type(ctx) == SOCK_STREAM) {
1438+
if (*pev == pev_end) {
1439+
return -ENOMEM;
1440+
}
1441+
1442+
(*pev)->obj = net_tcp_tx_sem_get(ctx);
1443+
(*pev)->type = K_POLL_TYPE_SEM_AVAILABLE;
1444+
(*pev)->mode = K_POLL_MODE_NOTIFY_ONLY;
1445+
(*pev)->state = K_POLL_STATE_NOT_READY;
1446+
(*pev)++;
1447+
} else {
1448+
return -EALREADY;
1449+
}
1450+
14371451
}
14381452

14391453
/* If socket is already in EOF or error, it can be reported
@@ -1452,17 +1466,24 @@ static int zsock_poll_update_ctx(struct net_context *ctx,
14521466
{
14531467
ARG_UNUSED(ctx);
14541468

1455-
/* For now, assume that socket is always writable */
1456-
if (pfd->events & ZSOCK_POLLOUT) {
1457-
pfd->revents |= ZSOCK_POLLOUT;
1458-
}
1459-
14601469
if (pfd->events & ZSOCK_POLLIN) {
14611470
if ((*pev)->state != K_POLL_STATE_NOT_READY || sock_is_eof(ctx)) {
14621471
pfd->revents |= ZSOCK_POLLIN;
14631472
}
14641473
(*pev)++;
14651474
}
1475+
if (pfd->events & ZSOCK_POLLOUT) {
1476+
if (IS_ENABLED(CONFIG_NET_NATIVE_TCP) &&
1477+
net_context_get_type(ctx) == SOCK_STREAM) {
1478+
if ((*pev)->state != K_POLL_STATE_NOT_READY &&
1479+
!sock_is_eof(ctx)) {
1480+
pfd->revents |= ZSOCK_POLLOUT;
1481+
}
1482+
(*pev)++;
1483+
} else {
1484+
pfd->revents |= ZSOCK_POLLOUT;
1485+
}
1486+
}
14661487

14671488
if (sock_is_error(ctx)) {
14681489
pfd->revents |= ZSOCK_POLLERR;

0 commit comments

Comments
 (0)