We were calculating the wrong number of words per byte in the first
place, and then passing the number of *words* to malloc, which expects
the number of *bytes*.
Fix both errors
Now that we're using NODELAY, we should definitely use cork around
writes to the upstream server. This prevents each partial write()
from being its own packet, which would be terrible if it actually
happened with any regularity (we'd mostly see it when the kernel
is stressed, and write() is progressing a few bytes at a time as
a result)
Nagle doesn't actually affect us too badly here, as we don't write
the header and then the data in two separate calls under normal
circumstances, which is the pathological case, but we should have
NODELAY on, regardless
This commit beefs up the Makefile to do the build, instead of the
Rakefile.
It also removes from the Rakefile the dependency on rake_utils, which
should mean it's ok to build in a schroot.
The files are reorganised to make the Makefile rules more tractable,
although the reorganisation reveals a problem with our current code
organisation.
The problem is that the proxy-specific code transitively depends on the
server code via flexnbd.h, which has a circular dependency on the server
and client structs. This should be broken in a future commit by
separating the flexnbd struct into a shared config struct and
server-specific parts, so that the server code can be moved into
src/server to more accurately show the functional dependencies.
This is a bit tricky, but calling shutdown() on a socket in a signal
handler is safe, and (at least in linux) appears to cause any read()
or write() calls blocked on that socket to return, even with SA_RESTART.
I'm not confident enough about the rest of flexnbd's syscall error
handling to turn SA_RESTART off for this signal...