Check for truncation when converting buffer size from size_t to openssl's int argument.
Try to fix possible thread-safety issues in SSL wrapper.