martylamb/nailgun — pull request #38 by andrewgaul (2014-06-25 05:31:50+00:00)
Title: Buffer underlying OutputStream in NGOutputStream

Previously every call to NGOutputStream.write required six system
calls:

19464 sendto(8, "\0", 1, 0, NULL, 0) = 1
19464 sendto(8, "\0", 1, 0, NULL, 0) = 1
19464 sendto(8, "\0", 1, 0, NULL, 0) = 1
19464 sendto(8, "\t", 1, 0, NULL, 0) = 1
19464 sendto(8, "1", 1, 0, NULL, 0) = 1
19464 sendto(8, "mymessage", 9, 0, NULL, 0) = 9

With this commit write only requires one system call:

19089 sendto(8, "\0\0\0\t1mymessage", 14, 0, NULL, 0) = 14

Note that all calls to write only buffer the current message and call
flush on the underlying OutputStream before returning.