3 sockets problems error in RTCS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

3 sockets problems error in RTCS

Jump to solution
5,619 Views
epl
Contributor I

Enviroment: M52259 demo board with MQX3.4

 

I have tried to connect 3 sockets in a port (or even 3 sockets in 3 ports).

The first two sockets can use normally, but the last one always failed when accept.

 

Who can tell me where I'm wrong or something can be modified?

Or the idea to the failed one socket.

 

Thx,

:smileyhappy:

 

Lists attatched below:

 

 

uint_32 sock, sock1, sock2;
sockaddr_in remote_addr;
uint_16 remote_addr_len, rlen;

 

for(;:smileywink:
{
   sock = RTCS_selectall(0);
   if (sock == listensock) {
    /* Connection requested; accept it. */
    rlen = sizeof(remote_addr);
    sock = accept(listensock, &remote_addr, &rlen);
    
    if (sock == RTCS_SOCKET_ERROR) {
     printf("\naccept() failed, error 0x%lx\n",RTCS_geterror(listensock));
     printf("in while\n");
     continue;
    }
    
    if(RTCS_detachsock(sock) == RTCS_OK)
    {
     printf("accept ok\n");
    }
    else
    {
     printf("\naccept() failed, error 0x%lx", RTCS_geterror(sock));
    }
    
   }
   
   sock1 = RTCS_selectall(0);
   if (sock1 == listensock) {
    /* Connection requested; accept it. */
    rlen = sizeof(remote_addr);
    sock1 = accept(listensock, &remote_addr, &rlen);
    
    if (sock1 == RTCS_SOCKET_ERROR) {
     printf("\naccept() failed, error 0x%lx\n",RTCS_geterror(listensock));
     printf("in while\n");
     continue;
    }
    
    if(RTCS_detachsock(sock1) == RTCS_OK)
    {
     printf("accept ok\n");
    }
    else
    {
     printf("\naccept() failed, error 0x%lx", RTCS_geterror(sock1));
    }
    
 }
   
   sock2 = RTCS_selectall(0);
   if (sock2 == listensock) {
    /* Connection requested; accept it. */
    rlen = sizeof(remote_addr);
    sock2 = accept(listensock, &remote_addr, &rlen);
    
    if (sock2 == RTCS_SOCKET_ERROR) {
     printf("\naccept() failed, error 0x%lx\n",RTCS_geterror(listensock));
     printf("in while\n");
     continue;
    }
    
    if(RTCS_detachsock(sock2) == RTCS_OK)
    {
     printf("accept ok\n");
    }
    else
    {
     printf("\naccept() failed, error 0x%lx", RTCS_geterror(sock2));
    }
    
}

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,948 Views
JeffBaker1
Contributor I

I got the same issue and I figured it out after one week's digging Freescale codes. The main problem is the memory limiation if you use the default RTCS settings.

 

Total available RAM is 59.0KB. With TAD, you can see that every new TCP socket connection needs extra 500+4392x2+148=9432B/59.0KB=16% as follows:
 

MQX -> Lightweight Memory Block Summary
Size (Decimal) Owner    Type
500      0x10001  TCP Control Block;RTCS/TCP
4392   0x10001  TCP Tx Window;RTCS/TCP
4392   0x10001  TCP Rx Window;RTCS/TCP
148     0x10001  TCP Send Clock;RTCS/TCP
(TCP/IP Task id is 0x10001)

 

The default OPT_TBSIZE and OPT_RBSIZE are 4380 bytes. If you call setsockopt() to reduce these two, for example, to a quarter like 1095 bytes, the memory usage to open a new TCP socket will drop from 16% to 4.7% as follows:

 

MQX -> Lightweight Memory Block Summary
Size (Decimal) Owner    Type
500  ->  500   0x10001  TCP Control Block;RTCS/TCP
4392 -> 1108   0x10001  TCP Tx Window;RTCS/TCP
4392 -> 1108   0x10001  TCP Rx Window;RTCS/TCP
148  ->   84   0x10001  TCP Send Clock;RTCS/TCP

View solution in original post

0 Kudos
Reply
13 Replies
1,948 Views
c_dawg
Contributor III

Thanks for the solution!  It is important to note when creating a project using CW 10.2 with MQX 3.8 selecting “Add RTCS support” will create rtcs_init.c.  This file contains RTCS_create() called by rtcs_init() in main.c. So it is important to have:

    _RTCS_socket_part_init = 4;

    _RTCS_socket_part_grow = 2;

    _RTCS_socket_part_max  = 20;

before rtcs_init() in main.c.

I haven't run into the memory problem yet...

0 Kudos
Reply
1,948 Views
ElliottKevin
Contributor I

Thanks man


__________________________________________________
Ford shocks and struts
Toyota quick strut
Nissan quick strut

0 Kudos
Reply
1,949 Views
JeffBaker1
Contributor I

I got the same issue and I figured it out after one week's digging Freescale codes. The main problem is the memory limiation if you use the default RTCS settings.

 

Total available RAM is 59.0KB. With TAD, you can see that every new TCP socket connection needs extra 500+4392x2+148=9432B/59.0KB=16% as follows:
 

MQX -> Lightweight Memory Block Summary
Size (Decimal) Owner    Type
500      0x10001  TCP Control Block;RTCS/TCP
4392   0x10001  TCP Tx Window;RTCS/TCP
4392   0x10001  TCP Rx Window;RTCS/TCP
148     0x10001  TCP Send Clock;RTCS/TCP
(TCP/IP Task id is 0x10001)

 

The default OPT_TBSIZE and OPT_RBSIZE are 4380 bytes. If you call setsockopt() to reduce these two, for example, to a quarter like 1095 bytes, the memory usage to open a new TCP socket will drop from 16% to 4.7% as follows:

 

MQX -> Lightweight Memory Block Summary
Size (Decimal) Owner    Type
500  ->  500   0x10001  TCP Control Block;RTCS/TCP
4392 -> 1108   0x10001  TCP Tx Window;RTCS/TCP
4392 -> 1108   0x10001  TCP Rx Window;RTCS/TCP
148  ->   84   0x10001  TCP Send Clock;RTCS/TCP

0 Kudos
Reply
1,948 Views
epl
Contributor I

Thank you!

0 Kudos
Reply
1,948 Views
pet
Contributor I

Hi Jeff,

 

how and where i can reduce the Lightweight Memory Block Summary to get able connect 3 socket with different ports.

I just working since 3 days with MQX.

 

thanks!

 

Peter

0 Kudos
Reply
1,948 Views
JeffBaker1
Contributor I

 

Hi Peter,

 

As I mentioned in my previous post, you call function setsockopt() before RTCS_create(). In the pages 266 and page 269 of Freescale MQX RTCS User's Guide, Rev. 4, there are explanation of how to configure OPT_TBSIZE and OPT_RBSIZE in setsockopt(). The default OPT_TBSIZE and OPT_RBSIZE are 4380 bytes. Make sure that your ethenet packet size is less than the number of bytes you try to update.

0 Kudos
Reply
1,948 Views
pet
Contributor I

it works now..

 

thank you!

 

 

0 Kudos
Reply
1,948 Views
PetrM
Senior Contributor I

Hello,

 

number of sockets is limited by default.

Try this (before RTCS_create()) to override default settings:

 

   _RTCS_socket_part_init = 4;
   _RTCS_socket_part_grow = 2;
   _RTCS_socket_part_max  = 20;

PetrM

 

0 Kudos
Reply
1,948 Views
rdazcal
Contributor III

Why these values? What do they mean?

 

I need to have 6 sockets open at one... with your modification I can get up to four.

 

I found a resumed explanation of them in the RTCSUG but it's a bit superficial...

 

0 Kudos
Reply
1,948 Views
epl
Contributor I

hi


Recently I am working on more than three sockets, but failed even with only four sockets. 


The socket just stuck in the "accept" function and never returned. 


I tried to change the three parameters (_RTCS_socket_part_init,  _RTCS_socket_part_grow and  _RTCS_socket_part_max) to different values but don't really get any remarkable results.

(to rdazcal: I don't get the meanings of the three parameters either  :smileysad:  )


I wonder is there any other parameter I need to define or modify? 


Thanks to all solutions provided in advance. 


 

0 Kudos
Reply
1,948 Views
rdazcal
Contributor III

Hi all,

 

Turns out PeterM's parametrization do work for 6 sockets.

 

I found out that I had a second problem, other than the Socket limitation. It was memory limitation.

 

I initialized the Telnet Server, and than tried to create two tasks. The seccond one would fail due to lack of memory.

 

From what I could understand, when you create a Task, it's stack will be created in the default memory pool (please Freescalers, correct me if I'm wrong). I was assigning 3000 bytes for each task stack, so it consumed all of my memory.

 

I don't have CW professional edition, so it's quite a chalenge finding out these memory issues!

 

See if that info helps you epl

0 Kudos
Reply
1,948 Views
epl
Contributor I

hi 
I found myself still get limitation with max 3 sockets even with simple Ethernet application. 
Worrying about the memory problem, I also decreased each thread's stack as small as it can normally works. Nevertheless, the 3 sockets problem still exists.   :smileysad:
Is there anyone already exceeds 3 socket connections?  
Thank you! 

 

0 Kudos
Reply
1,948 Views
epl
Contributor I

thx for your help very much.

It's seems ok by your pre-definition settings.

:smileyhappy:

 

0 Kudos
Reply