lwip-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lwip-users] lwip socket is stable


From: FreeRTOS Info
Subject: Re: [lwip-users] lwip socket is stable
Date: Mon, 15 Aug 2011 16:49:26 +0100
User-agent: Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20110624 Thunderbird/5.0

A couple of points:

>       if (bind(listenfd, (struct sockaddr *) &local_addr,
sizeof(local_addr)) < 0)
>       {
>               printf(" socket bind 8080fail \r\n");
>               return ;
>       }
>
>     if (listen(listenfd, 1) == -1)
>       {
>               return;
>       }


+ Never attempt to return from a task.  There is nothing to return to.
If you want to kill the task just call vTaskDelete( NULL );


+ As far as I can see, both tasks include a vTaskDelay() call, so both
should run.  If you are in any doubt that one task is using 100% CPU
time then you could set up the run time stats feature (which requires a
separate clock source, but should the CPU time allocated to each task).

+ You have a lot on the task stacks.  Is the stack size large enough?
Do you have run time stack checking switched on?


Regards,
Richard.

+ http://www.FreeRTOS.org
Designed for Microcontrollers.
More than 7000 downloads per month.




On 15/08/2011 04:09, vincent cui wrote:
> Dear everyone:
> 
> I create two task in freeRTOS. And use them to send/receive data from client..
> But only one task works .. I don't know why... 
> 
> 
> xTaskCreate( SocketTask, (signed char *) NULL, SOCKET_TASK_STACK_SIZE, NULL, 
> SOCKET_TASK_PRIORITY+0, NULL); 
> xTaskCreate( SocketTask1, (signed char *) NULL, SOCKET_TASK_STACK_SIZE, NULL, 
> SOCKET_TASK_PRIORITY+1, NULL);
> 
> void SocketTask(void * pvArg)
> {     
>       u8_t buf[32];
>       int count;
>       int listenfd;    
>       int remotefd;    
>       int len;   
>       struct sockaddr_in local_addr,remote_addr;          
>       fd_set readset;        
>       fd_set writeset;        
>       struct timeval timeout;        
>       timeout.tv_sec = 1;        
>       timeout.tv_usec = 0;  
>       // waiting for HDCP to get allocate IP
>       while (IPaddress == netif.ip_addr.addr)
>       {
>               vTaskDelay(100);
>       }
>       
>     listenfd = socket(AF_INET,SOCK_STREAM,0); 
>     local_addr.sin_family = AF_INET;    
>       local_addr.sin_port = htons(8080);    
>       local_addr.sin_len = sizeof(local_addr);    
>       local_addr.sin_addr.s_addr = INADDR_ANY;  
>       
>       if (bind(listenfd, (struct sockaddr *) &local_addr, sizeof(local_addr)) 
> < 0)     
>       { 
>               printf(" socket bind 8080fail \r\n");       
>               return ;    
>       } 
> 
>     if (listen(listenfd, 1) == -1)    
>       {        
>               return;    
>       } 
>     len = sizeof(remote_addr);        
>       while(1)        
>       {           
>               remotefd = accept(listenfd, (struct sockaddr *)&remote_addr, 
> &len);          
>               if(remotefd != -1)          
>               {          
>                       int ret;            
>                       send(remotefd,"start to work!\r\n",16,0);            
>                       for(;;)            
>                       {              
>                               FD_ZERO(&readset);              
>                               FD_ZERO(&writeset);               
>                               FD_SET(remotefd, &readset);              
>                               FD_SET(remotefd, &writeset); 
>                 ret = lwip_select(remotefd+1, &readset, &writeset, 0, 
> &timeout);                                   
>                               if(ret > 0)              
>                               {                
>                                       if (FD_ISSET(remotefd, &readset))       
>          
>                                       {                 
>                                                memset(buf,0,32);              
>   
>                                                if(recv(remotefd,buf,32,0) <= 
> 0)                  
>                                                {                    
>                                                       close(remotefd);        
>             
>                                                       remotefd = -1;          
>           
>                                                       break;                  
>                                                }                  
>                                                else                  
>                                                {                    
>                                                       int i = strlen(buf);    
>                 
>                                                       send(remotefd,buf,i 
> ,0);                   
>                                               }                
>                                       }                   
>                               }             
>                               else if(ret < 0)              
>                               {         
>                                       close(remotefd);                
>                                       remotefd = -1;                
>                                       break;              
>                               }  
>                               vTaskDelay(100);                        
>                       }          
>               } 
>               vTaskDelay(100);     
>       }
>        
> }
> 
> void SocketTask1(void * pvArg)
> {     
>       u8_t buf[32];
>       int count;
>       int listenfd;    
>       int remotefd;    
>       int len;   
>       struct sockaddr_in local_addr,remote_addr;          
>       fd_set readset;        
>       fd_set writeset;        
>       struct timeval timeout;        
>       timeout.tv_sec = 1;        
>       timeout.tv_usec = 0;  
>       // waiting for HDCP to get allocate IP
>       while (IPaddress == netif.ip_addr.addr)
>       {
>               vTaskDelay(100);
>       }
>       
>     listenfd = socket(AF_INET,SOCK_STREAM,0); 
>     local_addr.sin_family = AF_INET;    
>       local_addr.sin_port = htons(port);    
>       local_addr.sin_len = sizeof(8081);    
>       local_addr.sin_addr.s_addr = INADDR_ANY;  
>   
>       if (bind(listenfd, (struct sockaddr *) &local_addr, sizeof(local_addr)) 
> < 0)     
>       { 
>               printf(" socket bind 8081 fail \r\n");       
>               return ;    
>       } 
> 
>     if (listen(listenfd, 1) == -1)    
>       {        
>               return;    
>       } 
>     len = sizeof(remote_addr);        
>       while(1)        
>       {            
>               remotefd = accept(listenfd, (struct sockaddr *)&remote_addr, 
> &len);          
>               if(remotefd != -1)          
>               {          
>                       int ret;            
>                       send(remotefd,"start to work!\r\n",16,0);            
>                       for(;;)            
>                       {              
>                               FD_ZERO(&readset);              
>                               FD_ZERO(&writeset);               
>                               FD_SET(remotefd, &readset);              
>                               FD_SET(remotefd, &writeset); 
>                 ret = lwip_select(remotefd+1, &readset, &writeset, 0, 
> &timeout);                                   
>                               if(ret > 0)              
>                               {                
>                                       if (FD_ISSET(remotefd, &readset))       
>          
>                                       {                 
>                                                memset(buf,0,32);              
>     
>                                                if(recv(remotefd,buf,32,0) <= 
> 0)                  
>                                                {                    
>                                                       close(remotefd);        
>             
>                                                       remotefd = -1;          
>           
>                                                       break;                  
>                                                }                  
>                                                else                  
>                                                {                    
>                                                       int i = strlen(buf);    
>                 
>                                                       send(remotefd,buf,i 
> ,0);                  
>                                               }                
>                                       }                   
>                               }             
>                               else if(ret < 0)              
>                               {         
>                                       close(remotefd);                
>                                       remotefd = -1;                
>                                       break;              
>                               }  
>                               vTaskDelay(100);                        
>                       }          
>               } 
>               vTaskDelay(100);     
>       }
>        
> }
> ----------------------------------------------------------------------
> 
> 锘?Vincent Cui
> Sr.Firmware Engineer
> Mobile: +8613482482211
> Tel: +86 21 34612525x6104
> Fax: +86 21 34619770
> E-Mail: address@hidden
> Shanghai EnLogic Electric Technology Co., Ltd.
> Address: 1104-1106, Building A, No.391, Guiping Road, Xuhui District, 
> Shanghai, 200233
> http://www.enlogic.com
> -----Original Message-----
> From: address@hidden [mailto:address@hidden On Behalf Of FreeRTOS Info
> Sent: 2011年8月12日 16:38
> To: Mailing list for lwIP users
> Subject: Re: [lwip-users] lwip socket is stable
> 
> I think, to get a reasonable answer, you would fist have to post the
> relevant snippet of your code - the bit that is accepting and using
> connections.
> 
> 
> Regards,
> Richard.
> 
> + http://www.FreeRTOS.org
> Designed for Microcontrollers.
> More than 7000 downloads per month.
> 
> 
> 
> 
> On 12/08/2011 08:53, vincent cui wrote:
>> Kieran Mansley:
>>
>> I create a task that will listen 8080 port and receive data from client. And 
>> I use TCP tool to connect it and send data, it works well
>>
>> But, I add to create a task that will listen 8081 port. After the first task 
>> connect and work,, the second task cann't connect... 
>>
>> Why ? 
>>
>>
>> Vincent 
>>
>>
>>
>> ï»?Vincent Cui
>> Sr.Firmware Engineer
>> Mobile: +8613482482211
>> Tel: +86 21 34612525x6104
>> Fax: +86 21 34619770
>> E-Mail: address@hidden
>> Shanghai EnLogic Electric Technology Co., Ltd.
>> Address: 1104-1106, Building A, No.391, Guiping Road, Xuhui District, 
>> Shanghai, 200233
>> http://www.enlogic.com
>> -----Original Message-----
>> From: address@hidden [mailto:address@hidden On Behalf Of Kieran Mansley
>> Sent: 2011Äê8ÔÂ11ÈÕ 22:44
>> To: Mailing list for lwIP users
>> Subject: Re: [lwip-users] lwip socket is stable
>>
>> On Thu, 2011-08-11 at 14:27 +0000, vincent cui wrote:
>>> I mean lwIP socket code is without error correction .
>>
>> If you use a SOCK_STREAM socket it will be reliable, and in order, as
>> for any SOCK_STREAM socket on any other system.  If you use a SOCK_DGRAM
>> socket it will (again, as for other systems) be unreliable and
>> potentially out of order.  
>>
>>> I will port BOA webserver base on lwIP..is it feasible ?
>>
>> No idea; I've no experience of that webserver I'm afraid.
>>
>> Kieran
>>
>>
>> _______________________________________________
>> lwip-users mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/lwip-users
>> _______________________________________________
>> lwip-users mailing list
>> address@hidden
>> https://lists.nongnu.org/mailman/listinfo/lwip-users
> 
> 
> _______________________________________________
> lwip-users mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/lwip-users
> _______________________________________________
> lwip-users mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/lwip-users




reply via email to

[Prev in Thread] Current Thread [Next in Thread]