So, I was using nc (on FreeBSD) to image an HD over the network and
it was consuming much cpu.  It turns out that the buffer used by netcat
is only 2k in size, though the buffer on the stack is 16k.

This patch increased plan to use the entire buffer:
--- netcat.obsd.c.orig  2014-05-19 18:25:23.000000000 -0700
+++ netcat.obsd.c       2014-06-09 20:07:31.000000000 -0700
@@ -738,7 +738,7 @@
        int lfd = fileno(stdout);
        int plen;
 
-       plen = 2048;
+       plen = sizeof buf;
 
        /* Setup Network FD */
        pfd[0].fd = nfd;

A better patch is probably the following which also increases the size
of the buffer to at least 64k:
--- netcat.obsd.c.orig  2014-05-19 18:25:23.000000000 -0700
+++ netcat.obsd.c       2014-06-09 20:11:56.000000000 -0700
@@ -733,12 +733,12 @@
 readwrite(int nfd)
 {
        struct pollfd pfd[2];
-       unsigned char buf[16384];
+       unsigned char buf[64*1024];
        int n, wfd = fileno(stdin);
        int lfd = fileno(stdout);
        int plen;
 
-       plen = 2048;
+       plen = sizeof buf;
 
        /* Setup Network FD */
        pfd[0].fd = nfd;

I would like to apply the following patch to FreeBSD, but it'd be nice
to keep these changes to a minimum between the two.

Thanks.

-- 
  John-Mark Gurney                              Voice: +1 415 225 5579

     "All that I will do, has been done, All that I have, has not."

Reply via email to