This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to support MSG_WAITALL flag for recv() operation

Hi 

We need the recv() be blocking until the full amount of requested data can be returned or the operation was timeout, how to achieve this?

I tried flag MSG_WAITALL but failed to compile with error 'MSG_WAITALL' undeclared;

I also tried flag NRF_MSG_WAITALL but did not work, the recv() also returned the smaller amount of data for first message.

Parents Reply Children
  • Hi

    Sorry I cannot find the answer from your link, which flag should I use, MSG_WAITALL or NRF_MSG_WAITALL?

    To obviate misunderstanding, let me explain more about my question:

    1, My TCP client recv() could be blocking untill timeout if TCP server did not send any data;

    2, Conversely, if TCP server sent a part of client requested data before recv() timeout, the client will return the part of data immediately instead of waiting for the whole requested data untill timeout. This is my issue, we need the recv() waiting untill ether it was timeout or the client received the requested complete data.

    SDK: NCS v1.2

    modem: mfw_nrf9160_1.1.1

  • Siyou said:
    instead of waiting for the whole requested data untill timeout.

     What do you mean by requested data here? With NRF_MSG_WAITALL the recv will be blocking until data has been received or it times out.

  • What do you mean by requested data here?

    ret = recv(sock, data, size, NRF_MSG_WAITALL);

    Let me take my code as example, the requested data is the input parameter size of recv()

    When I set the timeout to 10000(10s), size to 10, the recv() is expected could be blocking until either 10s timeout or it received 10 bytes of data. But the actual result is: if the TCP server sent out only 5 bytes of data within 10s, nRF9160 recv() will return the 5 bytes data instead of blocking until timeout.

    That is, the NRF_MSG_WAITALL did not seem to work.

  • From what I gather, the NRF_MSG_WAITALL flag just means the recv() will block until it receives any data, whether it's 1 byte or 1000 bytes. The size parameter just sets the maximum amount of bytes you can receive in a single recv() call, and has nothing to do with the amount of data it takes for recv() to return. Does that make sense?

  • Hi Hakon,

    I cannot agree with you.

    According to https://pubs.opengroup.org/onlinepubs/9699919799/functions/recv.html

    MSG_WAITALL
    On SOCK_STREAM sockets this requests that the function block until the full amount of data can be returned. 
    

    If your NRF_MSG_WAITALL is the equivalent of MSG_WAITALL, the expected behavior is: block until the full amount of data can be returned, right?

Related