2019-07-02 02:25:32 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* net/inet/inet_txdrain.c
|
|
|
|
*
|
2024-09-11 20:39:39 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-19 19:45:37 +08: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
|
2019-07-02 02:25:32 +08:00
|
|
|
*
|
2021-02-19 19:45:37 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2019-07-02 02:25:32 +08:00
|
|
|
*
|
2021-02-19 19:45:37 +08: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.
|
2019-07-02 02:25:32 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
|
|
|
|
#include "udp/udp.h"
|
|
|
|
#include "tcp/tcp.h"
|
|
|
|
#include "inet/inet.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: inet_txdrain
|
|
|
|
*
|
|
|
|
* Description:
|
2019-07-02 04:07:12 +08:00
|
|
|
* Wait for any buffered Tx data to be sent from the socket.
|
2019-07-02 02:25:32 +08:00
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* psock - Pointer to the socket structure instance
|
2020-01-04 18:37:46 +08:00
|
|
|
* timeout - The relative time when the timeout will occur
|
2019-07-02 02:25:32 +08:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated error value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-01-04 18:37:46 +08:00
|
|
|
int inet_txdrain(FAR struct socket *psock, unsigned int timeout)
|
2019-07-02 02:25:32 +08:00
|
|
|
{
|
|
|
|
int ret = OK;
|
|
|
|
|
|
|
|
DEBUGASSERT(psock != NULL);
|
|
|
|
|
|
|
|
/* Draining depends on the socket family */
|
|
|
|
|
|
|
|
switch (psock->s_type)
|
|
|
|
{
|
2019-07-02 04:07:12 +08:00
|
|
|
#if defined(NET_TCP_HAVE_STACK)
|
2019-07-02 02:25:32 +08:00
|
|
|
case SOCK_STREAM:
|
|
|
|
{
|
2020-01-04 18:37:46 +08:00
|
|
|
ret = tcp_txdrain(psock, timeout);
|
2019-07-02 02:25:32 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2019-07-02 04:07:12 +08:00
|
|
|
#if defined(NET_UDP_HAVE_STACK)
|
2019-07-02 02:25:32 +08:00
|
|
|
case SOCK_DGRAM:
|
|
|
|
{
|
2020-01-04 18:37:46 +08:00
|
|
|
ret = udp_txdrain(psock, timeout);
|
2019-07-02 02:25:32 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Other protocols do no support write buffering */
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|