BIO_METHOD eorAwareBioMethod;
-__attribute__((__constructor__))
-void initEorBioMethod(void) {
+void* initEorBioMethod(void) {
memcpy(&eorAwareBioMethod, BIO_s_socket(), sizeof(eorAwareBioMethod));
// override the bwrite method for MSG_EOR support
eorAwareBioMethod.bwrite = AsyncSSLSocket::eorAwareBioWrite;
// set here. openssl code seems to be checking ".type == BIO_TYPE_SOCKET" and
// then have specific handlings. The eorAwareBioWrite should be compatible
// with the one in openssl.
+
+ // Return something here to enable AsyncSSLSocket to call this method using
+ // a function-scoped static.
+ return nullptr;
}
} // anonymous namespace
AsyncSocket(evb),
ctx_(ctx),
handshakeTimeout_(this, evb) {
- setup_SSL_CTX(ctx_->getSSLCtx());
+ init();
}
/**
server_(server),
ctx_(ctx),
handshakeTimeout_(this, evb) {
- setup_SSL_CTX(ctx_->getSSLCtx());
+ init();
if (server) {
SSL_CTX_set_info_callback(ctx_->getSSLCtx(),
AsyncSSLSocket::sslInfoCallback);
AsyncSSLSocket::AsyncSSLSocket(const shared_ptr<SSLContext> &ctx,
EventBase* evb,
const std::string& serverName) :
- AsyncSocket(evb),
- ctx_(ctx),
- handshakeTimeout_(this, evb),
- tlsextHostname_(serverName) {
- setup_SSL_CTX(ctx_->getSSLCtx());
+ AsyncSSLSocket(ctx, evb) {
+ tlsextHostname_ = serverName;
}
/**
AsyncSSLSocket::AsyncSSLSocket(const shared_ptr<SSLContext>& ctx,
EventBase* evb, int fd,
const std::string& serverName) :
- AsyncSocket(evb, fd),
- ctx_(ctx),
- handshakeTimeout_(this, evb),
- tlsextHostname_(serverName) {
- setup_SSL_CTX(ctx_->getSSLCtx());
+ AsyncSSLSocket(ctx, evb, fd, false) {
+ tlsextHostname_ = serverName;
}
#endif
<< sslState_ << ", events=" << eventFlags_ << ")";
}
+void AsyncSSLSocket::init() {
+ // Do this here to ensure we initialize this once before any use of
+ // AsyncSSLSocket instances and not as part of library load.
+ static const auto eorAwareBioMethodInitializer = initEorBioMethod();
+ setup_SSL_CTX(ctx_->getSSLCtx());
+}
+
void AsyncSSLSocket::closeNow() {
// Close the SSL connection.
if (ssl_ != nullptr && fd_ != -1) {