Skip to content

Commit

Permalink
rework the write_blocked() handlers
Browse files Browse the repository at this point in the history
to match the EOF handlers, so I'm more convinced taht they're
correct.
  • Loading branch information
alandekok committed Nov 19, 2024
1 parent 9a22365 commit a491cf4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
8 changes: 3 additions & 5 deletions src/lib/bio/fd.c
Original file line number Diff line number Diff line change
Expand Up @@ -728,12 +728,10 @@ static ssize_t fr_bio_fd_try_connect(fr_bio_fd_t *my)
*/
case EINPROGRESS:
if (!my->info.write_blocked) {
if (my->cb.write_blocked) {
rcode = my->cb.write_blocked((fr_bio_t *) my);
if (rcode < 0) return rcode;
}

my->info.write_blocked = true;

rcode = fr_bio_write_blocked((fr_bio_t *) my);
if (rcode < 0) return rcode;
}

return fr_bio_error(IO_WOULD_BLOCK);
Expand Down
6 changes: 2 additions & 4 deletions src/lib/bio/fd_write.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ if (rcode > 0) {
*/
my->info.write_blocked = true;

if (my->cb.write_blocked) {
error = fr_bio_write_blocked((fr_bio_t *) my);
if (error < 0) return error;
}
error = fr_bio_write_blocked((fr_bio_t *) my);
if (error < 0) return error;

return rcode;
}
Expand Down
14 changes: 7 additions & 7 deletions src/lib/bio/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ static ssize_t fr_bio_mem_read_verify_datagram(fr_bio_t *bio, void *packet_ctx,
*/
static ssize_t fr_bio_mem_write_next(fr_bio_t *bio, void *packet_ctx, void const *buffer, size_t size)
{
int error;
ssize_t rcode;
size_t room, leftover;
fr_bio_mem_t *my = talloc_get_type_abort(bio, fr_bio_mem_t);
Expand Down Expand Up @@ -410,14 +411,13 @@ static ssize_t fr_bio_mem_write_next(fr_bio_t *bio, void *packet_ctx, void const
return rcode;
}

if (my->cb.write_blocked) {
int error;

error = my->cb.write_blocked(bio);
if (error < 0) return error;
/*
* Tell previous BIOs in the chain that they are blocked.
*/
error = fr_bio_write_blocked(bio);
if (error < 0) return error;

fr_assert(error != 0); /* what to do? */
}
fr_assert(error != 0); /* what to do? */

/*
* We had WOULD BLOCK, or wrote partial bytes. Save the data to the memory buffer, and ensure
Expand Down
5 changes: 4 additions & 1 deletion src/lib/bio/retry.c
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,10 @@ static ssize_t fr_bio_retry_write(fr_bio_t *bio, void *packet_ctx, void const *b
my->info.write_blocked = true;
my->all_used = true;

rcode = my->cb.write_blocked(bio);
/*
* Previous BIOs are blocked, but we still try to write retries.
*/
rcode = fr_bio_write_blocked(bio);
if (rcode < 0) return rcode;

return fr_bio_error(IO_WOULD_BLOCK);
Expand Down

0 comments on commit a491cf4

Please sign in to comment.