udp.h 25 KB

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