casaroli commented on code in PR #22358:
URL: https://github.com/apache/nuttx/pull/22358#discussion_r4709015554
##########
net/tcp/tcp_conn.c:
##########
@@ -564,6 +564,107 @@ static bool tcp_reclaimable(FAR struct tcp_conn_s *conn)
conn->tcpstateflags == TCP_LAST_ACK);
}
+/****************************************************************************
+ * Name: tcp_is_syn_backlog
+ *
+ * Description:
+ * Return true if the connection is in TCP_SYN_RCVD on the address and
+ * port of the listener.
+ *
+ ****************************************************************************/
+
+static bool tcp_is_syn_backlog(FAR struct tcp_conn_s *listener,
+ FAR struct tcp_conn_s *conn)
+{
+ if (conn->tcpstateflags != TCP_SYN_RCVD)
+ {
+ return false;
+ }
+
+#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
+ return tcp_conn_cmp(listener->domain,
+ (FAR const union ip_addr_u *)&listener->u,
+ listener->lport, conn);
+#else
+ return tcp_conn_cmp((FAR const union ip_addr_u *)&listener->u,
+ listener->lport, conn);
+#endif
+}
+
+/****************************************************************************
+ * Name: tcp_syn_room
+ *
+ * Description:
+ * Return true if the listener can take one more connection in
+ * TCP_SYN_RCVD. Its connections in TCP_SYN_RCVD and the ones that wait
+ * for accept() together take at most the backlog of listen(). If there
+ * is no room, free the oldest connection in TCP_SYN_RCVD of the listener
+ * on this device and take its place (RFC 4987, section 3.4).
+ *
+ * Input Parameters:
+ * dev - The device whose lock the caller holds.
+ * listener - The listening connection.
+ *
+ * Returned Value:
+ * true if a new connection in TCP_SYN_RCVD can be made.
+ *
+ ****************************************************************************/
+
+static bool tcp_syn_room(FAR struct net_driver_s *dev,
+ FAR struct tcp_conn_s *listener)
+{
+ FAR struct tcp_conn_s *oldest = NULL;
+ FAR struct tcp_conn_s *conn;
+ size_t nsynrcvd = 0;
+ size_t nfree = SIZE_MAX;
+ bool room = true;
+
+ tcp_conn_list_lock();
+#ifdef CONFIG_NET_TCPBACKLOG
+ nfree = 0;
+ if (listener->backlog != NULL)
+ {
+ nfree = sq_count(&listener->backlog->bl_free);
+ }
+#endif
+
+ /* The list is in the order of creation: the first match is the oldest */
+
+ for (conn = (FAR struct tcp_conn_s *)g_active_tcp_connections.head;
+ conn != NULL;
+ conn = (FAR struct tcp_conn_s *)conn->sconn.s_node.flink)
+ {
+ if (tcp_is_syn_backlog(listener, conn))
+ {
+ if (oldest == NULL && conn->dev == dev)
Review Comment:
Done.
##########
net/tcp/tcp_conn.c:
##########
@@ -564,6 +564,107 @@ static bool tcp_reclaimable(FAR struct tcp_conn_s *conn)
conn->tcpstateflags == TCP_LAST_ACK);
}
+/****************************************************************************
+ * Name: tcp_is_syn_backlog
+ *
+ * Description:
+ * Return true if the connection is in TCP_SYN_RCVD on the address and
+ * port of the listener.
+ *
+ ****************************************************************************/
+
+static bool tcp_is_syn_backlog(FAR struct tcp_conn_s *listener,
+ FAR struct tcp_conn_s *conn)
+{
+ if (conn->tcpstateflags != TCP_SYN_RCVD)
+ {
+ return false;
+ }
+
+#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NET_IPv6)
+ return tcp_conn_cmp(listener->domain,
+ (FAR const union ip_addr_u *)&listener->u,
+ listener->lport, conn);
+#else
+ return tcp_conn_cmp((FAR const union ip_addr_u *)&listener->u,
+ listener->lport, conn);
+#endif
+}
+
+/****************************************************************************
+ * Name: tcp_syn_room
+ *
+ * Description:
+ * Return true if the listener can take one more connection in
+ * TCP_SYN_RCVD. Its connections in TCP_SYN_RCVD and the ones that wait
+ * for accept() together take at most the backlog of listen(). If there
+ * is no room, free the oldest connection in TCP_SYN_RCVD of the listener
+ * on this device and take its place (RFC 4987, section 3.4).
+ *
+ * Input Parameters:
+ * dev - The device whose lock the caller holds.
+ * listener - The listening connection.
+ *
+ * Returned Value:
+ * true if a new connection in TCP_SYN_RCVD can be made.
+ *
+ ****************************************************************************/
+
+static bool tcp_syn_room(FAR struct net_driver_s *dev,
+ FAR struct tcp_conn_s *listener)
+{
+ FAR struct tcp_conn_s *oldest = NULL;
+ FAR struct tcp_conn_s *conn;
+ size_t nsynrcvd = 0;
+ size_t nfree = SIZE_MAX;
+ bool room = true;
+
+ tcp_conn_list_lock();
+#ifdef CONFIG_NET_TCPBACKLOG
+ nfree = 0;
+ if (listener->backlog != NULL)
+ {
+ nfree = sq_count(&listener->backlog->bl_free);
Review Comment:
Done.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]