}
TEST(AsyncSSLSocketTest, TestPreReceivedData) {
- EventBase clientEventBase;
- EventBase serverEventBase;
+ EventBase eventBase;
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
std::array<int, 2> fds;
getctx(clientCtx, dfServerCtx);
AsyncSSLSocket::UniquePtr clientSockPtr(
- new AsyncSSLSocket(clientCtx, &clientEventBase, fds[0], false));
+ new AsyncSSLSocket(clientCtx, &eventBase, fds[0], false));
AsyncSSLSocket::UniquePtr serverSockPtr(
- new AsyncSSLSocket(dfServerCtx, &serverEventBase, fds[1], true));
+ new AsyncSSLSocket(dfServerCtx, &eventBase, fds[1], true));
auto clientSock = clientSockPtr.get();
auto serverSock = serverSockPtr.get();
SSLHandshakeClient client(std::move(clientSockPtr), true, true);
// Steal some data from the server.
- clientEventBase.loopOnce();
std::array<uint8_t, 10> buf;
- recv(fds[1], buf.data(), buf.size(), 0);
+ auto bytesReceived = recv(fds[1], buf.data(), buf.size(), 0);
+ checkUnixError(bytesReceived, "recv failed");
- serverSock->setPreReceivedData(IOBuf::wrapBuffer(range(buf)));
+ serverSock->setPreReceivedData(
+ IOBuf::wrapBuffer(ByteRange(buf.data(), bytesReceived)));
SSLHandshakeServer server(std::move(serverSockPtr), true, true);
while (!client.handshakeSuccess_ && !client.handshakeError_) {
- serverEventBase.loopOnce();
- clientEventBase.loopOnce();
+ eventBase.loopOnce();
}
EXPECT_TRUE(client.handshakeSuccess_);
}
TEST(AsyncSSLSocketTest, TestMoveFromAsyncSocket) {
- EventBase clientEventBase;
- EventBase serverEventBase;
+ EventBase eventBase;
auto clientCtx = std::make_shared<SSLContext>();
auto dfServerCtx = std::make_shared<SSLContext>();
std::array<int, 2> fds;
getctx(clientCtx, dfServerCtx);
AsyncSSLSocket::UniquePtr clientSockPtr(
- new AsyncSSLSocket(clientCtx, &clientEventBase, fds[0], false));
- AsyncSocket::UniquePtr serverSockPtr(
- new AsyncSocket(&serverEventBase, fds[1]));
+ new AsyncSSLSocket(clientCtx, &eventBase, fds[0], false));
+ AsyncSocket::UniquePtr serverSockPtr(new AsyncSocket(&eventBase, fds[1]));
auto clientSock = clientSockPtr.get();
auto serverSock = serverSockPtr.get();
SSLHandshakeClient client(std::move(clientSockPtr), true, true);
// Steal some data from the server.
- clientEventBase.loopOnce();
std::array<uint8_t, 10> buf;
- recv(fds[1], buf.data(), buf.size(), 0);
- serverSock->setPreReceivedData(IOBuf::wrapBuffer(range(buf)));
+ auto bytesReceived = recv(fds[1], buf.data(), buf.size(), 0);
+ checkUnixError(bytesReceived, "recv failed");
+
+ serverSock->setPreReceivedData(
+ IOBuf::wrapBuffer(ByteRange(buf.data(), bytesReceived)));
AsyncSSLSocket::UniquePtr serverSSLSockPtr(
new AsyncSSLSocket(dfServerCtx, std::move(serverSockPtr), true));
auto serverSSLSock = serverSSLSockPtr.get();
SSLHandshakeServer server(std::move(serverSSLSockPtr), true, true);
while (!client.handshakeSuccess_ && !client.handshakeError_) {
- serverEventBase.loopOnce();
- clientEventBase.loopOnce();
+ eventBase.loopOnce();
}
EXPECT_TRUE(client.handshakeSuccess_);