1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

Add some more bufchain_try_* functions.

We already had bufchain_try_fetch_consume; now we also have
bufchain_try_fetch (for when you want to wait until that much data is
available but then not commit to removing it), and
bufchain_try_consume (so you can conveniently ignore a certain amount
of incoming data).
This commit is contained in:
Simon Tatham 2021-11-19 10:21:40 +00:00
parent 4e93a2c1b8
commit efee4e0eae
2 changed files with 22 additions and 0 deletions

2
misc.h
View File

@ -123,6 +123,8 @@ ptrlen bufchain_prefix(bufchain *ch);
void bufchain_consume(bufchain *ch, size_t len); void bufchain_consume(bufchain *ch, size_t len);
void bufchain_fetch(bufchain *ch, void *data, size_t len); void bufchain_fetch(bufchain *ch, void *data, size_t len);
void bufchain_fetch_consume(bufchain *ch, void *data, size_t len); void bufchain_fetch_consume(bufchain *ch, void *data, size_t len);
bool bufchain_try_consume(bufchain *ch, size_t len);
bool bufchain_try_fetch(bufchain *ch, void *data, size_t len);
bool bufchain_try_fetch_consume(bufchain *ch, void *data, size_t len); bool bufchain_try_fetch_consume(bufchain *ch, void *data, size_t len);
size_t bufchain_fetch_consume_up_to(bufchain *ch, void *data, size_t len); size_t bufchain_fetch_consume_up_to(bufchain *ch, void *data, size_t len);
void bufchain_set_callback_inner( void bufchain_set_callback_inner(

View File

@ -153,6 +153,26 @@ void bufchain_fetch_consume(bufchain *ch, void *data, size_t len)
bufchain_consume(ch, len); bufchain_consume(ch, len);
} }
bool bufchain_try_fetch(bufchain *ch, void *data, size_t len)
{
if (ch->buffersize >= len) {
bufchain_fetch(ch, data, len);
return true;
} else {
return false;
}
}
bool bufchain_try_consume(bufchain *ch, size_t len)
{
if (ch->buffersize >= len) {
bufchain_consume(ch, len);
return true;
} else {
return false;
}
}
bool bufchain_try_fetch_consume(bufchain *ch, void *data, size_t len) bool bufchain_try_fetch_consume(bufchain *ch, void *data, size_t len)
{ {
if (ch->buffersize >= len) { if (ch->buffersize >= len) {