|
From: | linkaiqin |
Subject: | [lwip-users] The issue about gethostbyname() function |
Date: | Wed, 13 Jan 2016 00:52:04 +0800 |
I have a project using lwip stack with uCOS-III RTOS. lwip version is lwip-37bb0b89f062ed4fc47f0e42146dfdb065e1d6c4 that is from git.
My application thread priority is higher than lwip tcpip_thread priority.
When application call gethostbyname(), My RTOS detect the parameter *sem of sys_sem_signal() is uncorrect object type. After debug, I find the problem.
The gethostbyname() calling procedure is that:
lwip_gethostbyname()
netconn_gethostbyname_addrtype()
tcpip_callback(lwip_netconn_do_gethostbyname, &API_VAR_REF(msg));
sys_sem_wait(API_EXPR_REF_SEM(API_VAR_REF(msg).sem));
sys_sem_free(API_EXPR_REF(API_VAR_REF(msg).sem));
When application thread execute to sys_sem_wait() above, it will block.
Then lwip tcpip_thread will call lwip_netconn_do_gethostbyname(msg) function whose calling procedure is that:
lwip_netconn_do_gethostbyname()
dns_gethostbyname_addrtype()
dns_enqueue()
dns_check_entry() dns.c:1379
dns_send() dns.c:985
dns_call_found() dns.c:735
lwip_netconn_do_dns_found(arg) dns.c:899
msg->err = ERR_VAL
sys_sem_signal(msg->sem)
After calling sys_sem_signal(msg->sem) function, application thread will run again immediately since its priority is higher than lwip tcpip_thread. Then application thread will free msg->sem by calling sys_sem_free().
Once lwip tcpip_thread continue to run, lwip_netconn_do_gethostbyname() will check msg->err if unequal to ERR_INPROGRESS. Because msg->err is set to ERR_VAL above, so sys_sem_signal(msg->sem) will be called.However, msg->sem is freed already.
This output info by usart is that:
dns_enqueue: "www.baidu.com": use DNS entry 0
dns_enqueue: "www.baidu.com": use DNS pcb 0
dns_send: dns_servers[0] "www.baidu.com": request
lwip_gethostbyname(www.baidu.com) failed, err=-6
Could not find host www.baidu.com
sys_sem_signal: err:24004
[Prev in Thread] | Current Thread | [Next in Thread] |