mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-04 04:52:47 -05:00
Macroise the cumbersome read idioms in the BPPs.
Now the three 'proper' BPPs each have a BPP_READ() macro that wraps up the fiddly combination of crMaybeWaitUntilV and bufchainery they use to read a fixed-length amount of input data. The sshverstring 'BPP' doesn't read fixed-length data in quite the same way, but it has a similar BPP_WAITFOR macro. No functional change. Mostly this is just a cleanup to make the code more legible, but also, the new macros will be a good place to centralise anything else that needs doing on every read, such as EOF checking.
This commit is contained in:
@ -197,6 +197,12 @@ static void ssh_verstring_send(struct ssh_verstring_state *s)
|
||||
vs_logevent(("We claim version: %s", s->our_vstring));
|
||||
}
|
||||
|
||||
#define BPP_WAITFOR(minlen) do \
|
||||
{ \
|
||||
crMaybeWaitUntilV( \
|
||||
bufchain_size(s->bpp.in_raw) >= (minlen)); \
|
||||
} while (0)
|
||||
|
||||
void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
|
||||
{
|
||||
struct ssh_verstring_state *s =
|
||||
@ -221,8 +227,7 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
|
||||
* Every time round this loop, we're at the start of a new
|
||||
* line, so look for the prefix.
|
||||
*/
|
||||
crMaybeWaitUntilV(bufchain_size(s->bpp.in_raw) >=
|
||||
s->prefix_wanted.len);
|
||||
BPP_WAITFOR(s->prefix_wanted.len);
|
||||
bufchain_fetch(s->bpp.in_raw, s->prefix, s->prefix_wanted.len);
|
||||
if (!memcmp(s->prefix, s->prefix_wanted.ptr, s->prefix_wanted.len)) {
|
||||
bufchain_consume(s->bpp.in_raw, s->prefix_wanted.len);
|
||||
@ -237,7 +242,9 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
|
||||
void *data;
|
||||
char *nl;
|
||||
|
||||
crMaybeWaitUntilV(bufchain_size(s->bpp.in_raw) > 0);
|
||||
/* Wait to receive at least 1 byte, but then consume more
|
||||
* than that if it's there. */
|
||||
BPP_WAITFOR(1);
|
||||
bufchain_prefix(s->bpp.in_raw, &data, &len);
|
||||
if ((nl = memchr(data, '\012', len)) != NULL) {
|
||||
bufchain_consume(s->bpp.in_raw, nl - (char *)data + 1);
|
||||
|
Reference in New Issue
Block a user