[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lwip-devel] [PATCH 1/3] Add non-blocking write API to network devices
From: |
Russ Dill |
Subject: |
[lwip-devel] [PATCH 1/3] Add non-blocking write API to network devices |
Date: |
Fri, 23 Oct 2015 04:53:32 -0700 |
This adds a non-blocking API option for network devices. Network devices that
can support a non-blocking write API advertise by setting their
NETIF_FLAG_NONBLOCK flag. Users of the non-blocking API can then activate the
API by setting the write_ready callback.
When the non-blocking API is active, the device driver may return
ERR_WOULDBLOCK for any of it's output functions (output, output_ip6,
linkoutput). Instead of being dropped, the caller should retain the packet.
When the network device can again accept packets, it should call the
write_ready callback. The pending packets can then be passed to the output
function again.
Signed-off-by: Russ Dill <address@hidden>
---
src/include/lwip/netif.h | 20 ++++++++++++++++++++
src/include/lwip/opt.h | 8 ++++++++
2 files changed, 28 insertions(+)
diff --git a/src/include/lwip/netif.h b/src/include/lwip/netif.h
index 7435221..e7ad81b 100644
--- a/src/include/lwip/netif.h
+++ b/src/include/lwip/netif.h
@@ -98,6 +98,10 @@ extern "C" {
/** If set, the netif has MLD6 capability.
* Set by the netif driver in its init function. */
#define NETIF_FLAG_MLD6 0x40U
+/** If set, the netif has non-blocking operation capability. This allows the
+ * netif to be used in a scheduling discipline.
+ * Set by the netif driver in its init function. */
+#define NETIF_FLAG_NONBLOCK 0x80U
#if LWIP_CHECKSUM_CTRL_PER_NETIF
#define NETIF_CHECKSUM_GEN_IP 0x0001
@@ -130,6 +134,17 @@ typedef err_t (*netif_init_fn)(struct netif *netif);
*/
typedef err_t (*netif_input_fn)(struct pbuf *p, struct netif *inp);
+/** Function prototype for netif->write_ready functions. This function is saved
+ * as 'write_ready' callback function in the netif struct. This
function is assigned
+ * when operating in non-blocking mode. It should be called when the
interface is
+ * ready to send more packets after having previously returned
ERR_WOULDBLOCK from
+ * one of the output functions. Note that calling this function may cause the
+ * output functions of the netif to be called.
+ *
+ * @param netif The associated netif
+ */
+typedef void (*netif_write_ready_fn)(struct netif *netif);
+
#if LWIP_IPV4
/** Function prototype for netif->output functions. Called by lwIP
when a packet
* shall be sent. For ethernet netif, set this to 'etharp_output' and set
@@ -199,6 +214,11 @@ struct netif {
/** This function is called by the network device driver
* to pass a packet up the TCP/IP stack. */
netif_input_fn input;
+#if LWIP_NETIF_NONBLOCKING
+ /** This function is called by the network device driver when it is ready to
+ * send more packets */
+ netif_write_ready_fn write_ready;
+#endif
#if LWIP_IPV4
/** This function is called by the IP module when it wants
* to send a packet on the interface. This function typically
diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h
index 0e84712..926c2ab 100644
--- a/src/include/lwip/opt.h
+++ b/src/include/lwip/opt.h
@@ -1438,6 +1438,14 @@
#define LWIP_NETIF_TX_SINGLE_PBUF 0
#endif /* LWIP_NETIF_TX_SINGLE_PBUF */
+/**
+ * LWIP_NETIF_NONBLOCKING==1: support a nonblocking write API for network
+ * interfaces.
+ */
+#ifndef LWIP_NETIF_NONBLOCKING
+#define LWIP_NETIF_NONBLOCKING 0
+#endif
+
/*
------------------------------------
---------- LOOPIF options ----------
--
2.5.0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lwip-devel] [PATCH 1/3] Add non-blocking write API to network devices,
Russ Dill <=