Commit 7e7a7df7 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 6

Add a pair of util functions for getting and setting the BIO fd

Summary: Because we need to translate them between sockets and file descriptors when we're on Windows.

Reviewed By: yfeldblum

Differential Revision: D3724802

fbshipit-source-id: 07fff6e1bec7b9b90e0d39fd98441466a746b7f7
parent 79d7f0f5
...@@ -699,7 +699,7 @@ bool AsyncSSLSocket::setupSSLBio() { ...@@ -699,7 +699,7 @@ bool AsyncSSLSocket::setupSSLBio() {
} }
OpenSSLUtils::setBioAppData(wb, this); OpenSSLUtils::setBioAppData(wb, this);
BIO_set_fd(wb, fd_, BIO_NOCLOSE); OpenSSLUtils::setBioFd(wb, fd_, BIO_NOCLOSE);
SSL_set_bio(ssl_, wb, wb); SSL_set_bio(ssl_, wb, wb);
return true; return true;
} }
...@@ -1590,8 +1590,8 @@ int AsyncSSLSocket::bioWrite(BIO* b, const char* in, int inl) { ...@@ -1590,8 +1590,8 @@ int AsyncSSLSocket::bioWrite(BIO* b, const char* in, int inl) {
flags |= MSG_NOSIGNAL; flags |= MSG_NOSIGNAL;
#endif #endif
auto result = auto result = tsslSock->sendSocketMessage(
tsslSock->sendSocketMessage(BIO_get_fd(b, nullptr), &msg, flags); OpenSSLUtils::getBioFd(b, nullptr), &msg, flags);
BIO_clear_retry_flags(b); BIO_clear_retry_flags(b);
if (!result.exception && result.writeReturn <= 0) { if (!result.exception && result.writeReturn <= 0) {
if (OpenSSLUtils::getBioShouldRetryWrite(result.writeReturn)) { if (OpenSSLUtils::getBioShouldRetryWrite(result.writeReturn)) {
......
...@@ -180,6 +180,27 @@ void OpenSSLUtils::setCustomBioMethod(BIO* b, BIO_METHOD* meth) { ...@@ -180,6 +180,27 @@ void OpenSSLUtils::setCustomBioMethod(BIO* b, BIO_METHOD* meth) {
#endif #endif
} }
int OpenSSLUtils::getBioFd(BIO* b, int* fd) {
#ifdef _WIN32
int ret = portability::sockets::socket_to_fd((SOCKET)BIO_get_fd(b, fd));
if (fd != nullptr) {
*fd = ret;
}
return ret;
#else
return BIO_get_fd(b, fd);
#endif
}
void OpenSSLUtils::setBioFd(BIO* b, int fd, int flags) {
#ifdef _WIN32
SOCKET sock = portability::sockets::fd_to_socket(fd);
#else
int sock = fd;
#endif
BIO_set_fd(b, sock, flags);
}
} // ssl } // ssl
} // folly } // folly
......
...@@ -69,6 +69,8 @@ class OpenSSLUtils { ...@@ -69,6 +69,8 @@ class OpenSSLUtils {
static void setBioAppData(BIO* b, void* ptr); static void setBioAppData(BIO* b, void* ptr);
static void* getBioAppData(BIO* b); static void* getBioAppData(BIO* b);
static void setCustomBioMethod(BIO*, BIO_METHOD*); static void setCustomBioMethod(BIO*, BIO_METHOD*);
static int getBioFd(BIO* b, int* fd);
static void setBioFd(BIO* b, int fd, int flags);
}; };
} // ssl } // ssl
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment