mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-16 02:27:32 -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:
@ -48,6 +48,12 @@ static void ssh2_bare_bpp_free(BinaryPacketProtocol *bpp)
|
||||
sfree(s);
|
||||
}
|
||||
|
||||
#define BPP_READ(ptr, len) do \
|
||||
{ \
|
||||
crMaybeWaitUntilV(bufchain_try_fetch_consume( \
|
||||
s->bpp.in_raw, ptr, len)); \
|
||||
} while (0)
|
||||
|
||||
static void ssh2_bare_bpp_handle_input(BinaryPacketProtocol *bpp)
|
||||
{
|
||||
struct ssh2_bare_bpp_state *s =
|
||||
@ -59,8 +65,7 @@ static void ssh2_bare_bpp_handle_input(BinaryPacketProtocol *bpp)
|
||||
/* Read the length field. */
|
||||
{
|
||||
unsigned char lenbuf[4];
|
||||
crMaybeWaitUntilV(bufchain_try_fetch_consume(
|
||||
s->bpp.in_raw, lenbuf, 4));
|
||||
BPP_READ(lenbuf, 4);
|
||||
s->packetlen = toint(GET_32BIT_MSB_FIRST(lenbuf));
|
||||
}
|
||||
|
||||
@ -83,8 +88,7 @@ static void ssh2_bare_bpp_handle_input(BinaryPacketProtocol *bpp)
|
||||
/*
|
||||
* Read the remainder of the packet.
|
||||
*/
|
||||
crMaybeWaitUntilV(bufchain_try_fetch_consume(
|
||||
s->bpp.in_raw, s->data, s->packetlen));
|
||||
BPP_READ(s->data, s->packetlen);
|
||||
|
||||
/*
|
||||
* The data we just read is precisely the initial type byte
|
||||
|
Reference in New Issue
Block a user