void ServerTask( void )
{
...
while( 1 )
{
sock1 = socket( ... );
bind( sock1, ... );
listen( sock1, ... );
while( 1 )
{
sock2 = accept( sock1, ... )
if( sock2 < 0 )
break;
xTaskCreate( SessionTask, ..., sock2, ... );
}
shutdown( sock1, SHUT_RDWR ));
closesocket( sock1 );
}
}
void SessionTask( int sock3 )
{
...
while( 1 )
{
recv( sock3, ... );
... //process the protocol
send( sock3, ... );
if(( IsError1 != 0 ) || ( NeedToTerminate1 != 0 ))
break;
}
shutdown( sock3, SHUT_RDWR ));
closesocket( sock3 );
vTaskDelete( NULL );
}
void TerminalTask( void )
{
...
while( 1 )
{
sock4 = socket( ... );
bind( sock4, ... );
listen( sock4, ... );
while( 1 )
{
sock5 = accept( sock4, ... )
if( sock5 < 0 )
break;
... //sends debug messages on sock4 until the client is connected
}
shutdown( sock4, SHUT_RDWR ));
closesocket( sock4 );
}
}
void NotificationTask( void )
{
...
while( 1 )
{
sock6 = socket( ... );
if( connect( sock6, ... ) != 0 )
{
closesocket( sock6 );
... //delay 10 s
continue;
}
while( 1 )
{
send( sock6, ... );
... //process the protocol
recv( sock6, ... );
if(( IsError2 != 0 ) || ( NeedToTerminate2 != 0 ))
break;
}
closesocket( sock6 );
}
}
xTaskCreate( ServerTask, ... );
xTaskCreate( TerminalTask, ... );
xTaskCreate( NotificationTask, ... );
vTaskDelete( NotificationTaskHandle );
if( sock6_IsValid )
closesocket( sock6 );
xTaskCreate( NotificationTask, ... );
LWIP_ASSERT("state!", msg->conn->state == NETCONN_CONNECT);
UNLOCK_TCPIP_CORE();
sys_arch_sem_wait(LWIP_API_MSG_SEM(msg), 0);
LOCK_TCPIP_CORE();
LWIP_ASSERT("state!", msg->conn->state != NETCONN_CONNECT);