mono/mono — pull request #829 by bassamtabbara (2013-12-06 17:37:42+00:00)
Title: Convert blocking operations in HttpWebRequest and SslClientStream to non-blocking

This fixes #15451. More details:
* HttpWebRequest now writes the HTTP request headers asynchronously. This will avoid blocking a thread pool thread until the headers are written.
* SslClientStream was doing the TLS handshake in a blocking manner. Converted the handshake to an async state machine where all operations are done asynchronously.
* The test case identified in #15451 now completes quickly with less than 15 threads created, vs. 100s of threads used before this fix.

Future work if needed:
* I did not convert SslServerStream but the same pattern could be used here.
* SendAlert is still blocking. I thought it was not worth converting it to non-blocking.

I've tested this in our product and it seems to work well under stress. I ran the system nunit tests as well. However, I'm unable to find a unit test suite for SslStream. There are few test tools but in Mono.Security/Test but I don't see actual test cases. Please advise.