/*
- * Copyright 2017 Facebook, Inc.
+ * Copyright 2012-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#pragma once
#include <signal.h>
-#include <pthread.h>
#include <folly/ExceptionWrapper.h>
#include <folly/SocketAddress.h>
#include <folly/io/async/ssl/SSLErrors.h>
#include <folly/io/async/test/TestSSLServer.h>
#include <folly/portability/GTest.h>
+#include <folly/portability/PThread.h>
#include <folly/portability/Sockets.h>
#include <folly/portability/Unistd.h>
#include <condition_variable>
#include <iostream>
#include <list>
+#include <memory>
namespace folly {
int getFlagsImpl(folly::WriteFlags flags, int /*defaultFlags*/) noexcept
override {
- return oldCallback_->getFlags(flags);
+ return oldCallback_->getFlags(flags, false /*zeroCopyEnabled*/);
}
void getAncillaryData(folly::WriteFlags flags, void* data) noexcept override {
if (flags_) {
return flags_;
} else {
- return oldCallback_->getFlags(flags);
+ return oldCallback_->getFlags(flags, false /*zeroCopyEnabled*/);
}
}
class WriteCallbackBase :
public AsyncTransportWrapper::WriteCallback {
-public:
+ public:
explicit WriteCallbackBase(SendMsgParamsCallbackBase* mcb = nullptr)
: state(STATE_WAITING)
, bytesWritten(0)
class ExpectWriteErrorCallback :
public WriteCallbackBase {
-public:
+ public:
explicit ExpectWriteErrorCallback(SendMsgParamsCallbackBase* mcb = nullptr)
: WriteCallbackBase(mcb) {}
}
};
-#ifdef MSG_ERRQUEUE
+#ifdef FOLLY_HAVE_MSG_ERRQUEUE
/* copied from include/uapi/linux/net_tstamp.h */
/* SO_TIMESTAMPING gets an integer bit field comprised of these values */
enum SOF_TIMESTAMPING {
};
class WriteCheckTimestampCallback :
- public WriteCallbackBase {
-public:
+ public WriteCallbackBase {
+ public:
explicit WriteCheckTimestampCallback(SendMsgParamsCallbackBase* mcb = nullptr)
: WriteCallbackBase(mcb) {}
bool gotTimestamp_{false};
bool gotByteSeq_{false};
};
-#endif // MSG_ERRQUEUE
+#endif // FOLLY_HAVE_MSG_ERRQUEUE
class ReadCallbackBase :
public AsyncTransportWrapper::ReadCallback {
};
class ReadCallback : public ReadCallbackBase {
-public:
+ public:
explicit ReadCallback(WriteCallbackBase *wcb)
: ReadCallbackBase(wcb)
, buffers() {}
}
class Buffer {
- public:
+ public:
Buffer() : buffer(nullptr), length(0) {}
Buffer(char* buf, size_t len) : buffer(buf), length(len) {}
};
class ReadErrorCallback : public ReadCallbackBase {
-public:
+ public:
explicit ReadErrorCallback(WriteCallbackBase *wcb)
: ReadCallbackBase(wcb) {}
};
class WriteErrorCallback : public ReadCallback {
-public:
+ public:
explicit WriteErrorCallback(WriteCallbackBase *wcb)
: ReadCallback(wcb) {}
};
class EmptyReadCallback : public ReadCallback {
-public:
+ public:
explicit EmptyReadCallback()
: ReadCallback(nullptr) {}
class HandshakeCallback :
public AsyncSSLSocket::HandshakeCB {
-public:
+ public:
enum ExpectType {
EXPECT_SUCCESS,
EXPECT_ERROR
};
class SSLServerAcceptCallback: public SSLServerAcceptCallbackBase {
-public:
+ public:
uint32_t timeout_;
explicit SSLServerAcceptCallback(HandshakeCallback *hcb,
}
}
- // Functions inherited from TAsyncSSLServerSocket::SSLAcceptCallback
void connAccepted(
const std::shared_ptr<folly::AsyncSSLSocket> &s)
noexcept override {
};
class SSLServerAcceptCallbackDelay: public SSLServerAcceptCallback {
-public:
+ public:
explicit SSLServerAcceptCallbackDelay(HandshakeCallback *hcb):
SSLServerAcceptCallback(hcb) {}
- // Functions inherited from TAsyncSSLServerSocket::SSLAcceptCallback
void connAccepted(
const std::shared_ptr<folly::AsyncSSLSocket> &s)
noexcept override {
};
class SSLServerAsyncCacheAcceptCallback: public SSLServerAcceptCallback {
-public:
+ public:
explicit SSLServerAsyncCacheAcceptCallback(HandshakeCallback *hcb,
uint32_t timeout = 0):
SSLServerAcceptCallback(hcb, timeout) {}
- // Functions inherited from TAsyncSSLServerSocket::SSLAcceptCallback
void connAccepted(
const std::shared_ptr<folly::AsyncSSLSocket> &s)
noexcept override {
class HandshakeErrorCallback: public SSLServerAcceptCallbackBase {
-public:
+ public:
explicit HandshakeErrorCallback(HandshakeCallback *hcb):
SSLServerAcceptCallbackBase(hcb) {}
- // Functions inherited from TAsyncSSLServerSocket::SSLAcceptCallback
void connAccepted(
const std::shared_ptr<folly::AsyncSSLSocket> &s)
noexcept override {
};
class HandshakeTimeoutCallback: public SSLServerAcceptCallbackBase {
-public:
+ public:
explicit HandshakeTimeoutCallback(HandshakeCallback *hcb):
SSLServerAcceptCallbackBase(hcb) {}
- // Functions inherited from TAsyncSSLServerSocket::SSLAcceptCallback
void connAccepted(
const std::shared_ptr<folly::AsyncSSLSocket> &s)
noexcept override {
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;
bufLen_(2500),
iovCount_(2000) {
// Fill buf_
- buf_.reset(new uint8_t[bufLen_]);
+ buf_ = std::make_unique<uint8_t[]>(bufLen_);
for (uint32_t n = 0; n < sizeof(buf_); ++n) {
buf_[n] = n % 0xff;
}
// Initialize iov_
- iov_.reset(new struct iovec[iovCount_]);
+ iov_ = std::make_unique<struct iovec[]>(iovCount_);
for (uint32_t n = 0; n < iovCount_; ++n) {
iov_[n].iov_base = buf_.get() + n;
if (n & 0x1) {
: socket_(std::move(socket)),
bufSize_(2500 * 2000),
bytesRead_(0) {
- buf_.reset(new uint8_t[bufSize_]);
+ buf_ = std::make_unique<uint8_t[]>(bufSize_);
socket_->sslAccept(this, std::chrono::milliseconds(100));
}
const unsigned char* nextProto;
unsigned nextProtoLength;
SSLContext::NextProtocolType protocolType;
+ folly::Optional<AsyncSocketException> except;
private:
void handshakeSuc(AsyncSSLSocket*) noexcept override {
void handshakeErr(
AsyncSSLSocket*,
const AsyncSocketException& ex) noexcept override {
- ADD_FAILURE() << "client handshake error: " << ex.what();
+ except = ex;
}
void writeSuccess() noexcept override {
socket_->close();
const unsigned char* nextProto;
unsigned nextProtoLength;
SSLContext::NextProtocolType protocolType;
+ folly::Optional<AsyncSocketException> except;
private:
void handshakeSuc(AsyncSSLSocket*) noexcept override {
void handshakeErr(
AsyncSSLSocket*,
const AsyncSocketException& ex) noexcept override {
- ADD_FAILURE() << "server handshake error: " << ex.what();
+ except = ex;
}
void getReadBuffer(void** /* bufReturn */, size_t* lenReturn) override {
*lenReturn = 0;
EventBase* eventBase_;
};
-}
+} // namespace folly