Unix Stream socket -- "send()" for large amount of data



I'm working on an application where one thread ("producer")
will be adding data to a buffer and another ("consumer")
will be sending it to a stream socket via "send()" as fast
as the socket will take it.

Is it better for the consumer to do a single "send()"
call each time with all the (un-consumed) data in the
buffer?

Or is it better to pass no more than some
"max_send_size" bytes with each call?
(If the system buffer has more than "max_send_size"
bytes available, this would mean more calls to
send().)

From the point of view of my application, it doesn't
really make a difference, except that a single "send()"
call with everything is somewhat simpler to code.
So if there's not much advantage to sending smaller chunks,
I'd go with the "send everything" approach.

(In either case, of course, I will use the value returned
by "send()" to tell how many bytes were actually
sent.)
.



Relevant Pages

  • Re: CSocket problem
    ... > I'm having a problem with a byte stream socket connection. ... the receive buffer sometimes gets full. ... a stream socket does not throw away bytes. ... caused by sender code that ignores the rules. ...
    (microsoft.public.vc.mfc)
  • Re: Error in SEND(2) man page ?
    ... This tells me that if doing a sendon a tcp non-blocking socket whose send buffer is full, the call should return with -1 and errno=EAGAIN. ... But running a trivial test app, sendwill indicate that is sent some but not all of the data buffer when the socket's send buffer is full. ... socket, as a stream socket has no real concept of "messages". ...
    (Linux-Kernel)
  • Re: partial receive in socket recv() issue for large response
    ... so you should be able to recieve as much as ... the current value of SO_RCVBUF (see setsockopt) in a single call to recv ... with a stream socket. ... You will never receive such buffer at one read, ...
    (microsoft.public.win32.programmer.networks)
  • Re: Producer-Consumer problem, but the producer updates the old buffers.
    ... Producer fills buffer #1, then fills ... The consumer consumes one buffer a time, ... While it is reading buffer #1, the producer is ready to fill ... 1: prepare buffer msg ...
    (comp.programming.threads)
  • Re: Producer-Consumer problem, but the producer updates the old buffers.
    ... Producer fills buffer #1, then fills ... The consumer consumes one buffer a time, ... While it is reading buffer #1, the producer is ready to fill ... SEMC is a posix semaphore to signal putting of msg to waiter ...
    (comp.programming.threads)