Hi everyone,
I'm using CW 10.2, MQX 3.8.1 and a custom board with MK60DN512
Here is a sample test task:
error = RTCS_create();
if( error != RTCS_OK )
{
printf( "\nRTCS failed to initialize, error = %X", error );
return;
}
while( 1 )
{
FTPd_init( "FTP server", PRIO_FTPSRV, STACK_FTPSRV );
_time_delay_ticks( 500 );
FTPd_stop();
_time_delay_ticks( 500 );
}
If I run this test, after some times the FTP cycle is executed I can see the socket number grow up (like in the picture):
The FTPd_init function creates an FTP server task that creates two sockets (the socket in listening state and the socket in ground state).
The FTPd_stop function destroys the task FTP server task, but it seems to close only the socket in listening state and not the socket in ground state.
Is this a bug or don't I make the correct steps to close both sockets?
Many thanks
Teckna
Hi Teckna,
The reason you are getting out of sockets is because they are not closing immediately due some timer that are inside the TCPIP stack that are meant to allow that all the communications in the sockets are closed gratefully. These timers are around the minutes. You are not giving more than 2 seconds to release the sockets and this is stressing for the system.
For the FTP server there are some options for the user_config.h file that might help:
FTPDCFG_SHUTDOWN_OPTION
Flags used in shutdown() for close connection. Default value FLAG_ABORT_CONNECTION.
FTPDCFG_CONNECT_TIMEOUT
Connection timeout.
FTPDCFG_SEND_TIMEOUT
Sending timeout.
FTPDCFG_TIMEWAIT_TIMEOUT
The timeout.
Hope this helps.
Regards,
-Garabo
Hi Garabo,
All the options you suggested have their default values; I've change the code of the test:
FTPd_init( "FTP server", PRIO_FTPSRV, STACK_FTPSRV );
_time_delay_ticks( 50 );
FTPd_stop();
while( 1 )
_time_delay_ticks( 5 );
After running this test for about 25 minutes, the socket in ground state is still in the socket list.
Do you have other suggestions?
Many thanks
Teckna
Hi Teckna,
Are you able to see in the Task Aware Debugging who is the owner of the socket? The Server daemon or the Server child?
Regards,
-Garabo
Hi Garabo,
The owner of the socket is "System".
If I break in my test before the FTPd_stop is called, there are two sockets in the list:
If I break in my test after the FTPd_stop is called, there is only the second socket in the list, and it remains there for at least half an hour.
Many thanks
Teckna
Hi.
Sounds like a bug to me (but I am not an RTCS expert). FTP uses two sockets. One for commands and the other for data. If both are not being closed when the FTP server task is shut down it seems like a mistake.
Good luck.
Hi,
Many thanks for your answer.
The two sockets (the one in listening state and the one in the ground state) are both related the command port. The sockets related to the data port are created only when the connection with the command port is established.
The socket in the listening state is the one created with the socket function, while the socket in the ground state is the one created with the accept function.
No connection is established, so the program is blocked inside the accept function, waiting for an incoming connection. The accept function have not returned, but the socket have already been created (i.e., the socket data structure have already been allocated).
When the FTPd_stop function is called, the FTPd_Exit_handler is called and the shutdown of the socket in the listening state is performed (the socket data structure is deallocated), but the shutdown of the socket in the ground state is not performed (and the socket data structure is not deallocated): I suppose that the problem is that because of the accept function have not returned, the socket value of the socket in the ground state is still unkwnown at the higher level, so no shutdown can be performed.
Am I right or do I make a mistake?
Many thanks
Teckna