Hello,
This is a new feature proposal for BIO_f_buffer.
The current implementation allows the user to write some data to the
buffer, and then flush it to the underlying BIO, using the BIO_flush
call.
A similar mechanism would be helpful for the receiving side: fill the
buffer with some data from the underlying BIO, and then the user may
read data from the buffer.
This patch introduces a new call, BIO_fill(b,n), which attempts to fill
buffer b with n bytes.
Return value: number of bytes read from the next BIO.

Cheers,

       Yair



diff -ur C:\openssl_dist\crypto\bio\bf_buff.c
C:\openssl\crypto\bio\bf_buff.c
--- C:\openssl_dist\crypto\bio\bf_buff.c Wed Jun 11 21:43:50 2003
+++ C:\openssl\crypto\bio\bf_buff.c Tue Mar 22 11:33:37 2005
@@ -509,3 +509,35 @@
  return(buffer_write(b,str,strlen(str)));
  }
 
+int BIO_fill(BIO *b, int pendingbytes)
+{
+ int i,num=0;
+ BIO_F_BUFFER_CTX *ctx;
+
+ if (b==NULL || pendingbytes==0) return(0);
+ ctx=(BIO_F_BUFFER_CTX *)b->ptr;
+
+ if (ctx->ibuf_off > (ctx->ibuf_size/2))
+ {
+  memcpy(ctx->ibuf, ctx->ibuf + ctx->ibuf_off, ctx->ibuf_len);
+  ctx->ibuf_off = 0;
+ }
+
+ if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
+ while ((num<pendingbytes) && (ctx->ibuf_size - ctx->ibuf_len -
ctx->ibuf_off)>0 )
+ {
+  BIO_clear_retry_flags(b);
+
+  i=BIO_read(b->next_bio, ctx->ibuf+ctx->ibuf_off+ctx->ibuf_len,
ctx->ibuf_size-ctx->ibuf_len-ctx->ibuf_off);
+  if (i <= 0)
+  {
+   BIO_copy_next_retry(b);
+   if (i < 0) return((num > 0)?num:i);
+   if (i == 0) return(num);
+  }
+  num += i;
+  ctx->ibuf_len += i;
+ }
+ return num;
+}
+
diff -ur C:\openssl_dist\include\openssl\bio.h
C:\openssl\include\openssl\bio.h
--- C:\openssl_dist\include\openssl\bio.h Wed Mar 24 14:35:20 2004
+++ C:\openssl\include\openssl\bio.h Tue Mar 22 11:34:37 2005
@@ -486,6 +486,8 @@
 size_t BIO_ctrl_get_write_guarantee(BIO *b);
 size_t BIO_ctrl_get_read_request(BIO *b);
 int BIO_ctrl_reset_read_request(BIO *b);
+int BIO_fill(BIO *b, int pendingbytes);
+
 
 /* These two aren't currently implemented */
 /* int BIO_get_ex_num(BIO *bio); */


______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       openssl-dev@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to