2018-09-09 17:21:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* net/udp/udp_notifier.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2018-09-09 23:01:44 +02:00
|
|
|
#include <assert.h>
|
2018-09-09 17:21:39 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
#include <nuttx/wqueue.h>
|
2018-09-09 17:21:39 +02:00
|
|
|
#include <nuttx/mm/iob.h>
|
|
|
|
|
|
|
|
#include "udp/udp.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_UDP_READAHEAD_NOTIFIER
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: udp_notifier_setup
|
|
|
|
*
|
|
|
|
* Description:
|
2018-09-09 23:01:44 +02:00
|
|
|
* Set up to perform a callback to the worker function when an UDP data
|
|
|
|
* is added to the read-ahead buffer. The worker function will execute
|
|
|
|
* on the high priority worker thread.
|
2018-09-09 19:57:25 +02:00
|
|
|
*
|
2018-09-09 17:21:39 +02:00
|
|
|
* Input Parameters:
|
2018-09-09 23:01:44 +02:00
|
|
|
* worker - The worker function to execute on the high priority work
|
|
|
|
* queue when data is available in the UDP readahead buffer.
|
2018-09-09 17:21:39 +02:00
|
|
|
* conn - The UDP connection where read-ahead data is needed.
|
2018-09-09 23:01:44 +02:00
|
|
|
* arg - A user-defined argument that will be available to the worker
|
|
|
|
* function when it runs.
|
2018-09-09 17:21:39 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* > 0 - The signal notification is in place. The returned value is a
|
|
|
|
* key that may be used later in a call to
|
|
|
|
* udp_notifier_teardown().
|
|
|
|
* == 0 - There is already buffered read-ahead data. No signal
|
|
|
|
* notification will be provided.
|
|
|
|
* < 0 - An unexpected error occurred and no signal will be sent. The
|
|
|
|
* returned value is a negated errno value that indicates the
|
|
|
|
* nature of the failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
int udp_notifier_setup(worker_t worker, FAR struct udp_conn_s *conn,
|
|
|
|
FAR void *arg)
|
2018-09-09 17:21:39 +02:00
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
struct work_notifier_s info;
|
|
|
|
|
|
|
|
DEBUGASSERT(worker != NULL);
|
|
|
|
|
2018-09-09 17:21:39 +02:00
|
|
|
/* If there is already buffered read-ahead data, then return zero without
|
|
|
|
* setting up the notification.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (conn->readahead.qh_head != NULL)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
/* Otherwise, this is just a simple wrapper around work_notifer_setup(). */
|
|
|
|
|
|
|
|
info.evtype = WORK_UDP_READAHEAD;
|
|
|
|
info.qualifier = conn;
|
|
|
|
info.arg = arg;
|
|
|
|
info.worker = worker;
|
2018-09-09 17:21:39 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
return work_notifier_setup(&info);
|
2018-09-09 17:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: udp_notifier_teardown
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Eliminate a UDP read-ahead notification previously setup by
|
|
|
|
* udp_notifier_setup(). This function should only be called if the
|
|
|
|
* notification should be aborted prior to the notification. The
|
|
|
|
* notification will automatically be torn down after the signal is sent.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
|
|
|
* key - The key value returned from a previous call to
|
|
|
|
* udp_notifier_setup().
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; a negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int udp_notifier_teardown(int key)
|
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
/* This is just a simple wrapper around work_notifier_teardown(). */
|
2018-09-09 17:21:39 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
return work_notifier_teardown(key);
|
2018-09-09 17:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: udp_notifier_signal
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Read-ahead data has been buffered. Signal all threads waiting for
|
|
|
|
* read-ahead data to become available.
|
|
|
|
*
|
2018-09-09 23:01:44 +02:00
|
|
|
* When read-ahead data becomes available, *all* of the workers waiting
|
|
|
|
* for read-ahead data will be executed. If there are multiple workers
|
|
|
|
* waiting for read-ahead data then only the first to execute will get the
|
|
|
|
* data. Others will need to call udp_notifier_setup() once again.
|
2018-09-09 19:57:25 +02:00
|
|
|
*
|
2018-09-09 17:21:39 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* conn - The UDP connection where read-ahead data was just buffered.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void udp_notifier_signal(FAR struct udp_conn_s *conn)
|
|
|
|
{
|
2018-09-09 23:01:44 +02:00
|
|
|
/* This is just a simple wrapper around work_notifier_signal(). */
|
2018-09-09 17:21:39 +02:00
|
|
|
|
2018-09-09 23:01:44 +02:00
|
|
|
return work_notifier_signal(WORK_UDP_READAHEAD, conn);
|
2018-09-09 17:21:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_UDP_READAHEAD_NOTIFIER */
|