Hello all,

Why the data transfer speed of the OpenSSL client and server is nearly 10 times slower then when using the regular sockets? The code of the standard samples of client and servers are used.

The code for client is:

char host[MAX_PATH];
BIO *out;
char buf[1024*10],*p;
SSL_CTX *ssl_ctx=NULL;
SSL *ssl;
BIO *ssl_bio;
int i,len,off,ret=1;
int chunk_size;
int buf_size = 1024*1024;
int nBioBlockSize;
cout << "Please, enter the server host and port as following host:port (ex: ASUS:443):\n";
cin >> host;
cout << "Set BIO block size (ex: 4096): ";
cin >> nBioBlockSize;
p = new char[buf_size];
srand( (unsigned)time( NULL ) );
for (int j=0; j<buf_size; j++)
{
   p[j] = (char)rand();
}
/* Setup all the global SSL stuff */
OpenSSL_add_ssl_algorithms();
ssl_ctx=SSL_CTX_new(SSLv23_client_method());
/* Lets make a SSL structure */
ssl=SSL_new(ssl_ctx);
SSL_set_connect_state(ssl);
/* Use it inside an SSL BIO */
ssl_bio=BIO_new(BIO_f_ssl());
BIO_set_ssl(ssl_bio,ssl,BIO_CLOSE);
/* Lets use a connect BIO under the SSL BIO */
out=BIO_new(BIO_s_connect());
BIO_set_conn_hostname(out,host);
BIO_set_nbio(out,1);
out=BIO_push(ssl_bio,out);
BIO_set_write_buf_size(out, nBioBlockSize*4);
//BIO_get_write_buf_size(out, nBioBlockSize);
len = buf_size;
cout << "Sending data\n";
for (int k=0; k<300; k++)
{
   // cout << "SENDING AGAIN!\n" << "\n";
   off=0;
   len = buf_size;
   for (;;)
   {
       //cout << "writing\n";
       i=BIO_write(out,&(p[off]),min(len, nBioBlockSize));
       if (i <= 0)
       {
           if (BIO_should_retry(out))
           {
               //cout << "write DELAY\n";
               Sleep(1);
               continue;
           }
           else
           {
               cout << "ERRORORORORORO\n";
               goto err;
           }
       }
       else
       {
           BIO_ctrl(out, BIO_CTRL_FLUSH, 0, NULL);
       }
       off+=i;
       len-=i;
       if (len <= 0)
           break;
   }
}
if (0)
{
   err:
   if (ERR_peek_error() == 0) /* system call error */
   {
           fprintf(stderr,"errno=%d ",errno);
           perror("error");
   }
   else
       ERR_print_errors_fp(stderr);
   }
   BIO_free_all(out);
   if (ssl_ctx != NULL)
       SSL_CTX_free(ssl_ctx);
}
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to