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() {
}
OpenSSLUtils::setBioAppData(wb, this);
BIO_set_fd(wb, fd_, BIO_NOCLOSE);
OpenSSLUtils::setBioFd(wb, fd_, BIO_NOCLOSE);
SSL_set_bio(ssl_, wb, wb);
return true;
}
......@@ -1590,8 +1590,8 @@ int AsyncSSLSocket::bioWrite(BIO* b, const char* in, int inl) {
flags |= MSG_NOSIGNAL;
#endif
auto result =
tsslSock->sendSocketMessage(BIO_get_fd(b, nullptr), &msg, flags);
auto result = tsslSock->sendSocketMessage(
OpenSSLUtils::getBioFd(b, nullptr), &msg, flags);
BIO_clear_retry_flags(b);
if (!result.exception && result.writeReturn <= 0) {
if (OpenSSLUtils::getBioShouldRetryWrite(result.writeReturn)) {
......
......@@ -180,6 +180,27 @@ void OpenSSLUtils::setCustomBioMethod(BIO* b, BIO_METHOD* meth) {
#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
} // folly
......
......@@ -69,6 +69,8 @@ class OpenSSLUtils {
static void setBioAppData(BIO* b, void* ptr);
static void* getBioAppData(BIO* b);
static void setCustomBioMethod(BIO*, BIO_METHOD*);
static int getBioFd(BIO* b, int* fd);
static void setBioFd(BIO* b, int fd, int flags);
};
} // 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