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 <paul.sokolovsky@linaro.org>
This commit is contained in:
Paul Sokolovsky 2017-05-11 13:49:16 +03:00 committed by Jukka Rissanen
parent 3432ff4fca
commit 041d38740d
2 changed files with 25 additions and 3 deletions

View File

@ -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)

View File

@ -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)