title: How to make non-blocking OpenSSL connection?
body: <p>I want make a non-blocking OpenSSL connection</p>
  
  <p>On this connection - if no data available for read, then entire program execution flow make stop on SSL_read(). I want so that if no data available for read it give me the returns values like WANT_READ and i know no more data available. </p>
  
  <pre><code>char *sslRead (connection *c)
  {
  const int readSize = 1024;
  char *rc = NULL;
  int r;
  int received, count = 0;
  int ReallocSize = 0;
  char buffer[1024];
  
  if (c)
  {
      while (1)
      {
          if (!rc)
          {
              rc = malloc (readSize + 1); 
              if (rc == NULL)
                  printf("the major error have happen. leave program\n");
          }
          else
          {
              ReallocSize = (count + 1) * (readSize + 1);
              rc = realloc (rc, ReallocSize);
          }
  
          // if i have no data available for read after reading data, 
          // this call will not return anything and wait for more data
  
          // i want change this non blocking connections
          received = SSL_read (c-&gt;sslHandle, buffer, readSize);
  
          buffer[received] = '\0';
  
  
          if (received &lt;= 0)
          {
              printf(" received equal to or less than 0\n");
              switch (SSL_get_error(c-&gt;sslHandle, r))
              {
              case SSL_ERROR_NONE:
                  printf("SSL_ERROR_NONE\n");
                  break;   
              case SSL_ERROR_ZERO_RETURN: 
                  printf("SSL_ERROR_ZERO_RETURN\n");
                  break;   
              case SSL_ERROR_WANT_READ: 
                  printf("SSL_ERROR_WANT_READ\n");
                  break;
              default:
                  printf("error happens %i\n", r); 
              }     
              break;
          }
  
          count++;
      }
  }
  return rc;
  </code></pre>
  
  <p>}</p>
  
  <p>here is how i make connection</p>
  
  <pre><code>connection *sslConnect (void)
  {
     connection *c;
  
     c = malloc (sizeof (connection));
     c-&gt;sslHandle = NULL;
     c-&gt;sslContext = NULL;
  
     c-&gt;socket = tcpConnect ();
     if (c-&gt;socket)
     {
      // Register the error strings for libcrypto &amp; libssl
      SSL_load_error_strings ();
      // Register the available ciphers and digests
      SSL_library_init ();
  
      // New context saying we are a client, and using SSL 2 or 3
      c-&gt;sslContext = SSL_CTX_new (SSLv23_client_method ());
      if (c-&gt;sslContext == NULL)
      ERR_print_errors_fp (stderr);
  
      // Create an SSL struct for the connection
      c-&gt;sslHandle = SSL_new (c-&gt;sslContext);
      if (c-&gt;sslHandle == NULL)
      ERR_print_errors_fp (stderr);
  
      // Connect the SSL struct to our connection
      if (!SSL_set_fd (c-&gt;sslHandle, c-&gt;socket))
      ERR_print_errors_fp (stderr);
  
      // Initiate SSL handshake
      if (SSL_connect (c-&gt;sslHandle) != 1)
      ERR_print_errors_fp (stderr);
      }
      else
      {
       perror ("Connect failed");
      }
  
      return c;
  }
  </code></pre>
  
  <p>thanks you very much. </p>