Setting sync parameter

The sync parameter doesn't exactly do what you might expect. As you have seen messages to be sent are buffered in an output queue. The sync parameter specifies the number of messages held in this buffer before anything is written.

Note that it doesn't write all buffered messages in one single chunk, it writes each distinct message with a single write() system call.