Teckna Teckna

Closing sockets while destroying task

Discussion created by Teckna Teckna on Mar 14, 2013

Hi everyone,

 

I'm using CW 10.2, MQX 3.8.1 and a custom board based on Kinetis K60.

 

Basically I have 2 tasks task_a that creates task_b:

 

task_a

 

{

     ...

     _task_create( ... task_b ... );

     ...

     _task_abort( ... task_b ... );

     ...

}

 

task_b

 

{

 

 

 

     ...

     sock1 = socket( AF_INET, SOCK_STREAM, 0 );

     ...

 

     if( bind( sock1, ... ) != RTCS_OK )

          return;

     if( listen( sock1, 0 ) != RTCS_OK )

          return;

     sock2 = accept( sock1, ... );

     ...

}

 

 

When task_b is executed, it creates a socket (sock1) and waits for a connection, blocking itself inside the accept() function. If no connection is made task_b waits infinitely, so sock2 is not assigned. When task_a must close task_b, the sockets created by task_b must be closed. The problem is that sock1 is assigned, but sock2 is already unassigned, but the function accept(), before blocking, has allocated the socket structure that is normally released by closing the socket.

 

How can I correctly close the socket?

 

Many thanks

Teckna

Outcomes