diff --git a/include/nuttx/signal.h b/include/nuttx/signal.h index 3710f0ea1d..befc6ab684 100644 --- a/include/nuttx/signal.h +++ b/include/nuttx/signal.h @@ -59,6 +59,7 @@ enum nxsig_evtype_e NXSIG_IOB_AVAIL = 1, /* Signal availability of an IOB */ NXSIG_NET_DOWN, /* Signal that the network is down */ NXSIG_TCP_READAHEAD, /* Signal that TCP read-ahead data is available */ + NXSIG_TCP_DISCONNECT, /* Signal loss of TCP connection */ NXSIG_UDP_READAHEAD, /* Signal that TCP read-ahead data is available */ }; diff --git a/mm/iob/Kconfig b/mm/iob/Kconfig index 3bb1a8648b..f4899ead85 100644 --- a/mm/iob/Kconfig +++ b/mm/iob/Kconfig @@ -63,6 +63,7 @@ config IOB_NOTIFIER bool "Support IOB notifications" default n select SIG_NOTIFIER + depends on !DISABLE_SIGNALS ---help--- Enable building of IOB notifier logic that will send a signal to a kernel thread when an IOB is available. This is is a general diff --git a/net/netdev/Kconfig b/net/netdev/Kconfig index 9c66826f41..d7a8d648ec 100644 --- a/net/netdev/Kconfig +++ b/net/netdev/Kconfig @@ -36,4 +36,15 @@ config NETDEV_IFINDEX When enabled, these option also enables the user interfaces: if_nametoindex() and if_indextoname(). +config NETDOWN_NOTIFIER + bool "Support network down notifications" + default n + select SIG_NOTIFIER + depends on !DISABLE_SIGNALS + ---help--- + Enable building of logic that will send a signal to a kernel + thread when the network is taken down. This is is a general purpose + notifier, but was developed specifically to support SIGHUP poll() + logic. + endmenu # Network Device Operations diff --git a/net/netdev/Make.defs b/net/netdev/Make.defs index 28a8967c2e..b7e8ebcda1 100644 --- a/net/netdev/Make.defs +++ b/net/netdev/Make.defs @@ -45,6 +45,10 @@ ifeq ($(CONFIG_NETDEV_IFINDEX),y) NETDEV_CSRCS += netdev_indextoname.c netdev_nametoindex.c endif +ifeq ($(CONFIG_NETDOWN_NOTIFIER),y) +SOCK_CSRCS += netdown_notifier.c +endif + # Include netdev build support DEPPATH += --dep-path netdev diff --git a/net/netdev/netdev.h b/net/netdev/netdev.h index 9ccd7b8e49..62f6824fdf 100644 --- a/net/netdev/netdev.h +++ b/net/netdev/netdev.h @@ -466,6 +466,85 @@ int netdev_ipv6_ifconf(FAR struct lifconf *lifc); int netdev_dev_lladdrsize(FAR struct net_driver_s *dev); +/**************************************************************************** + * Name: netdown_notifier_setup + * + * Description: + * Set up to notify the specified PID with the provided signal number. + * + * NOTE: To avoid race conditions, the caller should set the sigprocmask + * to block signal delivery. The signal will be delivered once the + * signal is removed from the sigprocmask. + * + * Input Parameters: + * pid - The PID to be notified. If a zero value is provided, then the + * PID of the calling thread will be used. + * signo - The signal number to use with the notification. + * dev - The network driver to be monitored + * + * Returned Value: + * > 0 - The signal notification is in place. The returned value is a + * key that may be used later in a call to + * netdown_notifier_teardown(). + * == 0 - The the device is already down. 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. + * + ****************************************************************************/ + +#ifdef CONFIG_NETDOWN_NOTIFIER +int netdown_notifier_setup(int pid, int signo, FAR struct net_driver_s *dev); +#endif + +/**************************************************************************** + * Name: netdown_notifier_teardown + * + * Description: + * Eliminate a TCP read-ahead notification previously setup by + * netdown_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 + * netdown_notifier_setup(). + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. + * + ****************************************************************************/ + +#ifdef CONFIG_NETDOWN_NOTIFIER +int netdown_notifier_teardown(int key); +#endif + +/**************************************************************************** + * Name: netdown_notifier_signal + * + * Description: + * Read-ahead data has been buffered. Signal all threads waiting for + * read-ahead data to become available. + * + * When the read-ahead data becomes available, *all* of the waiters in + * this thread will be signaled. If there are multiple waiters then only + * the highest priority thread will get the data. Lower priority threads + * will need to call netdown_notifier_setup() once again. + * + * Input Parameters: + * dev - The TCP connection where read-ahead data was just buffered. + * + * Returned Value: + * None. + * + ****************************************************************************/ + +#ifdef CONFIG_NETDOWN_NOTIFIER +void netdown_notifier_signal(FAR struct net_driver_s *dev); +#endif + #undef EXTERN #ifdef __cplusplus } diff --git a/net/netdev/netdev_ioctl.c b/net/netdev/netdev_ioctl.c index c1baf47e6c..6e7bd663e5 100644 --- a/net/netdev/netdev_ioctl.c +++ b/net/netdev/netdev_ioctl.c @@ -1789,6 +1789,15 @@ void netdev_ifdown(FAR struct net_driver_s *dev) /* Notify clients that the network has been taken down */ (void)devif_dev_event(dev, NULL, NETDEV_DOWN); + +#ifdef CONFIG_NETDOWN_NOTIFIER + /* Provide signal notifications to threads that want to be + * notified of the network down state via signal. + */ + + netdown_notifier_signal(dev); +#endif + } } diff --git a/net/tcp/Kconfig b/net/tcp/Kconfig index 045e6a7f6f..8fc1d697fa 100644 --- a/net/tcp/Kconfig +++ b/net/tcp/Kconfig @@ -70,7 +70,7 @@ config TCP_READAHEAD_NOTIFIER bool "Support TCP read-ahead notifications" default n select SIG_NOTIFIER - depends on NET_TCP_READAHEAD && !DISABLE_POLL + depends on NET_TCP_READAHEAD && !DISABLE_SIGNALS ---help--- Enable building of TCP read-ahead notifier logic that will send a signal to a kernel thread when an TCP read-ahead data has been diff --git a/net/udp/Kconfig b/net/udp/Kconfig index 9f1aad0868..a6d035f45a 100644 --- a/net/udp/Kconfig +++ b/net/udp/Kconfig @@ -61,7 +61,7 @@ config UDP_READAHEAD_NOTIFIER bool "Support UDP read-ahead notifications" default n select SIG_NOTIFIER - depends on NET_UDP_READAHEAD && !DISABLE_POLL + depends on NET_UDP_READAHEAD && !DISABLE_SIGNALS ---help--- Enable building of UDP read-ahead notifier logic that will send a signal to a kernel thread when an UDP read-ahead data has been diff --git a/sched/Kconfig b/sched/Kconfig index 896142ae50..345877b912 100644 --- a/sched/Kconfig +++ b/sched/Kconfig @@ -1185,7 +1185,7 @@ config SIG_NOTIFIER config SIG_NOTIFIER_NWAITERS int "Number of signal waiters" - default 4 + default 8 range 1 32766 depends on SIG_NOTIFIER ---help---