Dear Friends

How to use properly SSL_read/SSL_write with select?
my default code with use standart api, make an call to select before call to recv/send api


my code to read is like this


to Read i use
  do
  {
     if( iPos == iAllocated - 1 )
     {
        iAllocated += iBufferSize;
        Buffer = ( char * ) hb_xrealloc( Buffer, iAllocated );
     }

     if( hb_selectReadSocket( Socket ) )
     {
        iLen = SSL_read( Socket->pSSL, &cChar, 1 );
        iRet = SSL_get_error( Socket->pSSL, iLen) ;
        Socket->errorCode = iRet;
     }
     else
     {
        iTimeElapsed += Socket->timeout;


        /* this signals timeout */
        iLen = -2;
     }

     if( iLen > 0 )
     {
        /* verify endsequence recognition automata status */
        if( cChar == szPattern[ ulPatPos ] )
        {
           ulPatPos ++;
           if( ! szPattern[ ulPatPos ] )
           {
              break;
           }
        }
        else
        {
           ulPatPos = 0;
        }

        Buffer[ iPos++ ] = cChar;
     }
     else
     {
        break;
     }
  }
  while( iMax == 0 || iPos < iMax );

static int hb_selectReadSocket( HB_SSL_SOCKET_STRUCT *Socket )
{
  fd_set set;
  struct timeval tv;

  FD_ZERO( &set );
  FD_SET(Socket->com, &set);

  if( Socket->timeout == -1 )
  {
     if( select( Socket->com + 1, &set, NULL, NULL, NULL ) < 0 )
        return 0;
  }
  else
  {
     tv.tv_sec = Socket->timeout/ 1000;
     tv.tv_usec = (Socket->timeout % 1000) * 1000;
     if( select( Socket->com + 1, &set, NULL, NULL, &tv ) < 0 )
        return 0;
  }

  return FD_ISSET( Socket->com, &set );
}

So , how can i change so can work correctly with openssl SSL_read/SSL_write api

Thanks in advance

Regards
Luiz Rafael



______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    openssl-users@openssl.org
Automated List Manager                           majord...@openssl.org

Reply via email to