|
From: | Yoav Nissim |
Subject: | Re: [lwip-users] How to close tcp_thread |
Date: | Wed, 28 Apr 2010 09:55:43 +0300 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.7) Gecko/20100111 Lightning/1.0b1 Thunderbird/3.0.1 |
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? -- Yoav Nissim Software Engineer, Software Tools Division Jungo Software Technologies Email: address@hidden Web: http://www.jungo.com Phone: +972-74-7212138 Fax: +972-74-7212122 Mobile: +972-54-2271315 |
[Prev in Thread] | Current Thread | [Next in Thread] |