2015-01-25 21:16:44 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* net/local/local_release.c
|
|
|
|
*
|
2024-09-11 14:39:39 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-01-25 21:16:44 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-01-25 21:16:44 +01:00
|
|
|
*
|
2021-02-19 12:45:37 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-01-25 21:16:44 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2021-09-16 07:40:02 +02:00
|
|
|
#include <nuttx/nuttx.h>
|
2022-09-25 17:08:38 +02:00
|
|
|
#include <nuttx/queue.h>
|
2015-01-25 21:16:44 +01:00
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
|
2015-01-30 19:43:37 +01:00
|
|
|
#include <arch/irq.h>
|
|
|
|
|
2015-01-25 21:16:44 +01:00
|
|
|
#include "local/local.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: local_release
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* If the local, Unix domain socket is in the connected state, then
|
|
|
|
* disconnect it. Release the local connection structure in any event
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* conn - A reference to local connection structure
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int local_release(FAR struct local_conn_s *conn)
|
|
|
|
{
|
|
|
|
/* There should be no references on this structure */
|
|
|
|
|
|
|
|
DEBUGASSERT(conn->lc_crefs == 0);
|
2016-12-03 23:28:19 +01:00
|
|
|
net_lock();
|
2015-01-25 21:16:44 +01:00
|
|
|
|
2015-01-31 14:58:51 +01:00
|
|
|
#ifdef CONFIG_NET_LOCAL_STREAM
|
2015-01-27 14:03:20 +01:00
|
|
|
/* We should not bet here with state LOCAL_STATE_ACCEPT. That is an
|
|
|
|
* internal state that should be atomic with respect to socket operations.
|
2015-01-25 21:16:44 +01:00
|
|
|
*/
|
|
|
|
|
2015-01-27 14:03:20 +01:00
|
|
|
DEBUGASSERT(conn->lc_state != LOCAL_STATE_ACCEPT);
|
2015-01-25 21:16:44 +01:00
|
|
|
|
|
|
|
/* Is the socket is listening socket (SOCK_STREAM server) */
|
|
|
|
|
2023-12-19 10:37:08 +01:00
|
|
|
if (conn->lc_state == LOCAL_STATE_LISTENING)
|
2015-01-25 21:16:44 +01:00
|
|
|
{
|
2023-12-19 10:37:08 +01:00
|
|
|
FAR struct local_conn_s *accept;
|
2021-09-16 07:40:02 +02:00
|
|
|
FAR dq_entry_t *waiter;
|
2024-06-07 05:51:15 +02:00
|
|
|
FAR dq_entry_t *tmp;
|
2015-01-25 21:16:44 +01:00
|
|
|
|
2015-01-27 23:39:30 +01:00
|
|
|
DEBUGASSERT(conn->lc_proto == SOCK_STREAM);
|
2015-01-25 21:16:44 +01:00
|
|
|
|
|
|
|
/* Are there still clients waiting for a connection to the server? */
|
|
|
|
|
2024-06-07 05:51:15 +02:00
|
|
|
dq_for_every_safe(&conn->u.server.lc_waiters, waiter, tmp)
|
2015-01-25 21:16:44 +01:00
|
|
|
{
|
2023-12-19 10:37:08 +01:00
|
|
|
accept = container_of(waiter, struct local_conn_s,
|
|
|
|
u.accept.lc_waiter);
|
|
|
|
local_subref(accept);
|
2015-01-25 21:16:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
conn->u.server.lc_pending = 0;
|
|
|
|
}
|
2015-01-31 14:58:51 +01:00
|
|
|
#endif /* CONFIG_NET_LOCAL_STREAM */
|
2015-01-25 21:16:44 +01:00
|
|
|
|
|
|
|
/* For the remaining states (LOCAL_STATE_UNBOUND and LOCAL_STATE_UNBOUND),
|
|
|
|
* we simply free the connection structure.
|
|
|
|
*/
|
|
|
|
|
2015-01-27 14:03:20 +01:00
|
|
|
/* Free the connection structure */
|
2015-01-25 21:16:44 +01:00
|
|
|
|
2015-01-27 14:03:20 +01:00
|
|
|
local_free(conn);
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2015-01-25 21:16:44 +01:00
|
|
|
return OK;
|
|
|
|
}
|