ellzey/libevhtp — pull request #81 by StunMan (2013-03-08 00:58:39+00:00)
Title: client ssl connection added.

I added the functionality to establish a ssl-connection as client.
This requires a SSL_CTX and must be set by the user.

There might be a better way to integrate it in the library but this should do right now.

NOTE:
It might be wise to add the workaround mentioned at http://www.wangafu.net/~nickm/libevent-book/Ref6a_advanced_bufferevents.html

SSL *ctx = bufferevent_openssl_get_ssl(bev);

/*
* SSL_RECEIVED_SHUTDOWN tells SSL_shutdown to act as if we had already
* received a close notify from the other end. SSL_shutdown will then
* send the final close notify in reply. The other end will receive the
* close notify and send theirs. By this time, we will have already
* closed the socket and the other end's real close notify will never be
* received. In effect, both sides will think that they have completed a
* clean shutdown and keep their sessions valid. This strategy will fail
* if the socket is not ready for writing, in which case this hack will
* lead to an unclean shutdown and lost session on the other end.
*/
SSL_set_shutdown(ctx, SSL_RECEIVED_SHUTDOWN);
SSL_shutdown(ctx);
bufferevent_free(bev);