Closing sockets while destroying task

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Closing sockets while destroying task

340 次查看
Teckna
Contributor V

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

标签 (1)
0 项奖励
0 回复数