• Resolved

RTOS: NDK sockets

Tool/software: TI-RTOS

Hello,

 I have set up a TCP server and enabled  the socket’s options:  SO_RCVTIMEO , SO_SNDTIMEO.

I called recv() with the flag MSG_WAITALL  and I noticed that there is no timeout on recv() (i.e. after the time defined with SO_RCVTIMEO recv() still blocks())

From what I read I could not find an explicit answer but it sounded like that the timeout option should be in effect, if set ,even with MSG_WAITALL in recv().

I also tried removing the MSG_WAITALL from recv() (setting flags parameter to 0) and still recv() blocks forever without any timeout.

Can you please explain (or help fix)  why the timeout does not hold ?

Thanks 

Guy

  • What values are you using for the timeout? Are you letting the kernel create the default 1ms clock tick? You can look in ROV->Clock to confirm this. Is the clock tick advancing if you run, look at the tick count in ROV, run, and look at the tick count in ROV again.

    Also, what NDK version are you using?
  • In reply to ToddMullanix:

    Hi,
    I looked at ROV and the clock it ticking.

    as for the timeout the socket option is set as follows:

    struct timeval tv;
    tv.tv_sec = 5;
    tv.tv_usec = 0;
    setsockopt(hSock,SOL_SOCKET,SO_RCVTIMEO,&tv,sizeof(tv));

    i also check the setsockopt returns without errors.

    NDK version i use - 2.24.2.31

    Thanks
    Guy
  • In reply to Guy Mardiks:

    Thanks. I'll check this out tomorrow when I'm in the office. Sorry, I forgot to ask what device are you on?
  • In reply to ToddMullanix:

    Hi,
    I am working on TDA3xx (the specific code is on the ARM M4)

    Thanks
    Guy
  • In reply to Guy Mardiks:

    Hi Guy,

    I tried an example with 2.24.02.31 (and again with 2.25.00.09) and it worked fine. I set both SO_RCVTIMEO and SO_SNDTIMEO to 5 seconds. I had my laptop sending a TCP packet (on port 1000)that the target just echo'd back. I had the laptop stop sending for a bit but not close the socket. I checked (via WireShark) that the target closed the socket in 5 seconds.  

    Here is the primary source file that I used for testing.

    tcpEcho.c

    Todd

  • In reply to ToddMullanix:

    Hi,
    Thanks you for you help.
    It was my mistake - my client was closing the socket before the timeout expiration so the accepted socket on the server side never had a chance to actually timeout. i changed the client and indeed the timeout happens.

    about the code you sent - why have you set the SO_KEEPALIVE option - can you explain a bit about it (from my understanding it just makes the TCP sending keepalive packets after a time (not sure what is this time) when there is no traffic but i am not sure if and/or why it is necessary)

    one more thing - it seems the strerror function does not know the socket error codes (i.e. for the timeout it prints unknown error) - is there an alternative function in NDK to get the string form for the socket's error?

    Thanks
    Guy
  • In reply to Guy Mardiks:

    The SO_KEEPALIVE option was in the example I tweaked. I expect that it was there for testing purposes. The default send time is 2 hours. If there were no timeouts on the recv/send APIs, its useful in making sure things are still alive.

    I don't see an strerror equivalent. I'm pinging one of the NDK engineers.

  • In reply to ToddMullanix:

    We don't have an equivalent API.
  • In reply to ToddMullanix:

    Thanks for your help.

    Guy