Skip to content

Commit ad67946

Browse files
rlubosmbolivar-nordic
authored andcommitted
[nrf fromtree] 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]> (cherry picked from commit 8ba5990)
1 parent 78d4740 commit ad67946

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
@@ -1420,7 +1420,21 @@ static int zsock_poll_prepare_ctx(struct net_context *ctx,
14201420
}
14211421

14221422
if (pfd->events & ZSOCK_POLLOUT) {
1423-
return -EALREADY;
1423+
if (IS_ENABLED(CONFIG_NET_NATIVE_TCP) &&
1424+
net_context_get_type(ctx) == SOCK_STREAM) {
1425+
if (*pev == pev_end) {
1426+
return -ENOMEM;
1427+
}
1428+
1429+
(*pev)->obj = net_tcp_tx_sem_get(ctx);
1430+
(*pev)->type = K_POLL_TYPE_SEM_AVAILABLE;
1431+
(*pev)->mode = K_POLL_MODE_NOTIFY_ONLY;
1432+
(*pev)->state = K_POLL_STATE_NOT_READY;
1433+
(*pev)++;
1434+
} else {
1435+
return -EALREADY;
1436+
}
1437+
14241438
}
14251439

14261440
/* If socket is already in EOF, it can be reported
@@ -1439,17 +1453,24 @@ static int zsock_poll_update_ctx(struct net_context *ctx,
14391453
{
14401454
ARG_UNUSED(ctx);
14411455

1442-
/* For now, assume that socket is always writable */
1443-
if (pfd->events & ZSOCK_POLLOUT) {
1444-
pfd->revents |= ZSOCK_POLLOUT;
1445-
}
1446-
14471456
if (pfd->events & ZSOCK_POLLIN) {
14481457
if ((*pev)->state != K_POLL_STATE_NOT_READY || sock_is_eof(ctx)) {
14491458
pfd->revents |= ZSOCK_POLLIN;
14501459
}
14511460
(*pev)++;
14521461
}
1462+
if (pfd->events & ZSOCK_POLLOUT) {
1463+
if (IS_ENABLED(CONFIG_NET_NATIVE_TCP) &&
1464+
net_context_get_type(ctx) == SOCK_STREAM) {
1465+
if ((*pev)->state != K_POLL_STATE_NOT_READY &&
1466+
!sock_is_eof(ctx)) {
1467+
pfd->revents |= ZSOCK_POLLOUT;
1468+
}
1469+
(*pev)++;
1470+
} else {
1471+
pfd->revents |= ZSOCK_POLLOUT;
1472+
}
1473+
}
14531474

14541475
if (sock_is_eof(ctx)) {
14551476
pfd->revents |= ZSOCK_POLLHUP;

0 commit comments

Comments
 (0)