#include <folly/io/async/AsyncTransport.h>
#include <folly/io/async/EventBase.h>
#include <folly/io/async/ssl/SSLErrors.h>
+#include <folly/portability/Sockets.h>
#include <folly/portability/Unistd.h>
#include <gtest/gtest.h>
#include <iostream>
#include <list>
#include <fcntl.h>
-#include <poll.h>
#include <sys/types.h>
-#include <sys/socket.h>
-#include <netinet/tcp.h>
namespace folly {
: wcb_(wcb), state(STATE_WAITING) {}
~ReadCallbackBase() {
- EXPECT_EQ(state, STATE_SUCCEEDED);
+ EXPECT_EQ(STATE_SUCCEEDED, state);
}
void setSocket(
}
~HandshakeCallback() {
- EXPECT_EQ(state, STATE_SUCCEEDED);
+ EXPECT_EQ(STATE_SUCCEEDED, state);
}
void closeSocket() {
state(STATE_WAITING), hcb_(hcb) {}
~SSLServerAcceptCallbackBase() {
- EXPECT_EQ(state, STATE_SUCCEEDED);
+ EXPECT_EQ(STATE_SUCCEEDED, state);
}
void acceptError(const std::exception& ex) noexcept override {
}
};
+class ConnectTimeoutCallback : public SSLServerAcceptCallbackBase {
+ public:
+ ConnectTimeoutCallback() : SSLServerAcceptCallbackBase(nullptr) {
+ // We don't care if we get invoked or not.
+ // The client may time out and give up before connAccepted() is even
+ // called.
+ state = STATE_SUCCEEDED;
+ }
+
+ // Functions inherited from TAsyncSSLServerSocket::SSLAcceptCallback
+ void connAccepted(
+ const std::shared_ptr<folly::AsyncSSLSocket>& s) noexcept override {
+ std::cerr << "ConnectTimeoutCallback::connAccepted" << std::endl;
+
+ // Just wait a while before closing the socket, so the client
+ // will time out waiting for the handshake to complete.
+ s->getEventBase()->tryRunAfterDelay([=] { s->close(); }, 100);
+ }
+};
class TestSSLServer {
protected:
public:
// Create a TestSSLServer.
// This immediately starts listening on the given port.
- explicit TestSSLServer(SSLServerAcceptCallbackBase *acb);
+ explicit TestSSLServer(
+ SSLServerAcceptCallbackBase* acb,
+ bool enableTFO = false);
// Kill the thread.
~TestSSLServer() {