Skip to content

Commit 5db412b

Browse files
committed
[add] a new function to manage internet check.
Signed-off-by: xiangxistu <[email protected]>
1 parent 53f5d0f commit 5db412b

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

components/net/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ config RT_USING_SAL
1010

1111
if RT_USING_SAL
1212

13+
config SAL_INTERNET_CHECK
14+
bool "Enable the ability that check internet status"
15+
default y
16+
help
17+
The ability that check internet status is provided by RT-Thread.
18+
1319
if RT_USING_LWIP || AT_USING_SOCKET
1420

1521
menu "protocol stack implement"

components/net/sal_socket/src/sal_socket.c

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include <sal.h>
2222
#include <netdev.h>
2323

24+
#ifdef SAL_INTERNET_CHECK
2425
#include <ipc/workqueue.h>
26+
#endif
2527

2628
/* check system workqueue stack size */
2729
#if RT_SYSTEM_WORKQUEUE_STACKSIZE < 1536
@@ -45,7 +47,7 @@ struct sal_socket_table
4547
struct sal_netdev_res_table
4648
{
4749
struct addrinfo *res;
48-
struct netdev *netdev;
50+
struct netdev *netdev;
4951
};
5052

5153
#ifdef SAL_USING_TLS
@@ -131,7 +133,7 @@ int sal_init(void)
131133

132134
/*init the dev_res table */
133135
rt_memset(sal_dev_res_tbl, 0, sizeof(sal_dev_res_tbl));
134-
136+
135137
/* create sal socket lock */
136138
rt_mutex_init(&sal_core_lock, "sal_lock", RT_IPC_FLAG_FIFO);
137139

@@ -142,6 +144,7 @@ int sal_init(void)
142144
}
143145
INIT_COMPONENT_EXPORT(sal_init);
144146

147+
#ifdef SAL_INTERNET_CHECK
145148
/* check SAL network interface device internet status */
146149
static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
147150
{
@@ -271,6 +274,7 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
271274
skt_ops->closesocket(sockfd);
272275
}
273276
}
277+
#endif /* SAL_INTERNET_CHECK */
274278

275279
/**
276280
* This function will check SAL network interface device internet status.
@@ -279,10 +283,12 @@ static void check_netdev_internet_up_work(struct rt_work *work, void *work_data)
279283
*/
280284
int sal_check_netdev_internet_up(struct netdev *netdev)
281285
{
286+
RT_ASSERT(netdev);
287+
288+
#ifdef SAL_INTERNET_CHECK
282289
/* workqueue for network connect */
283290
struct rt_delayed_work *net_work = RT_NULL;
284291

285-
RT_ASSERT(netdev);
286292

287293
net_work = (struct rt_delayed_work *)rt_calloc(1, sizeof(struct rt_delayed_work));
288294
if (net_work == RT_NULL)
@@ -293,7 +299,18 @@ int sal_check_netdev_internet_up(struct netdev *netdev)
293299

294300
rt_delayed_work_init(net_work, check_netdev_internet_up_work, (void *)netdev);
295301
rt_work_submit(&(net_work->work), RT_TICK_PER_SECOND);
302+
#else
303+
if(netdev_is_link_up(netdev))
304+
{
305+
netdev->flags |= NETDEV_FLAG_INTERNET_UP;
306+
}
307+
else
308+
{
309+
netdev->flags &= ~NETDEV_FLAG_INTERNET_UP;
310+
}
311+
LOG_D("You have shut down internet check function, internet status is subject to link status.");
296312

313+
#endif /* SAL_INTERNET_CHECK */
297314
return 0;
298315
}
299316

@@ -1138,7 +1155,7 @@ int sal_getaddrinfo(const char *nodename,
11381155
}
11391156

11401157
RT_ASSERT((i < SAL_SOCKETS_NUM));
1141-
1158+
11421159
}
11431160

11441161
return ret;

0 commit comments

Comments
 (0)