Hi tes_wzm (...?)
I am using lwIP 3.0 at the moment and had to shut it down as well.
My solution may not be perfect, but at least it works without any thread
killing...
1. I added a TCPIP_MSG_TERMINATE tcpip_msg_type to the enumeration
2. I added a case to the tcpip_thread switch:
while(1) { /* Main Loop */
...
...
case TCPIP_MSG_TERMINATE:
LWIP_DEBUGF(TCPIP_DEBUG, ("tcpip_thread: Terminating\n"));
sys_sem_signal(*(msg->sem));
return;
}
3. I added the tcpip_terminate() function to tcpip.c
void
tcpip_terminate(void)
{
struct tcpip_msg msg;
sys_sem_t sem;
/* If there is no tcpip mailbox, leave */
if (mbox == SYS_MBOX_NULL)
return;
/* Create semaphore for message */
sem = sys_sem_new(0);
/* TODO: how should we handle failure here? */
LWIP_ASSERT("tcpip_terminate: failed to create semaphore\n",
sem != SYS_SEM_NULL);
/* TODO: do we need to stop the timers? if so, how? */
/* Tell tcpip thread to exit, and wait */
msg.sem = &sem;
msg.type = TCPIP_MSG_TERMINATE;
sys_mbox_post(mbox, &msg);
sys_arch_sem_wait(sem, 0);
/* clean up tcpip thread resources */
sys_mbox_free(mbox);
sys_sem_free(sem);
mbox = SYS_MBOX_NULL;
/* clean up all initialized lwip components */
lwip_cleanup();
}
4. Before calling tcpip_terminate(), you had better make sure you clean
up all PPP sessions, interfaces, and anything else you've initialized
via the tcpip based APIs.
5. The lwip_cleanup() at the end of the function is not a part of lwIP.
I've added it in init.c as a reciprocal for lwip_init(). It basically
needs to clean up any resources that lwip_init() allocates, but I did
not get to do that part yet (nor even check if its necessary).
HTH,
Yoav.
On 29/03/10 10:36 AM, tes_wzm wrote:
> I use lwip+ppp to send data to my tcp server. When sth occured, I want
> to close tcp thread. How can I do it? If I kill this thread through
> OS, it will leak some memory which use to create mailbox and sem. Is't
> some routes to release this memory?
> View this message in context: How to close tcp_thread
> <http://old.nabble.com/How-to-close-tcp_thread-tp28065857p28065857.html>
> Sent from the lwip-users mailing list archive
> <http://old.nabble.com/lwip-users-f7923.html> at Nabble.com.
>
>
> _______________________________________________
> lwip-users mailing list
> [email protected]
> http://lists.nongnu.org/mailman/listinfo/lwip-users
--
Yoav Nissim
Software Engineer, Software Tools Division
Jungo Software Technologies
Email: [email protected]
Web: http://www.jungo.com
Phone: +972-74-7212138
Fax: +972-74-7212122
Mobile: +972-54-2271315
_______________________________________________
lwip-users mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lwip-users