]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clarifications
authorAlan T. DeKok <aland@freeradius.org>
Fri, 24 May 2024 14:27:26 +0000 (10:27 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 3 Jun 2024 12:43:45 +0000 (08:43 -0400)
and glue in write blocked / resume

src/lib/bio/mem.c

index 67ab2f674b8237c2c72b8c6db87d0c48dc9672f2..8ecdbd197f7f6f6e3e05729179a787b2e19fa8ca 100644 (file)
@@ -379,15 +379,24 @@ static ssize_t fr_bio_mem_write_next(fr_bio_t *bio, void *packet_ctx, void const
        }
 
        /*
-        *      We were flushing the buffer, return however much data we managed to write.
+        *      We were flushing the BIO, return however much data we managed to write.
         *
-        *      Note that flushes can never block.
+        *      Note that flushes should never block.
         */
        if (!buffer) {
                fr_assert(rcode != fr_bio_error(IO_WOULD_BLOCK));
                return rcode;
        }
 
+       if (my->cb.write_blocked) {
+               int error;
+
+               error = my->cb.write_blocked(bio);
+               if (error < 0) return error;
+
+               fr_assert(error != 0); /* what to do? */
+       }
+
        /*
         *      We had WOULD BLOCK, or wrote partial bytes.  Save the data to the memory buffer, and ensure
         *      that future writes are ordered.  i.e. they write to the memory buffer before writing to the
@@ -833,6 +842,10 @@ int fr_bio_mem_set_verify(fr_bio_t *bio, fr_bio_verify_t verify, bool datagram)
        return 0;
 }
 
+/*
+ *     There's no fr_bio_mem_write_blocked()
+ */
+
 /** See if we can resume writes to the memory bio.
  *
  *  Note that there is no equivalent fr_bio_mem_write_blocked(), as that function wouldn't do anything.
@@ -847,10 +860,15 @@ int fr_bio_mem_write_resume(fr_bio_t *bio)
 
        if (bio->write != fr_bio_mem_write_buffer) return 1;
 
+       /*
+        *      Flush the buffer, and then reset the write routine if we were successful.
+        */
        rcode = fr_bio_mem_write_flush(my, SIZE_MAX);
        if (rcode <= 0) return rcode;
 
        if (fr_bio_buf_used(&my->write_buffer) > 0) return 0;
 
-       return 1;
+       if (!my->cb.write_resume) return 1;
+
+       return my->cb.write_resume(bio);
 }