2015-01-25 21:16:44 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* net/local/local_release.c
|
|
|
|
*
|
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;
|
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? */
|
|
|
|
|
2021-09-16 07:40:02 +02:00
|
|
|
for (waiter = dq_peek(&conn->u.server.lc_waiters);
|
2024-02-28 06:14:19 +01:00
|
|
|
waiter != NULL;
|
2023-12-19 10:37:08 +01:00
|
|
|
waiter = dq_next(&accept->u.accept.lc_waiter))
|
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;
|
|
|
|
}
|