diff --git a/net/socket/net_clone.c b/net/socket/net_clone.c index 8139411529..dcaf92ecce 100644 --- a/net/socket/net_clone.c +++ b/net/socket/net_clone.c @@ -38,7 +38,6 @@ ****************************************************************************/ #include -#ifdef CONFIG_NET #include #include @@ -48,8 +47,11 @@ #include #include +#include "tcp/tcp.h" #include "socket/socket.h" +#ifdef CONFIG_NET + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -101,6 +103,15 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2) DEBUGASSERT(psock2->s_sockif != NULL && psock2->s_sockif->si_addref != NULL); psock2->s_sockif->si_addref(psock2); +#ifdef NET_TCP_HAVE_STACK + /* For connected socket types, it is necessary to also start the network monitor so + * that the newly cloned socket can receive a notification if the network connection + * is lost. + */ + + ret = tcp_start_monitor(psock2); +#endif + net_unlock(); return ret; } diff --git a/net/socket/socket.h b/net/socket/socket.h index 54e1c4daea..f90cf85a35 100644 --- a/net/socket/socket.h +++ b/net/socket/socket.h @@ -354,5 +354,24 @@ int net_timeo(systime_t start_time, socktimeo_t timeo); ssize_t psock_send(FAR struct socket *psock, FAR const void *buf, size_t len, int flags); +/**************************************************************************** + * Name: net_clone + * + * Description: + * Performs the low level, common portion of net_dupsd() and net_dupsd2() + * + * Input Parameters: + * psock1 - The existing socket that is being cloned. + * psock2 - A reference to an uninitialized socket structure alloated by + * the caller. + * + * Returned Value: + * Zero (OK) is returned on success; a negated errno value is returned on + * any failure. + * + ****************************************************************************/ + +int net_clone(FAR struct socket *psock1, FAR struct socket *psock2); + #endif /* CONFIG_NET */ #endif /* _NET_SOCKET_SOCKET_H */ diff --git a/net/tcp/tcp_callback.c b/net/tcp/tcp_callback.c index 532d934c9b..c3fd08e3a6 100644 --- a/net/tcp/tcp_callback.c +++ b/net/tcp/tcp_callback.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/tcp/tcp_callback.c * - * Copyright (C) 2007-2009, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2014, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -39,8 +39,6 @@ #include -#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) - #include #include #include @@ -53,6 +51,8 @@ #include "devif/devif.h" #include "tcp/tcp.h" +#ifdef NET_TCP_HAVE_STACK + /**************************************************************************** * Private Functions ****************************************************************************/ @@ -279,4 +279,4 @@ uint16_t tcp_datahandler(FAR struct tcp_conn_s *conn, FAR uint8_t *buffer, } #endif /* CONFIG_NET_TCP_READAHEAD */ -#endif /* CONFIG_NET && CONFIG_NET_TCP */ +#endif /* NET_TCP_HAVE_STACK */ diff --git a/net/tcp/tcp_monitor.c b/net/tcp/tcp_monitor.c index 854d04fc63..5c9c4863c8 100644 --- a/net/tcp/tcp_monitor.c +++ b/net/tcp/tcp_monitor.c @@ -38,7 +38,6 @@ ****************************************************************************/ #include -#if defined(CONFIG_NET) && defined(CONFIG_NET_TCP) #include #include @@ -357,5 +356,3 @@ void tcp_lost_connection(FAR struct socket *psock, uint16_t flags) } #endif /* NET_TCP_HAVE_STACK */ - -#endif /* CONFIG_NET && CONFIG_NET_TCP */