2008-11-28 15:42:52 +01:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libnx/nxmu/nx_disconnect.c
|
2008-11-28 15:42:52 +01:00
|
|
|
*
|
2021-02-23 19:55:00 +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
|
2008-11-28 15:42:52 +01:00
|
|
|
*
|
2021-02-23 19:55:00 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-11-28 15:42:52 +01:00
|
|
|
*
|
2021-02-23 19:55:00 +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.
|
2008-11-28 15:42:52 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2017-11-01 01:46:49 +01:00
|
|
|
#include <stdio.h>
|
2008-11-28 15:42:52 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2021-02-15 06:11:27 +01:00
|
|
|
#include <nuttx/mqueue.h>
|
2011-07-24 22:49:01 +02:00
|
|
|
#include <nuttx/nx/nx.h>
|
2013-12-27 20:18:20 +01:00
|
|
|
#include <nuttx/nx/nxmu.h>
|
2008-11-28 15:42:52 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nx_disconnect
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Disconnect a client from the NX server and/or free resources reserved
|
|
|
|
* by nx_connect/nx_connectinstance.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* handle - the handle returned by nx_connect
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2008-11-28 15:42:52 +01:00
|
|
|
* OK on success; ERROR on failure with the errno set appropriately.
|
|
|
|
* NOTE that handle will no long be valid upon return.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void nx_disconnect(NXHANDLE handle)
|
|
|
|
{
|
2019-03-13 16:16:30 +01:00
|
|
|
FAR struct nxmu_conn_s *conn = (FAR struct nxmu_conn_s *)handle;
|
2012-05-17 21:32:48 +02:00
|
|
|
struct nxsvrmsg_s outmsg;
|
2017-11-01 01:46:49 +01:00
|
|
|
char climqname[NX_CLIENT_MXNAMELEN];
|
2012-05-19 01:08:34 +02:00
|
|
|
int ret;
|
2008-11-28 15:42:52 +01:00
|
|
|
|
|
|
|
/* Inform the server that this client no longer exists */
|
|
|
|
|
2012-05-17 21:32:48 +02:00
|
|
|
outmsg.msgid = NX_SVRMSG_DISCONNECT;
|
|
|
|
outmsg.conn = conn;
|
2008-11-28 15:42:52 +01:00
|
|
|
|
|
|
|
/* We will finish the teardown upon receipt of the DISCONNECTED message */
|
2012-05-17 21:32:48 +02:00
|
|
|
|
2012-05-19 01:08:34 +02:00
|
|
|
ret = nxmu_sendserver(conn, &outmsg, sizeof(struct nxsvrmsg_s));
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
gerr("ERROR: nxmu_sendserver() returned %d\n", ret);
|
2012-05-19 01:08:34 +02:00
|
|
|
}
|
2017-11-01 01:46:49 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(climqname, sizeof(climqname),
|
|
|
|
NX_CLIENT_MQNAMEFMT, conn->cid);
|
2021-02-15 06:11:27 +01:00
|
|
|
_MQ_UNLINK(climqname);
|
2017-11-01 01:46:49 +01:00
|
|
|
}
|
2008-11-28 15:42:52 +01:00
|
|
|
}
|