* (example usage: bio_nread0(), read from buffer, bio_nread()
* or just bio_nread(), read from buffer)
*/
-/* WARNING: The non-copying interface is totally untested as of yet --
- * I wrote it, but have not yet read it; and surely it still is full
- * of bugs. */
+/* WARNING: The non-copying interface is largely untested as of yet
+ * and may contain bugs. */
static size_t bio_nread0(BIO *bio, char **buf)
{
struct bio_bio_st *b, *peer_b;
char dummy;
/* avoid code duplication -- nothing available for reading */
- return bio_read(bio, &dummy, num); /* returns 0 or -1 */
+ return bio_read(bio, &dummy, 1); /* returns 0 or -1 */
}
num = peer_b->len;
available = bio_nread0(bio, buf);
if (num > available)
num = available;
- if (num <= 0)
+ if (num == 0)
return num;
b = bio->ptr;
space = bio_nwrite0(bio, buf);
if (num > space)
num = space;
- if (num <= 0)
+ if (num == 0)
return num;
+ b = bio->ptr;
+ assert(b != NULL);
b->len += num;
assert(b->len <= b->size);
ret = (long) b->request;
break;
+ case BIO_C_RESET_READ_REQUEST:
+ /* Reset request. (Can be useful after read attempts
+ * at the other side that are meant to be non-blocking,
+ * e.g. when probing SSL_read to see if any data is
+ * available.) */
+ b->request = 0;
+ ret = 1;
+ break;
+
case BIO_C_SHUTDOWN_WR:
/* similar to shutdown(..., SHUT_WR) */
b->closed = 1;
return BIO_ctrl(bio, BIO_C_GET_READ_REQUEST, 0, NULL);
}
+int BIO_ctrl_reset_read_request(BIO *bio)
+ {
+ return (BIO_ctrl(bio, BIO_C_RESET_READ_REQUEST, 0, NULL) != 0);
+ }
+
/* BIO_nread0/nread/nwrite0/nwrite are availabe only for BIO pairs for now
* (conceivably some other BIOs could allow non-copying reads and writes too.)