netif: Add in close

This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2023-03-06 15:05:13 +00:00
1 parent cd874dad44
commit 09222bb666
4 files changed
+54 -9

No files matched your search

+22
View File
@@ -27,6 +27,15 @@ coap_netif_available(coap_session_t *session) {
}
#if COAP_SERVER_SUPPORT
/*
* return 1 netif still in use.
* 0 netif no longer available.
*/
int
coap_netif_available_ep(coap_endpoint_t *endpoint) {
return endpoint->sock.flags != COAP_SOCKET_EMPTY;
}
int
coap_netif_dgrm_listen(coap_endpoint_t *endpoint,
const coap_address_t *listen_addr) {
@@ -194,3 +203,16 @@ coap_netif_strm_write(coap_session_t *session, const uint8_t *data,
return bytes_written;
}
#endif /* COAP_DISABLE_TCP */
void
coap_netif_close(coap_session_t *session) {
coap_socket_close(&session->sock);
}
#if COAP_SERVER_SUPPORT
void
coap_netif_close_ep(coap_endpoint_t *endpoint) {
coap_socket_close(&endpoint->sock);
}
#endif /* COAP_SERVER_SUPPORT */
+7 -7
View File
@@ -262,8 +262,8 @@ void coap_session_mfree(coap_session_t *session) {
else if (session->proto == COAP_PROTO_TLS)
coap_tls_free_session(session);
#endif /* !COAP_DISABLE_TCP */
if (session->sock.flags != COAP_SOCKET_EMPTY)
coap_socket_close(&session->sock);
if (coap_netif_available(session))
coap_netif_close(session);
if (session->psk_identity)
coap_delete_bin_const(session->psk_identity);
if (session->psk_key)
@@ -678,8 +678,8 @@ void coap_session_disconnected(coap_session_t *session, coap_nack_reason_t reaso
#if !COAP_DISABLE_TCP
if (COAP_PROTO_RELIABLE(session->proto)) {
if (session->sock.flags != COAP_SOCKET_EMPTY) {
coap_socket_close(&session->sock);
if (coap_netif_available(session)) {
coap_netif_close(session);
coap_handle_event(session->context,
state == COAP_SESSION_STATE_CONNECTING ?
COAP_EVENT_TCP_FAILED : COAP_EVENT_TCP_CLOSED, session);
@@ -1579,7 +1579,7 @@ coap_free_endpoint(coap_endpoint_t *ep) {
coap_session_free(session);
}
}
if (ep->sock.flags != COAP_SOCKET_EMPTY) {
if (coap_netif_available_ep(ep)) {
/*
* ep->sock.endpoint is set in coap_new_endpoint().
* ep->sock.session is never set.
@@ -1587,13 +1587,13 @@ coap_free_endpoint(coap_endpoint_t *ep) {
* session->sock.session is set for both clients and servers (when a
* new session is accepted), but does not affect the endpoint.
*
* So, it is safe to call coap_socket_close() after all the sessions
* So, it is safe to call coap_netif_close_ep() after all the sessions
* have been freed above as we are only working with the endpoint sock.
*/
#ifdef COAP_EPOLL_SUPPORT
assert(ep->sock.session == NULL);
#endif /* COAP_EPOLL_SUPPORT */
coap_socket_close(&ep->sock);
coap_netif_close_ep(ep);
}
if (ep->context && ep->context->endpoint) {
+2 -2
View File
@@ -1089,7 +1089,7 @@ coap_send(coap_session_t *session, coap_pdu_t *pdu) {
#if COAP_CLIENT_SUPPORT
if (session->type == COAP_SESSION_TYPE_CLIENT &&
session->sock.flags == COAP_SOCKET_EMPTY) {
!coap_netif_available(session)) {
coap_log_debug("coap_send: Socket closed\n");
coap_delete_pdu(pdu);
return COAP_INVALID_MID;
@@ -2049,7 +2049,7 @@ coap_io_do_epoll(coap_context_t *ctx, struct epoll_event *events, size_t nevents
(events[j].events & (EPOLLOUT|EPOLLERR|EPOLLHUP|EPOLLRDHUP))) {
sock->flags |= COAP_SOCKET_CAN_CONNECT;
coap_connect_session(session->context, session, now);
if (sock->flags != COAP_SOCKET_EMPTY &&
if (coap_netif_available(session) &&
!(sock->flags & COAP_SOCKET_WANT_WRITE)) {
coap_epoll_ctl_mod(sock, EPOLLIN, __func__);
}