From 701963fe28be28019912133c36a78e5a03e36501 Mon Sep 17 00:00:00 2001 From: Thomas Schoebel-Theuer Date: Tue, 16 Aug 2022 06:38:11 +0200 Subject: [PATCH] net: factor out SS_CONNECTED state checking and add SS_CONNECTING --- kernel/mars_net.c | 3 ++- kernel/mars_net.h | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/kernel/mars_net.c b/kernel/mars_net.c index 368aacda..84700abe 100644 --- a/kernel/mars_net.c +++ b/kernel/mars_net.c @@ -431,7 +431,8 @@ bool mars_socket_is_alive(struct mars_socket *msock) ok = mars_get_socket(msock); if (likely(ok)) { struct socket *sock = msock->s_socket; - if (sock->state == SS_CONNECTED) { + + if (!_socket_not_connected(sock)) { msock->s_connected = true; } else if (msock->s_connected) { MARS_DBG("#%d remote side hangup %p sock = %p\n", msock->s_debug_nr, msock, msock->s_socket); diff --git a/kernel/mars_net.h b/kernel/mars_net.h index 3042406c..48bcba2f 100644 --- a/kernel/mars_net.h +++ b/kernel/mars_net.h @@ -163,6 +163,28 @@ extern long mars_socket_send_space_available(struct mars_socket *msock); extern int mars_send_raw(struct mars_socket *msock, const void *buf, int len, bool cork); extern int mars_recv_raw(struct mars_socket *msock, void *buf, int minlen, int maxlen); +extern inline bool _socket_is_connecting(struct socket *sock) +{ + return (sock->state == SS_CONNECTING); +} + +extern inline bool _socket_not_connected(struct socket *sock) +{ + return (sock->state != SS_CONNECTED); +} + +extern inline bool mars_socket_is_connecting(struct mars_socket *msock) +{ + return msock->s_socket && + _socket_is_connecting(msock->s_socket); +} + +extern inline bool mars_socket_not_connected(struct mars_socket *msock) +{ + return !msock->s_socket || + _socket_not_connected(msock->s_socket); +} + /* Mid-level generic field data exchange */ extern int mars_send_struct(struct mars_socket *msock, const void *data, const struct meta *meta, bool cork);