unix sockets: how to send really big data with one "send" call? -


I am using Unix scotch to transfer data (SOCK_STREAM mode)

First of all, more than 100k characters, I send the length of a string - this is the size (intestine) bytes. I

  Length = Stellen (SD) (SD, Long, Size)  

Then I send the full string

 Bytesend = Send (SD, S, Length)  
< P> but in Area to wonder "Baitsend" short "length".

Note that this works fine when I do not send large wires, that there may be some limitations for the "Send" system call which I was missing ...

send system call is considered fast because this program Other things can be useful work in Of course you do not want to wait for the data to be sent and to send a reply to another computer - which will come with a terrific throughput.

Therefore, all the send actually does have some data queues for sending and returning the program. The kernel can make the entire message copy in kernel memory, but it will consume many kernel memory (not good).

Instead, the program is responsible for retaking the kernel, just sending the remaining data as the message is just as reasonable as the queue.

In your case, use a loop to send data sent for the first time.

  while (length> gt; 0) {send bytescent = (SD, S, length); Break if (Bytesent == 0); // The socket may possibly close if (bytecent & lt; 0) breaks; // handle the proper errors by s + = bytesSent; Length - = bytecent; }  

You will need to do the same thing at the end.


Comments

Popular posts from this blog

asp.net - Javascript/DOM Why is does my form not support submit()? -

sockets - Delphi: TTcpServer, connection reset when reading -

javascript - Classic ASP "ExecuteGlobal" statement acting differently on two servers -