From 041d38740d64e295b18de68164ea2ef5d3fd52f8 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Thu, 11 May 2017 13:49:16 +0300 Subject: [PATCH] net: context, pkt: Changes for Sockets API Two changes are required so far: * There's unavoidable need to have a per-socket queue of packets (for data sockets) or pending connections (for listening sockets). These queues share the same space (as a C union). * There's a need to track "EOF" status of connection, synchronized with a queue of pending packets (i.e. EOF status should be processed only when all pending packets are processed). A natural place to store it per-packet then, and we had a "sent" bit which was used only for outgoing packets, recast it as "eof" for incoming socket packets. Signed-off-by: Paul Sokolovsky --- include/net/net_context.h | 8 ++++++++ include/net/net_pkt.h | 20 +++++++++++++++++--- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/include/net/net_context.h b/include/net/net_context.h index e0d1c7cdf6e..e7d20279012 100644 --- a/include/net/net_context.h +++ b/include/net/net_context.h @@ -237,6 +237,14 @@ struct net_context { /** TCP connection information */ struct net_tcp *tcp; #endif /* CONFIG_NET_TCP */ + +#if defined(CONFIG_NET_SOCKETS) + /** Per-socket packet or connection queues */ + union { + struct k_fifo recv_q; + struct k_fifo accept_q; + }; +#endif /* CONFIG_NET_SOCKETS */ }; static inline bool net_context_is_used(struct net_context *context) diff --git a/include/net/net_pkt.h b/include/net/net_pkt.h index 3d38349f06a..da4fa6b6a21 100644 --- a/include/net/net_pkt.h +++ b/include/net/net_pkt.h @@ -71,7 +71,9 @@ struct net_pkt { sys_snode_t sent_list; #endif - u8_t sent : 1; /* Is this sent or not + u8_t sent_or_eof: 1; /* For outgoing packet: is this sent or not + * For incoming packet of a socket: last + * packet before EOF * Used only if defined(CONFIG_NET_TCP) */ u8_t forwarding : 1; /* Are we forwarding this pkt @@ -188,13 +190,25 @@ static inline void net_pkt_set_next_hdr(struct net_pkt *pkt, u8_t *hdr) #if defined(CONFIG_NET_TCP) static inline u8_t net_pkt_sent(struct net_pkt *pkt) { - return pkt->sent; + return pkt->sent_or_eof; } static inline void net_pkt_set_sent(struct net_pkt *pkt, bool sent) { - pkt->sent = sent; + pkt->sent_or_eof = sent; } + +#if defined(CONFIG_NET_SOCKETS) +static inline u8_t net_pkt_eof(struct net_pkt *pkt) +{ + return pkt->sent_or_eof; +} + +static inline void net_pkt_set_eof(struct net_pkt *pkt, bool eof) +{ + pkt->sent_or_eof = eof; +} +#endif #endif #if defined(CONFIG_NET_ROUTE)