This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

NDK send function behavior

Hi

I am using NDK send function to send big (130k)  buffers over TCP/IP protocol

I use socket in blocking mode.

Can I be sure that the send function will be blocking until all the 130 k will be sent , or I need to check  the number of  sent bytes and implement the send in loop?

 

I mean, can I use the send in this way:

ret = send(hSocket, Buffer, Sze, 0);

Or , I must to implement this loop:

    int ret;   

    while(Size > 0)

   {

                                ret = send(stcpResults, Buffer, Size, 0);

 

                                if (ret < 0)

                                {

                                                break;

                                }

                                Size = Size - ret;

                                Buffer = Buffer + ret;

  }

  • Genady Kagan,

    Usually the socket buffer size will be affect the TCP send size.
    So that this will determine size of data can be sent in one burst.
    If you will get the error as per below or some other error, then you need to change your code accordingly.
    #define EMSGSIZE        40      // Message too long

    You can find the error through fdError();

    You can use without while part of the code, as per your first option.
    If you are getting the error, in this case you can implement the loop for TCP send.
    And also you can try with circular buffer for TCP send.