udp.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /****************************************************************************
  2. * net/udp/udp.h
  3. *
  4. * Copyright (C) 2014-2015, 2018 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __NET_UDP_UDP_H
  36. #define __NET_UDP_UDP_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <nuttx/config.h>
  41. #include <sys/types.h>
  42. #include <sys/socket.h>
  43. #include <queue.h>
  44. #include <nuttx/clock.h>
  45. #include <nuttx/net/ip.h>
  46. #ifdef CONFIG_NET_UDP_READAHEAD
  47. # include <nuttx/mm/iob.h>
  48. #endif
  49. #ifdef CONFIG_UDP_READAHEAD_NOTIFIER
  50. # include <nuttx/wqueue.h>
  51. #endif
  52. #if defined(CONFIG_NET_UDP) && !defined(CONFIG_NET_UDP_NO_STACK)
  53. /****************************************************************************
  54. * Pre-processor Definitions
  55. ****************************************************************************/
  56. #define NET_UDP_HAVE_STACK 1
  57. /* Conditions for support UDP poll/select operations */
  58. #if !defined(CONFIG_DISABLE_POLL) && defined(CONFIG_NET_UDP_READAHEAD)
  59. # define HAVE_UDP_POLL
  60. #endif
  61. #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
  62. /* UDP write buffer dump macros */
  63. # ifdef CONFIG_DEBUG_FEATURES
  64. # define UDP_WBDUMP(msg,wrb,len,offset) \
  65. udp_wrbuffer_dump(msg,wrb,len,offset)
  66. # else
  67. # define UDP_WBDUMP(msg,wrb,len,offset)
  68. # endif
  69. #endif
  70. /* Allocate a new UDP data callback */
  71. #define udp_callback_alloc(dev,conn) \
  72. devif_callback_alloc((dev), &(conn)->list)
  73. #define udp_callback_free(dev,conn,cb) \
  74. devif_conn_callback_free((dev), (cb), &(conn)->list)
  75. /* Definitions for the UDP connection struct flag field */
  76. #define _UDP_FLAG_CONNECTMODE (1 << 0) /* Bit 0: UDP connection-mode */
  77. #define _UDP_ISCONNECTMODE(f) (((f) & _UDP_FLAG_CONNECTMODE) != 0)
  78. /****************************************************************************
  79. * Public Type Definitions
  80. ****************************************************************************/
  81. /* Representation of a UDP connection */
  82. struct devif_callback_s; /* Forward reference */
  83. struct udp_hdr_s; /* Forward reference */
  84. struct udp_conn_s
  85. {
  86. dq_entry_t node; /* Supports a doubly linked list */
  87. union ip_binding_u u; /* IP address binding */
  88. uint16_t lport; /* Bound local port number (network byte order) */
  89. uint16_t rport; /* Remote port number (network byte order) */
  90. uint8_t flags; /* See _UDP_FLAG_* definitions */
  91. uint8_t domain; /* IP domain: PF_INET or PF_INET6 */
  92. uint8_t ttl; /* Default time-to-live */
  93. uint8_t crefs; /* Reference counts on this instance */
  94. #ifdef CONFIG_NET_UDP_BINDTODEVICE
  95. uint8_t boundto; /* Index of the interface we are bound to.
  96. * Unbound: 0, Bound: 1-MAX_IFINDEX */
  97. #endif
  98. #ifdef CONFIG_NET_UDP_READAHEAD
  99. /* Read-ahead buffering.
  100. *
  101. * readahead - A singly linked list of type struct iob_qentry_s
  102. * where the UDP/IP read-ahead data is retained.
  103. */
  104. struct iob_queue_s readahead; /* Read-ahead buffering */
  105. #endif
  106. #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
  107. /* Write buffering
  108. *
  109. * write_q - The queue of unsent I/O buffers. The head of this
  110. * list may be partially sent. FIFO ordering.
  111. */
  112. sq_queue_t write_q; /* Write buffering for UDP packets */
  113. FAR struct net_driver_s *dev; /* Last device */
  114. #endif
  115. /* Defines the list of UDP callbacks */
  116. FAR struct devif_callback_s *list;
  117. };
  118. /* This structure supports UDP write buffering. It is simply a container
  119. * for a IOB list and associated destination address.
  120. */
  121. #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
  122. struct udp_wrbuffer_s
  123. {
  124. sq_entry_t wb_node; /* Supports a singly linked list */
  125. struct sockaddr_storage wb_dest; /* Destination address */
  126. #ifdef CONFIG_NET_SOCKOPTS
  127. clock_t wb_start; /* Start time for timeout calculation */
  128. #endif
  129. struct iob_s *wb_iob; /* Head of the I/O buffer chain */
  130. };
  131. #endif
  132. /****************************************************************************
  133. * Public Data
  134. ****************************************************************************/
  135. #ifdef __cplusplus
  136. # define EXTERN extern "C"
  137. extern "C"
  138. {
  139. #else
  140. # define EXTERN extern
  141. #endif
  142. /****************************************************************************
  143. * Public Function Prototypes
  144. ****************************************************************************/
  145. struct sockaddr; /* Forward reference */
  146. struct socket; /* Forward reference */
  147. struct net_driver_s; /* Forward reference */
  148. struct pollfd; /* Forward reference */
  149. /****************************************************************************
  150. * Name: udp_initialize
  151. *
  152. * Description:
  153. * Initialize the UDP connection structures. Called once and only from
  154. * the UIP layer.
  155. *
  156. ****************************************************************************/
  157. void udp_initialize(void);
  158. /****************************************************************************
  159. * Name: udp_alloc
  160. *
  161. * Description:
  162. * Allocate a new, uninitialized UDP connection structure. This is
  163. * normally something done by the implementation of the socket() API
  164. *
  165. ****************************************************************************/
  166. FAR struct udp_conn_s *udp_alloc(uint8_t domain);
  167. /****************************************************************************
  168. * Name: udp_free
  169. *
  170. * Description:
  171. * Free a UDP connection structure that is no longer in use. This should be
  172. * done by the implementation of close().
  173. *
  174. ****************************************************************************/
  175. void udp_free(FAR struct udp_conn_s *conn);
  176. /****************************************************************************
  177. * Name: udp_active
  178. *
  179. * Description:
  180. * Find a connection structure that is the appropriate
  181. * connection to be used within the provided UDP/IP header
  182. *
  183. * Assumptions:
  184. * Called from network stack logic with the network stack locked
  185. *
  186. ****************************************************************************/
  187. FAR struct udp_conn_s *udp_active(FAR struct net_driver_s *dev,
  188. FAR struct udp_hdr_s *udp);
  189. /****************************************************************************
  190. * Name: udp_nextconn
  191. *
  192. * Description:
  193. * Traverse the list of allocated UDP connections
  194. *
  195. * Assumptions:
  196. * Called from network stack logic with the network stack locked
  197. *
  198. ****************************************************************************/
  199. FAR struct udp_conn_s *udp_nextconn(FAR struct udp_conn_s *conn);
  200. /****************************************************************************
  201. * Name: udp_bind
  202. *
  203. * Description:
  204. * This function implements the low-level parts of the standard UDP bind()
  205. * operation.
  206. *
  207. * Assumptions:
  208. * This function is called from normal user level code.
  209. *
  210. ****************************************************************************/
  211. int udp_bind(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr);
  212. /****************************************************************************
  213. * Name: udp_connect
  214. *
  215. * Description:
  216. * This function simply assigns a remote address to UDP "connection"
  217. * structure. This function is called as part of the implementation of:
  218. *
  219. * - connect(). If connect() is called for a SOCK_DGRAM socket, then
  220. * this logic performs the moral equivalent of connect() operation
  221. * for the UDP socket.
  222. * - recvfrom() and sendto(). This function is called to set the
  223. * remote address of the peer.
  224. *
  225. * The function will automatically allocate an unused local port for the
  226. * new connection if the socket is not yet bound to a local address.
  227. * However, another port can be chosen by using the udp_bind() call,
  228. * after the udp_connect() function has been called.
  229. *
  230. * Input Parameters:
  231. * conn - A reference to UDP connection structure. A value of NULL will
  232. * disconnect from any previously connected address.
  233. * addr - The address of the remote host.
  234. *
  235. * Assumptions:
  236. * This function is called (indirectly) from user code. Interrupts may
  237. * be enabled.
  238. *
  239. ****************************************************************************/
  240. int udp_connect(FAR struct udp_conn_s *conn, FAR const struct sockaddr *addr);
  241. /****************************************************************************
  242. * Name: udp_ipv4_select
  243. *
  244. * Description:
  245. * Configure to send or receive an UDP IPv4 packet
  246. *
  247. ****************************************************************************/
  248. #ifdef CONFIG_NET_IPv4
  249. void udp_ipv4_select(FAR struct net_driver_s *dev);
  250. #endif
  251. /****************************************************************************
  252. * Name: udp_ipv6_select
  253. *
  254. * Description:
  255. * Configure to send or receive an UDP IPv6 packet
  256. *
  257. ****************************************************************************/
  258. #ifdef CONFIG_NET_IPv6
  259. void udp_ipv6_select(FAR struct net_driver_s *dev);
  260. #endif
  261. /****************************************************************************
  262. * Name: udp_poll
  263. *
  264. * Description:
  265. * Poll a UDP "connection" structure for availability of TX data
  266. *
  267. * Input Parameters:
  268. * dev - The device driver structure to use in the send operation
  269. * conn - The UDP "connection" to poll for TX data
  270. *
  271. * Returned Value:
  272. * None
  273. *
  274. * Assumptions:
  275. * Called from network stack logic with the network stack locked
  276. *
  277. ****************************************************************************/
  278. void udp_poll(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn);
  279. /****************************************************************************
  280. * Name: psock_udp_cansend
  281. *
  282. * Description:
  283. * psock_udp_cansend() returns a value indicating if a write to the socket
  284. * would block. It is still possible that the write may block if another
  285. * write occurs first.
  286. *
  287. * Input Parameters:
  288. * psock An instance of the internal socket structure.
  289. *
  290. * Returned Value:
  291. * -ENOSYS (Function not implemented, always have to wait to send).
  292. *
  293. * Assumptions:
  294. * None
  295. *
  296. ****************************************************************************/
  297. int psock_udp_cansend(FAR struct socket *psock);
  298. ;
  299. /****************************************************************************
  300. * Name: udp_send
  301. *
  302. * Description:
  303. * Set-up to send a UDP packet
  304. *
  305. * Input Parameters:
  306. * dev - The device driver structure to use in the send operation
  307. * conn - The UDP "connection" structure holding port information
  308. *
  309. * Returned Value:
  310. * None
  311. *
  312. * Assumptions:
  313. * Called from network stack logic with the network stack locked
  314. *
  315. ****************************************************************************/
  316. void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn);
  317. /****************************************************************************
  318. * Name: udp_setsockopt
  319. *
  320. * Description:
  321. * udp_setsockopt() sets the UDP-protocol option specified by the
  322. * 'option' argument to the value pointed to by the 'value' argument for
  323. * the socket specified by the 'psock' argument.
  324. *
  325. * See <netinet/udp.h> for the a complete list of values of UDP protocol
  326. * options.
  327. *
  328. * Input Parameters:
  329. * psock Socket structure of socket to operate on
  330. * option identifies the option to set
  331. * value Points to the argument value
  332. * value_len The length of the argument value
  333. *
  334. * Returned Value:
  335. * Returns zero (OK) on success. On failure, it returns a negated errno
  336. * value to indicate the nature of the error. See psock_setcockopt() for
  337. * the list of possible error values.
  338. *
  339. ****************************************************************************/
  340. #ifdef CONFIG_NET_UDPPROTO_OPTIONS
  341. int udp_setsockopt(FAR struct socket *psock, int option,
  342. FAR const void *value, socklen_t value_len);
  343. #endif
  344. /****************************************************************************
  345. * Name: udp_wrbuffer_initialize
  346. *
  347. * Description:
  348. * Initialize the list of free write buffers
  349. *
  350. * Assumptions:
  351. * Called once early initialization.
  352. *
  353. ****************************************************************************/
  354. #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
  355. void udp_wrbuffer_initialize(void);
  356. #endif /* CONFIG_NET_UDP_WRITE_BUFFERS */
  357. /****************************************************************************
  358. * Name: udp_wrbuffer_alloc
  359. *
  360. * Description:
  361. * Allocate a UDP write buffer by taking a pre-allocated buffer from
  362. * the free list. This function is called from UDP logic when a buffer
  363. * of UDP data is about to sent
  364. *
  365. * Input Parameters:
  366. * None
  367. *
  368. * Assumptions:
  369. * Called from user logic with the network locked.
  370. *
  371. ****************************************************************************/
  372. #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
  373. struct udp_wrbuffer_s;
  374. FAR struct udp_wrbuffer_s *udp_wrbuffer_alloc(void);
  375. #endif /* CONFIG_NET_UDP_WRITE_BUFFERS */
  376. /****************************************************************************
  377. * Name: udp_wrbuffer_release
  378. *
  379. * Description:
  380. * Release a UDP write buffer by returning the buffer to the free list.
  381. * This function is called from user logic after it is consumed the
  382. * buffered data.
  383. *
  384. * Assumptions:
  385. * Called from network stack logic with the network stack locked
  386. *
  387. ****************************************************************************/
  388. #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
  389. void udp_wrbuffer_release(FAR struct udp_wrbuffer_s *wrb);
  390. #endif /* CONFIG_NET_UDP_WRITE_BUFFERS */
  391. /****************************************************************************
  392. * Name: udp_wrbuffer_test
  393. *
  394. * Description:
  395. * Check if there is room in the write buffer. Does not reserve any space.
  396. *
  397. * Assumptions:
  398. * None.
  399. *
  400. ****************************************************************************/
  401. #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
  402. int udp_wrbuffer_test(void);
  403. #endif /* CONFIG_NET_UDP_WRITE_BUFFERS */
  404. /****************************************************************************
  405. * Name: udp_wrbuffer_dump
  406. *
  407. * Description:
  408. * Dump the contents of a write buffer.
  409. *
  410. ****************************************************************************/
  411. #ifdef CONFIG_NET_UDP_WRITE_BUFFERS
  412. #ifdef CONFIG_DEBUG_FEATURES
  413. void udp_wrbuffer_dump(FAR const char *msg, FAR struct udp_wrbuffer_s *wrb,
  414. unsigned int len, unsigned int offset);
  415. #else
  416. # define udp_wrbuffer_dump(msg,wrb)
  417. #endif
  418. #endif /* CONFIG_NET_UDP_WRITE_BUFFERS */
  419. /****************************************************************************
  420. * Name: udp_ipv4_input
  421. *
  422. * Description:
  423. * Handle incoming UDP input in an IPv4 packet
  424. *
  425. * Input Parameters:
  426. * dev - The device driver structure containing the received UDP packet
  427. *
  428. * Returned Value:
  429. * OK The packet has been processed and can be deleted
  430. * ERROR Hold the packet and try again later. There is a listening socket
  431. * but no receive in place to catch the packet yet.
  432. *
  433. * Assumptions:
  434. * Called from network stack logic with the network stack locked
  435. *
  436. ****************************************************************************/
  437. #ifdef CONFIG_NET_IPv4
  438. int udp_ipv4_input(FAR struct net_driver_s *dev);
  439. #endif
  440. /****************************************************************************
  441. * Name: udp_ipv6_input
  442. *
  443. * Description:
  444. * Handle incoming UDP input in an IPv6 packet
  445. *
  446. * Input Parameters:
  447. * dev - The device driver structure containing the received UDP packet
  448. * iplen - The size of the IPv6 header. This may be larger than
  449. * IPv6_HDRLEN the IPv6 header if IPv6 extension headers are
  450. * present.
  451. *
  452. * Returned Value:
  453. * OK The packet has been processed and can be deleted
  454. * ERROR Hold the packet and try again later. There is a listening socket
  455. * but no receive in place to catch the packet yet.
  456. *
  457. * Assumptions:
  458. * Called from network stack logic with the network stack locked
  459. *
  460. ****************************************************************************/
  461. #ifdef CONFIG_NET_IPv6
  462. int udp_ipv6_input(FAR struct net_driver_s *dev, unsigned int iplen);
  463. #endif
  464. /****************************************************************************
  465. * Name: udp_find_laddr_device
  466. *
  467. * Description:
  468. * Select the network driver to use with the UDP transaction using the
  469. * locally bound IP address.
  470. *
  471. * Input Parameters:
  472. * conn - UDP connection structure (not currently used).
  473. *
  474. * Returned Value:
  475. * A pointer to the network driver to use. NULL is returned if driver is
  476. * not bound to any local device.
  477. *
  478. ****************************************************************************/
  479. FAR struct net_driver_s *udp_find_laddr_device(FAR struct udp_conn_s *conn);
  480. /****************************************************************************
  481. * Name: udp_find_raddr_device
  482. *
  483. * Description:
  484. * Select the network driver to use with the UDP transaction using the
  485. * remote IP address.
  486. *
  487. * Input Parameters:
  488. * conn - UDP connection structure (not currently used).
  489. *
  490. * Returned Value:
  491. * A pointer to the network driver to use.
  492. *
  493. ****************************************************************************/
  494. FAR struct net_driver_s *udp_find_raddr_device(FAR struct udp_conn_s *conn);
  495. /****************************************************************************
  496. * Name: udp_callback
  497. *
  498. * Description:
  499. * Inform the application holding the UDP socket of a change in state.
  500. *
  501. * Returned Value:
  502. * OK if packet has been processed, otherwise ERROR.
  503. *
  504. * Assumptions:
  505. * Called from network stack logic with the network stack locked
  506. *
  507. ****************************************************************************/
  508. uint16_t udp_callback(FAR struct net_driver_s *dev,
  509. FAR struct udp_conn_s *conn, uint16_t flags);
  510. /****************************************************************************
  511. * Name: psock_udp_send
  512. *
  513. * Description:
  514. * Implements send() for connected UDP sockets
  515. *
  516. ****************************************************************************/
  517. ssize_t psock_udp_send(FAR struct socket *psock, FAR const void *buf,
  518. size_t len);
  519. /****************************************************************************
  520. * Name: psock_udp_sendto
  521. *
  522. * Description:
  523. * This function implements the UDP-specific logic of the standard
  524. * sendto() socket operation.
  525. *
  526. * Input Parameters:
  527. * psock A pointer to a NuttX-specific, internal socket structure
  528. * buf Data to send
  529. * len Length of data to send
  530. * flags Send flags
  531. * to Address of recipient
  532. * tolen The length of the address structure
  533. *
  534. * NOTE: All input parameters were verified by sendto() before this
  535. * function was called.
  536. *
  537. * Returned Value:
  538. * On success, returns the number of characters sent. On error,
  539. * a negated errno value is returned. See the description in
  540. * net/socket/sendto.c for the list of appropriate return value.
  541. *
  542. ****************************************************************************/
  543. ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
  544. size_t len, int flags, FAR const struct sockaddr *to,
  545. socklen_t tolen);
  546. /****************************************************************************
  547. * Name: udp_pollsetup
  548. *
  549. * Description:
  550. * Setup to monitor events on one UDP/IP socket
  551. *
  552. * Input Parameters:
  553. * psock - The UDP/IP socket of interest
  554. * fds - The structure describing the events to be monitored, OR NULL if
  555. * this is a request to stop monitoring events.
  556. *
  557. * Returned Value:
  558. * 0: Success; Negated errno on failure
  559. *
  560. ****************************************************************************/
  561. #ifdef HAVE_UDP_POLL
  562. int udp_pollsetup(FAR struct socket *psock, FAR struct pollfd *fds);
  563. #endif
  564. /****************************************************************************
  565. * Name: udp_pollteardown
  566. *
  567. * Description:
  568. * Teardown monitoring of events on an UDP/IP socket
  569. *
  570. * Input Parameters:
  571. * psock - The UDP/IP socket of interest
  572. * fds - The structure describing the events to be monitored, OR NULL if
  573. * this is a request to stop monitoring events.
  574. *
  575. * Returned Value:
  576. * 0: Success; Negated errno on failure
  577. *
  578. ****************************************************************************/
  579. #ifdef HAVE_UDP_POLL
  580. int udp_pollteardown(FAR struct socket *psock, FAR struct pollfd *fds);
  581. #endif
  582. /****************************************************************************
  583. * Name: udp_notifier_setup
  584. *
  585. * Description:
  586. * Set up to perform a callback to the worker function when an UDP data
  587. * is added to the read-ahead buffer. The worker function will execute
  588. * on the low priority worker thread.
  589. *
  590. * Input Parameters:
  591. * worker - The worker function to execute on the low priority work
  592. * queue when data is available in the UDP read-ahead buffer.
  593. * conn - The UDP connection where read-ahead data is needed.
  594. * arg - A user-defined argument that will be available to the worker
  595. * function when it runs.
  596. *
  597. * Returned Value:
  598. * > 0 - The notification is in place. The returned value is a key that
  599. * may be used later in a call to udp_notifier_teardown().
  600. * == 0 - There is already buffered read-ahead data. No notification
  601. * will be provided.
  602. * < 0 - An unexpected error occurred and no notification will occur.
  603. * The returned value is a negated errno value that indicates the
  604. * nature of the failure.
  605. *
  606. ****************************************************************************/
  607. #ifdef CONFIG_UDP_READAHEAD_NOTIFIER
  608. int udp_notifier_setup(worker_t worker, FAR struct udp_conn_s *conn,
  609. FAR void *arg);
  610. #endif
  611. /****************************************************************************
  612. * Name: udp_notifier_teardown
  613. *
  614. * Description:
  615. * Eliminate a UDP read-ahead notification previously setup by
  616. * udp_notifier_setup(). This function should only be called if the
  617. * notification should be aborted prior to the notification. The
  618. * notification will automatically be torn down after the notification.
  619. *
  620. * Input Parameters:
  621. * key - The key value returned from a previous call to
  622. * udp_notifier_setup().
  623. *
  624. * Returned Value:
  625. * Zero (OK) is returned on success; a negated errno value is returned on
  626. * any failure.
  627. *
  628. ****************************************************************************/
  629. #ifdef CONFIG_UDP_READAHEAD_NOTIFIER
  630. int udp_notifier_teardown(int key);
  631. #endif
  632. /****************************************************************************
  633. * Name: udp_notifier_signal
  634. *
  635. * Description:
  636. * Read-ahead data has been buffered. Notify all threads waiting for
  637. * read-ahead data to become available.
  638. *
  639. * When read-ahead data becomes available, *all* of the workers waiting
  640. * for read-ahead data will be executed. If there are multiple workers
  641. * waiting for read-ahead data then only the first to execute will get the
  642. * data. Others will need to call udp_notifier_setup() once again.
  643. *
  644. * Input Parameters:
  645. * conn - The UDP connection where read-ahead data was just buffered.
  646. *
  647. * Returned Value:
  648. * None.
  649. *
  650. ****************************************************************************/
  651. #ifdef CONFIG_UDP_READAHEAD_NOTIFIER
  652. void udp_notifier_signal(FAR struct udp_conn_s *conn);
  653. #endif
  654. #undef EXTERN
  655. #ifdef __cplusplus
  656. }
  657. #endif
  658. #endif /* CONFIG_NET_UDP && !CONFIG_NET_UDP_NO_STACK */
  659. #endif /* __NET_UDP_UDP_H */