AnsweredAssumed Answered

SOCK_STREAM_recv() bug drops data on receive timeout

Question asked by Bowe Neuenschwander on Dec 30, 2015
Latest reply on Jan 20, 2016 by Carlos_Musich

We are using MQX for KSDK 1.3.  We have found that the socket recv() function will drop some data if a receive timeout occurs.  We found this when trying to transferring a relatively large file (~500KB).  I believe this is the relevant code in SOCK_STREAM_recv():


  error = RTCSCMD_issue(parms, TCP_Process_receive);
  if (error) {
    RTCS_setsockerror(sock, error);
    /* Start CR 2340 */
    /* If data was copied to the userbuf, but not all that
       the recv() asked for, and a timer was started that has
       now timed out, we need to return with the count, and not
       RTCS_ERROR */
    if (error == RTCSERR_TCP_TIMED_OUT) {
       int n;
       n = parms.TCB_PTR->rcvnxt - parms.TCB_PTR->rcvbufseq;
       RTCS_EXIT2(RECV, RTCS_OK, n);


When a receive timeout occurs (detected by line 10), it is supposed to return how much data it partially filled the buffer with.  However, we are seeing it return 0, even though there is data in the buffer (we added a memset to zero out the buffer before calling the socket recv function).  I think that line 13 is the culprit (it seems to always set n to 0), but I am not sure what it should be to fix the issue, because I do not completely understand the TCB (Transmission Control Block) and how they are used.  I am guessing this line used to work with a previous version of RTCS, and was never updated?