Richard (and others),
Here goes cut-down version of my program, that still fails.
Let me know what did i do wrong and what i maybe missing.
It shows only SSL-related calls, I deleted all error checking and unrelated
stuff.
Program does the following:
- main() spawns 200 threads.
- each threads connect to SSL-able server and send piece of data.
- each thread  then waits for a reply (via select() and ioctlsocket())
      and then disconnect.
- main() waits until all threads will terminate, cleanup and exit.



HANDLE         g_SSL_lock_cs [CRYPTO_NUM_LOCKS];
main()
{

    // Initialization code
    for (i=0; i<CRYPTO_NUM_LOCKS; i++)
       g_SSL_lock_cs [i] = CreateMutex (NULL, FALSE, NULL);

    CRYPTO_set_locking_callback (SSL_win32_locking_callback);

    ....spawning multiple threads. Each thread does:

    // This is each thread's code..
       {
       // SSL initialization code.
       SSLeay_add_ssl_algorithms  ();
       pSslMethod = SSLv2_client_method ();
       SSL_load_error_strings     ();
       pSslContext = SSL_CTX_new  (pSslMethod);  // NULL:error


       sSocket = socket (AF_INET, SOCK_STREAM, 0);
       bind    (sSocket, ...);
       connect (sSocket, ...); // connect to server.

       pSsl = SSL_new (pSslContext);
       SSL_set_fd     (pSsl, sSocket);

       iRetCode = SSL_connect (pSsl);   // Do connection.

       // Collect and printf some info...
          {
          pServerCertif = SSL_get_peer_certificate (pSsl);
          pStr = X509_NAME_oneline (X509_get_subject_name (pServerCertif), 
0, 0);
          ...
          Free (pStr);

          pStr = X509_NAME_oneline (X509_get_issuer_name  (pServerCertif), 
0, 0);
          ...
          Free (pStr);

          X509_free (pServerCertif);
          }

       // Send data to server.
       SSL_write (pSsl, pTransactData, iTransactDataSize);

       // Receive reply from server.
       SSL_read  (pSsl, pBuffer, iSize);

       // Cleanup and exit.
       if (pSsl) SSL_shutdown (pSsl);

       iRetCode = shutdown (sSocket, SD_BOTH);
       closesocket (sSocket);
       if (pSsl)         SSL_free       (pSsl);
       if (pSslContext)  SSL_CTX_free   (pSslContext);
       }
    // ==============


    .......main() is waiting for all threads to exit......


    // Now main() does cleanup...
    CRYPTO_set_locking_callback (NULL);

    for (i=0; i<CRYPTO_NUM_LOCKS; i++)
       CloseHandle (g_SSL_lock_cs [i]);

    return;
}  // end of main()


// And this is locking callback.
VOID  SSL_win32_locking_callback (int mode, int type, const char *file, int 
line)
{
    if (mode & CRYPTO_LOCK)
       WaitForSingleObject (g_SSL_lock_cs[type], INFINITE);
    else
       ReleaseMutex        (g_SSL_lock_cs[type]);
}

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

Reply via email to