send_command: get responses using dynamic heap buffer and process OOB
Rather than process one buffer at a time and do partial outputs each
loop on every partial response (sent to us from receive_command()), we
make a buffer on the heap and keep growing it as long as there's still
data coming in the response. So we get the whole message before
attempting to process it.
As before, we go until either the other end closes (as it does at the
end of the transmission), or there's no more data to read (ie, another
read would block). The latter happens when we received the whole
response buffer, but the receiver hasn't yet finished closing the client
socket. Either of these scenarios means we're at the end of the
message.
The reason for separating receipt and disposition is so that processing
of the response buffer's contents becomes independent, out-of-band from
filling the buffer itself. This way, we can make the message-receive
loop into a utility function of its own, and re-use it in
receive_command() so it can be made to process arbitrarily sized
send_command() messages; it's currently limited to a single BUFSZ buffer
and is read one character at a time. Already, we are *sending* the
complete command argument (eg, from "sdorfehs -c"), but it will get
truncated by receive_command() if it exceeds the buffer size on the
other side. (Actually, we try to send the whole thing in a single
write() and will bail the whole WM on failure, which we probably need to
fix as well...)
authored by
jcs.org
5e7ba32f
0c6f4363