Add a pointer to a paper (is the algorithm in section 4.2 the
[oweals/openssl.git] / crypto / bio / bss_bio.c
index be28472d346b35ff51ccb8890353b128a40518c9..272d3c921b98423693ca5a931f423d00f9602189 100644 (file)
@@ -250,7 +250,7 @@ static size_t bio_nread(BIO *bio, char **buf, size_t num)
        available = bio_nread0(bio, buf);
        if (num > available)
                num = available;
-       if (num <= 0)
+       if (num == 0)
                return num;
 
        b = bio->ptr;
@@ -400,14 +400,16 @@ static size_t bio_nwrite0(BIO *bio, char **buf)
 
 static size_t bio_nwrite(BIO *bio, char **buf, size_t num)
        {
-       struct bio_bio_st *b=bio->ptr;
+       struct bio_bio_st *b;
        size_t space;
 
        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);
 
@@ -491,6 +493,15 @@ static long bio_ctrl(BIO *bio, int cmd, long num, void *ptr)
                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;
@@ -748,6 +759,11 @@ size_t BIO_ctrl_get_read_request(BIO *bio)
        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.)