Commit 2586be5b authored by Mingtao Yang's avatar Mingtao Yang Committed by Facebook GitHub Bot

Deprecate AsyncTransportWrapper

Summary:
All implementations of transports in practice were all AsyncTransportWrappers
(AsyncSocket, AsyncSSLSocket, AsyncFizzBase, etc.).

AsyncTransportWrapper was confusing. The only additional functionality that
it provided was the ability to query underlying transports, a piece of
functionality which makes just as much sense on AsyncTransport.

The simplified model:

"AsyncTransport deals with bidirectional I/O. It is both an AsyncReader, and
an AsyncWriter. It may be nested."

This diff changes AsyncTransportWrapper usages in folly to refer to
AsyncTransport, and aliases AsyncTransportWrapper for compatibility.

Reviewed By: yfeldblum

Differential Revision: D21915048

fbshipit-source-id: 741fad91b8f7c8080f942168f5513b12602cfe9a
parent 0e32d9f4
...@@ -368,7 +368,7 @@ bool AsyncSSLSocket::good() const { ...@@ -368,7 +368,7 @@ bool AsyncSSLSocket::good() const {
sslState_ == STATE_UNINIT)); sslState_ == STATE_UNINIT));
} }
// The AsyncTransportWrapper definition of 'good' states that the transport is // The AsyncTransport definition of 'good' states that the transport is
// ready to perform reads and writes, so sslState_ == UNINIT must report !good. // ready to perform reads and writes, so sslState_ == UNINIT must report !good.
// connecting can be true when the sslState_ == UNINIT because the AsyncSocket // connecting can be true when the sslState_ == UNINIT because the AsyncSocket
// is connected but we haven't initiated the call to SSL_connect. // is connected but we haven't initiated the call to SSL_connect.
......
...@@ -320,7 +320,7 @@ class AsyncSSLSocket : public virtual AsyncSocket { ...@@ -320,7 +320,7 @@ class AsyncSSLSocket : public virtual AsyncSocket {
* the flag should be reset. * the flag should be reset.
*/ */
// Inherit AsyncTransportWrapper methods from AsyncSocket except the // Inherit AsyncTransport methods from AsyncSocket except the
// following. // following.
// See the documentation in AsyncTransport.h // See the documentation in AsyncTransport.h
// TODO: implement graceful shutdown in close() // TODO: implement graceful shutdown in close()
......
...@@ -73,7 +73,7 @@ namespace folly { ...@@ -73,7 +73,7 @@ namespace folly {
#define SO_NO_TSOCKS 201 #define SO_NO_TSOCKS 201
#endif #endif
class AsyncSocket : public AsyncTransportWrapper { class AsyncSocket : public AsyncTransport {
public: public:
using UniquePtr = std::unique_ptr<AsyncSocket, Destructor>; using UniquePtr = std::unique_ptr<AsyncSocket, Destructor>;
......
...@@ -133,8 +133,236 @@ constexpr bool isSet(WriteFlags a, WriteFlags b) { ...@@ -133,8 +133,236 @@ constexpr bool isSet(WriteFlags a, WriteFlags b) {
constexpr WriteFlags kEorRelevantWriteFlags = constexpr WriteFlags kEorRelevantWriteFlags =
WriteFlags::EOR | WriteFlags::TIMESTAMP_TX; WriteFlags::EOR | WriteFlags::TIMESTAMP_TX;
class AsyncReader {
public:
class ReadCallback {
public:
virtual ~ReadCallback() = default;
/**
* When data becomes available, getReadBuffer() will be invoked to get the
* buffer into which data should be read.
*
* This method allows the ReadCallback to delay buffer allocation until
* data becomes available. This allows applications to manage large
* numbers of idle connections, without having to maintain a separate read
* buffer for each idle connection.
*
* It is possible that in some cases, getReadBuffer() may be called
* multiple times before readDataAvailable() is invoked. In this case, the
* data will be written to the buffer returned from the most recent call to
* readDataAvailable(). If the previous calls to readDataAvailable()
* returned different buffers, the ReadCallback is responsible for ensuring
* that they are not leaked.
*
* If getReadBuffer() throws an exception, returns a nullptr buffer, or
* returns a 0 length, the ReadCallback will be uninstalled and its
* readError() method will be invoked.
*
* getReadBuffer() is not allowed to change the transport state before it
* returns. (For example, it should never uninstall the read callback, or
* set a different read callback.)
*
* @param bufReturn getReadBuffer() should update *bufReturn to contain the
* address of the read buffer. This parameter will never
* be nullptr.
* @param lenReturn getReadBuffer() should update *lenReturn to contain the
* maximum number of bytes that may be written to the read
* buffer. This parameter will never be nullptr.
*/
virtual void getReadBuffer(void** bufReturn, size_t* lenReturn) = 0;
/**
* readDataAvailable() will be invoked when data has been successfully read
* into the buffer returned by the last call to getReadBuffer().
*
* The read callback remains installed after readDataAvailable() returns.
* It must be explicitly uninstalled to stop receiving read events.
* getReadBuffer() will be called at least once before each call to
* readDataAvailable(). getReadBuffer() will also be called before any
* call to readEOF().
*
* @param len The number of bytes placed in the buffer.
*/
virtual void readDataAvailable(size_t len) noexcept = 0;
/**
* When data becomes available, isBufferMovable() will be invoked to figure
* out which API will be used, readBufferAvailable() or
* readDataAvailable(). If isBufferMovable() returns true, that means
* ReadCallback supports the IOBuf ownership transfer and
* readBufferAvailable() will be used. Otherwise, not.
* By default, isBufferMovable() always return false. If
* readBufferAvailable() is implemented and to be invoked, You should
* overwrite isBufferMovable() and return true in the inherited class.
*
* This method allows the AsyncSocket/AsyncSSLSocket do buffer allocation by
* itself until data becomes available. Compared with the pre/post buffer
* allocation in getReadBuffer()/readDataAvailabe(), readBufferAvailable()
* has two advantages. First, this can avoid memcpy. E.g., in
* AsyncSSLSocket, the decrypted data was copied from the openssl internal
* buffer to the readbuf buffer. With the buffer ownership transfer, the
* internal buffer can be directly "moved" to ReadCallback. Second, the
* memory allocation can be more precise. The reason is
* AsyncSocket/AsyncSSLSocket can allocate the memory of precise size
* because they have more context about the available data than
* ReadCallback. Think about the getReadBuffer() pre-allocate 4072 bytes
* buffer, but the available data is always 16KB (max OpenSSL record size).
*/
virtual bool isBufferMovable() noexcept {
return false;
}
/**
* Suggested buffer size, allocated for read operations,
* if callback is movable and supports folly::IOBuf
*/
virtual size_t maxBufferSize() const {
return 64 * 1024; // 64K
}
/**
* readBufferAvailable() will be invoked when data has been successfully
* read.
*
* Note that only either readBufferAvailable() or readDataAvailable() will
* be invoked according to the return value of isBufferMovable(). The timing
* and aftereffect of readBufferAvailable() are the same as
* readDataAvailable()
*
* @param readBuf The unique pointer of read buffer.
*/
virtual void readBufferAvailable(
std::unique_ptr<IOBuf> /*readBuf*/) noexcept {}
/**
* readEOF() will be invoked when the transport is closed.
*
* The read callback will be automatically uninstalled immediately before
* readEOF() is invoked.
*/
virtual void readEOF() noexcept = 0;
/**
* readError() will be invoked if an error occurs reading from the
* transport.
*
* The read callback will be automatically uninstalled immediately before
* readError() is invoked.
*
* @param ex An exception describing the error that occurred.
*/
virtual void readErr(const AsyncSocketException& ex) noexcept = 0;
};
// Read methods that aren't part of AsyncTransport.
virtual void setReadCB(ReadCallback* callback) = 0;
virtual ReadCallback* getReadCallback() const = 0;
protected:
virtual ~AsyncReader() = default;
};
class AsyncWriter {
public:
class WriteCallback {
public:
virtual ~WriteCallback() = default;
/**
* writeSuccess() will be invoked when all of the data has been
* successfully written.
*
* Note that this mainly signals that the buffer containing the data to
* write is no longer needed and may be freed or re-used. It does not
* guarantee that the data has been fully transmitted to the remote
* endpoint. For example, on socket-based transports, writeSuccess() only
* indicates that the data has been given to the kernel for eventual
* transmission.
*/
virtual void writeSuccess() noexcept = 0;
/**
* writeError() will be invoked if an error occurs writing the data.
*
* @param bytesWritten The number of bytes that were successfull
* @param ex An exception describing the error that occurred.
*/
virtual void writeErr(
size_t bytesWritten,
const AsyncSocketException& ex) noexcept = 0;
};
/**
* If you supply a non-null WriteCallback, exactly one of writeSuccess()
* or writeErr() will be invoked when the write completes. If you supply
* the same WriteCallback object for multiple write() calls, it will be
* invoked exactly once per call. The only way to cancel outstanding
* write requests is to close the socket (e.g., with closeNow() or
* shutdownWriteNow()). When closing the socket this way, writeErr() will
* still be invoked once for each outstanding write operation.
*/
virtual void write(
WriteCallback* callback,
const void* buf,
size_t bytes,
WriteFlags flags = WriteFlags::NONE) = 0;
/**
* If you supply a non-null WriteCallback, exactly one of writeSuccess()
* or writeErr() will be invoked when the write completes. If you supply
* the same WriteCallback object for multiple write() calls, it will be
* invoked exactly once per call. The only way to cancel outstanding
* write requests is to close the socket (e.g., with closeNow() or
* shutdownWriteNow()). When closing the socket this way, writeErr() will
* still be invoked once for each outstanding write operation.
*/
virtual void writev(
WriteCallback* callback,
const iovec* vec,
size_t count,
WriteFlags flags = WriteFlags::NONE) = 0;
/**
* If you supply a non-null WriteCallback, exactly one of writeSuccess()
* or writeErr() will be invoked when the write completes. If you supply
* the same WriteCallback object for multiple write() calls, it will be
* invoked exactly once per call. The only way to cancel outstanding
* write requests is to close the socket (e.g., with closeNow() or
* shutdownWriteNow()). When closing the socket this way, writeErr() will
* still be invoked once for each outstanding write operation.
*/
virtual void writeChain(
WriteCallback* callback,
std::unique_ptr<IOBuf>&& buf,
WriteFlags flags = WriteFlags::NONE) = 0;
/** zero copy related
* */
virtual bool setZeroCopy(bool /*enable*/) {
return false;
}
virtual bool getZeroCopy() const {
return false;
}
using ZeroCopyEnableFunc =
std::function<bool(const std::unique_ptr<folly::IOBuf>& buf)>;
virtual void setZeroCopyEnableFunc(ZeroCopyEnableFunc /*func*/) {}
protected:
virtual ~AsyncWriter() = default;
};
/** /**
* AsyncTransport defines an asynchronous API for streaming I/O. * AsyncTransport defines an asynchronous API for bidirectional streaming I/O.
* *
* This class provides an API to for asynchronously waiting for data * This class provides an API to for asynchronously waiting for data
* on a streaming transport, and for asynchronously sending data. * on a streaming transport, and for asynchronously sending data.
...@@ -160,7 +388,10 @@ constexpr WriteFlags kEorRelevantWriteFlags = ...@@ -160,7 +388,10 @@ constexpr WriteFlags kEorRelevantWriteFlags =
* timeout, since most callers want to give up if the remote end stops * timeout, since most callers want to give up if the remote end stops
* responding and no further progress can be made sending the data. * responding and no further progress can be made sending the data.
*/ */
class AsyncTransport : public DelayedDestruction, public AsyncSocketBase { class AsyncTransport : public DelayedDestruction,
public AsyncSocketBase,
public AsyncReader,
public AsyncWriter {
public: public:
typedef std::unique_ptr<AsyncTransport, Destructor> UniquePtr; typedef std::unique_ptr<AsyncTransport, Destructor> UniquePtr;
...@@ -498,272 +729,12 @@ class AsyncTransport : public DelayedDestruction, public AsyncSocketBase { ...@@ -498,272 +729,12 @@ class AsyncTransport : public DelayedDestruction, public AsyncSocketBase {
} }
} }
protected:
~AsyncTransport() override = default;
};
class AsyncReader {
public:
class ReadCallback {
public:
virtual ~ReadCallback() = default;
/**
* When data becomes available, getReadBuffer() will be invoked to get the
* buffer into which data should be read.
*
* This method allows the ReadCallback to delay buffer allocation until
* data becomes available. This allows applications to manage large
* numbers of idle connections, without having to maintain a separate read
* buffer for each idle connection.
*
* It is possible that in some cases, getReadBuffer() may be called
* multiple times before readDataAvailable() is invoked. In this case, the
* data will be written to the buffer returned from the most recent call to
* readDataAvailable(). If the previous calls to readDataAvailable()
* returned different buffers, the ReadCallback is responsible for ensuring
* that they are not leaked.
*
* If getReadBuffer() throws an exception, returns a nullptr buffer, or
* returns a 0 length, the ReadCallback will be uninstalled and its
* readError() method will be invoked.
*
* getReadBuffer() is not allowed to change the transport state before it
* returns. (For example, it should never uninstall the read callback, or
* set a different read callback.)
*
* @param bufReturn getReadBuffer() should update *bufReturn to contain the
* address of the read buffer. This parameter will never
* be nullptr.
* @param lenReturn getReadBuffer() should update *lenReturn to contain the
* maximum number of bytes that may be written to the read
* buffer. This parameter will never be nullptr.
*/
virtual void getReadBuffer(void** bufReturn, size_t* lenReturn) = 0;
/**
* readDataAvailable() will be invoked when data has been successfully read
* into the buffer returned by the last call to getReadBuffer().
*
* The read callback remains installed after readDataAvailable() returns.
* It must be explicitly uninstalled to stop receiving read events.
* getReadBuffer() will be called at least once before each call to
* readDataAvailable(). getReadBuffer() will also be called before any
* call to readEOF().
*
* @param len The number of bytes placed in the buffer.
*/
virtual void readDataAvailable(size_t len) noexcept = 0;
/**
* When data becomes available, isBufferMovable() will be invoked to figure
* out which API will be used, readBufferAvailable() or
* readDataAvailable(). If isBufferMovable() returns true, that means
* ReadCallback supports the IOBuf ownership transfer and
* readBufferAvailable() will be used. Otherwise, not.
* By default, isBufferMovable() always return false. If
* readBufferAvailable() is implemented and to be invoked, You should
* overwrite isBufferMovable() and return true in the inherited class.
*
* This method allows the AsyncSocket/AsyncSSLSocket do buffer allocation by
* itself until data becomes available. Compared with the pre/post buffer
* allocation in getReadBuffer()/readDataAvailabe(), readBufferAvailable()
* has two advantages. First, this can avoid memcpy. E.g., in
* AsyncSSLSocket, the decrypted data was copied from the openssl internal
* buffer to the readbuf buffer. With the buffer ownership transfer, the
* internal buffer can be directly "moved" to ReadCallback. Second, the
* memory allocation can be more precise. The reason is
* AsyncSocket/AsyncSSLSocket can allocate the memory of precise size
* because they have more context about the available data than
* ReadCallback. Think about the getReadBuffer() pre-allocate 4072 bytes
* buffer, but the available data is always 16KB (max OpenSSL record size).
*/
virtual bool isBufferMovable() noexcept {
return false;
}
/**
* Suggested buffer size, allocated for read operations,
* if callback is movable and supports folly::IOBuf
*/
virtual size_t maxBufferSize() const {
return 64 * 1024; // 64K
}
/**
* readBufferAvailable() will be invoked when data has been successfully
* read.
*
* Note that only either readBufferAvailable() or readDataAvailable() will
* be invoked according to the return value of isBufferMovable(). The timing
* and aftereffect of readBufferAvailable() are the same as
* readDataAvailable()
*
* @param readBuf The unique pointer of read buffer.
*/
virtual void readBufferAvailable(
std::unique_ptr<IOBuf> /*readBuf*/) noexcept {}
/**
* readEOF() will be invoked when the transport is closed.
*
* The read callback will be automatically uninstalled immediately before
* readEOF() is invoked.
*/
virtual void readEOF() noexcept = 0;
/**
* readError() will be invoked if an error occurs reading from the
* transport.
*
* The read callback will be automatically uninstalled immediately before
* readError() is invoked.
*
* @param ex An exception describing the error that occurred.
*/
virtual void readErr(const AsyncSocketException& ex) noexcept = 0;
};
// Read methods that aren't part of AsyncTransport.
virtual void setReadCB(ReadCallback* callback) = 0;
virtual ReadCallback* getReadCallback() const = 0;
protected:
virtual ~AsyncReader() = default;
};
class AsyncWriter {
public:
class WriteCallback {
public:
virtual ~WriteCallback() = default;
/**
* writeSuccess() will be invoked when all of the data has been
* successfully written.
*
* Note that this mainly signals that the buffer containing the data to
* write is no longer needed and may be freed or re-used. It does not
* guarantee that the data has been fully transmitted to the remote
* endpoint. For example, on socket-based transports, writeSuccess() only
* indicates that the data has been given to the kernel for eventual
* transmission.
*/
virtual void writeSuccess() noexcept = 0;
/**
* writeError() will be invoked if an error occurs writing the data.
*
* @param bytesWritten The number of bytes that were successfull
* @param ex An exception describing the error that occurred.
*/
virtual void writeErr(
size_t bytesWritten,
const AsyncSocketException& ex) noexcept = 0;
};
/**
* If you supply a non-null WriteCallback, exactly one of writeSuccess()
* or writeErr() will be invoked when the write completes. If you supply
* the same WriteCallback object for multiple write() calls, it will be
* invoked exactly once per call. The only way to cancel outstanding
* write requests is to close the socket (e.g., with closeNow() or
* shutdownWriteNow()). When closing the socket this way, writeErr() will
* still be invoked once for each outstanding write operation.
*/
virtual void write(
WriteCallback* callback,
const void* buf,
size_t bytes,
WriteFlags flags = WriteFlags::NONE) = 0;
/**
* If you supply a non-null WriteCallback, exactly one of writeSuccess()
* or writeErr() will be invoked when the write completes. If you supply
* the same WriteCallback object for multiple write() calls, it will be
* invoked exactly once per call. The only way to cancel outstanding
* write requests is to close the socket (e.g., with closeNow() or
* shutdownWriteNow()). When closing the socket this way, writeErr() will
* still be invoked once for each outstanding write operation.
*/
virtual void writev(
WriteCallback* callback,
const iovec* vec,
size_t count,
WriteFlags flags = WriteFlags::NONE) = 0;
/**
* If you supply a non-null WriteCallback, exactly one of writeSuccess()
* or writeErr() will be invoked when the write completes. If you supply
* the same WriteCallback object for multiple write() calls, it will be
* invoked exactly once per call. The only way to cancel outstanding
* write requests is to close the socket (e.g., with closeNow() or
* shutdownWriteNow()). When closing the socket this way, writeErr() will
* still be invoked once for each outstanding write operation.
*/
virtual void writeChain(
WriteCallback* callback,
std::unique_ptr<IOBuf>&& buf,
WriteFlags flags = WriteFlags::NONE) = 0;
/** zero copy related
* */
virtual bool setZeroCopy(bool /*enable*/) {
return false;
}
virtual bool getZeroCopy() const {
return false;
}
using ZeroCopyEnableFunc =
std::function<bool(const std::unique_ptr<folly::IOBuf>& buf)>;
virtual void setZeroCopyEnableFunc(ZeroCopyEnableFunc /*func*/) {}
protected:
virtual ~AsyncWriter() = default;
};
// Transitional intermediate interface. This is deprecated.
// Wrapper around folly::AsyncTransport, that includes read/write callbacks
class AsyncTransportWrapper : public AsyncTransport,
public AsyncReader,
public AsyncWriter {
public:
using UniquePtr = std::unique_ptr<AsyncTransportWrapper, Destructor>;
// Alias for inherited members from AsyncReader and AsyncWriter
// to keep compatibility.
using ReadCallback = AsyncReader::ReadCallback;
using WriteCallback = AsyncWriter::WriteCallback;
void setReadCB(ReadCallback* callback) override = 0;
ReadCallback* getReadCallback() const override = 0;
void write(
WriteCallback* callback,
const void* buf,
size_t bytes,
WriteFlags flags = WriteFlags::NONE) override = 0;
void writev(
WriteCallback* callback,
const iovec* vec,
size_t count,
WriteFlags flags = WriteFlags::NONE) override = 0;
void writeChain(
WriteCallback* callback,
std::unique_ptr<IOBuf>&& buf,
WriteFlags flags = WriteFlags::NONE) override = 0;
/** /**
* The transport wrapper may wrap another transport. This returns the * AsyncTransports may wrap other AsyncTransport. This returns the
* transport that is wrapped. It returns nullptr if there is no wrapped * transport that is wrapped. It returns nullptr if there is no wrapped
* transport. * transport.
*/ */
virtual const AsyncTransportWrapper* getWrappedTransport() const { virtual const AsyncTransport* getWrappedTransport() const {
return nullptr; return nullptr;
} }
...@@ -774,7 +745,7 @@ class AsyncTransportWrapper : public AsyncTransport, ...@@ -774,7 +745,7 @@ class AsyncTransportWrapper : public AsyncTransport,
*/ */
template <class T> template <class T>
const T* getUnderlyingTransport() const { const T* getUnderlyingTransport() const {
const AsyncTransportWrapper* current = this; const AsyncTransport* current = this;
while (current) { while (current) {
auto sock = dynamic_cast<const T*>(current); auto sock = dynamic_cast<const T*>(current);
if (sock) { if (sock) {
...@@ -787,9 +758,13 @@ class AsyncTransportWrapper : public AsyncTransport, ...@@ -787,9 +758,13 @@ class AsyncTransportWrapper : public AsyncTransport,
template <class T> template <class T>
T* getUnderlyingTransport() { T* getUnderlyingTransport() {
return const_cast<T*>(static_cast<const AsyncTransportWrapper*>(this) return const_cast<T*>(
->getUnderlyingTransport<T>()); static_cast<const AsyncTransport*>(this)->getUnderlyingTransport<T>());
} }
protected:
~AsyncTransport() override = default;
}; };
using AsyncTransportWrapper = AsyncTransport;
} // namespace folly } // namespace folly
...@@ -21,31 +21,30 @@ ...@@ -21,31 +21,30 @@
namespace folly { namespace folly {
/** /**
* Convenience class so that AsyncTransportWrapper can be decorated without * Convenience class so that AsyncTransport can be decorated without
* having to redefine every single method. * having to redefine every single method.
*/ */
template <class T> template <class T>
class DecoratedAsyncTransportWrapper : public folly::AsyncTransportWrapper { class DecoratedAsyncTransportWrapper : public folly::AsyncTransport {
public: public:
explicit DecoratedAsyncTransportWrapper(typename T::UniquePtr transport) explicit DecoratedAsyncTransportWrapper(typename T::UniquePtr transport)
: transport_(std::move(transport)) {} : transport_(std::move(transport)) {}
const AsyncTransportWrapper* getWrappedTransport() const override { const AsyncTransport* getWrappedTransport() const override {
return transport_.get(); return transport_.get();
} }
// folly::AsyncTransportWrapper // folly::AsyncTransport
ReadCallback* getReadCallback() const override { ReadCallback* getReadCallback() const override {
return transport_->getReadCallback(); return transport_->getReadCallback();
} }
void setReadCB( void setReadCB(folly::AsyncTransport::ReadCallback* callback) override {
folly::AsyncTransportWrapper::ReadCallback* callback) override {
transport_->setReadCB(callback); transport_->setReadCB(callback);
} }
void write( void write(
folly::AsyncTransportWrapper::WriteCallback* callback, folly::AsyncTransport::WriteCallback* callback,
const void* buf, const void* buf,
size_t bytes, size_t bytes,
folly::WriteFlags flags = folly::WriteFlags::NONE) override { folly::WriteFlags flags = folly::WriteFlags::NONE) override {
...@@ -53,14 +52,14 @@ class DecoratedAsyncTransportWrapper : public folly::AsyncTransportWrapper { ...@@ -53,14 +52,14 @@ class DecoratedAsyncTransportWrapper : public folly::AsyncTransportWrapper {
} }
void writeChain( void writeChain(
folly::AsyncTransportWrapper::WriteCallback* callback, folly::AsyncTransport::WriteCallback* callback,
std::unique_ptr<folly::IOBuf>&& buf, std::unique_ptr<folly::IOBuf>&& buf,
folly::WriteFlags flags = folly::WriteFlags::NONE) override { folly::WriteFlags flags = folly::WriteFlags::NONE) override {
transport_->writeChain(callback, std::move(buf), flags); transport_->writeChain(callback, std::move(buf), flags);
} }
void writev( void writev(
folly::AsyncTransportWrapper::WriteCallback* callback, folly::AsyncTransport::WriteCallback* callback,
const iovec* vec, const iovec* vec,
size_t bytes, size_t bytes,
folly::WriteFlags flags = folly::WriteFlags::NONE) override { folly::WriteFlags flags = folly::WriteFlags::NONE) override {
......
...@@ -32,7 +32,7 @@ class WriteChainAsyncTransportWrapper ...@@ -32,7 +32,7 @@ class WriteChainAsyncTransportWrapper
using DecoratedAsyncTransportWrapper<T>::DecoratedAsyncTransportWrapper; using DecoratedAsyncTransportWrapper<T>::DecoratedAsyncTransportWrapper;
void write( void write(
folly::AsyncTransportWrapper::WriteCallback* callback, AsyncTransport::WriteCallback* callback,
const void* buf, const void* buf,
size_t bytes, size_t bytes,
folly::WriteFlags flags = folly::WriteFlags::NONE) override { folly::WriteFlags flags = folly::WriteFlags::NONE) override {
...@@ -41,7 +41,7 @@ class WriteChainAsyncTransportWrapper ...@@ -41,7 +41,7 @@ class WriteChainAsyncTransportWrapper
} }
void writev( void writev(
folly::AsyncTransportWrapper::WriteCallback* callback, AsyncTransport::WriteCallback* callback,
const iovec* vec, const iovec* vec,
size_t count, size_t count,
folly::WriteFlags flags = folly::WriteFlags::NONE) override { folly::WriteFlags flags = folly::WriteFlags::NONE) override {
...@@ -54,7 +54,7 @@ class WriteChainAsyncTransportWrapper ...@@ -54,7 +54,7 @@ class WriteChainAsyncTransportWrapper
* derived classes to do that. * derived classes to do that.
*/ */
void writeChain( void writeChain(
folly::AsyncTransportWrapper::WriteCallback* callback, AsyncTransport::WriteCallback* callback,
std::unique_ptr<folly::IOBuf>&& buf, std::unique_ptr<folly::IOBuf>&& buf,
folly::WriteFlags flags = folly::WriteFlags::NONE) override = 0; folly::WriteFlags flags = folly::WriteFlags::NONE) override = 0;
}; };
......
...@@ -805,7 +805,7 @@ TEST(AsyncSSLSocketTest, SSLClientTimeoutTest) { ...@@ -805,7 +805,7 @@ TEST(AsyncSSLSocketTest, SSLClientTimeoutTest) {
cerr << "SSLClientTimeoutTest test completed" << endl; cerr << "SSLClientTimeoutTest test completed" << endl;
} }
class PerLoopReadCallback : public AsyncTransportWrapper::ReadCallback { class PerLoopReadCallback : public AsyncTransport::ReadCallback {
public: public:
void getReadBuffer(void** bufReturn, size_t* lenReturn) override { void getReadBuffer(void** bufReturn, size_t* lenReturn) override {
*bufReturn = buf_.data(); *bufReturn = buf_.data();
......
...@@ -151,7 +151,7 @@ class SendMsgAncillaryDataCallback : public SendMsgParamsCallbackBase { ...@@ -151,7 +151,7 @@ class SendMsgAncillaryDataCallback : public SendMsgParamsCallbackBase {
std::vector<char> ancillaryData_; std::vector<char> ancillaryData_;
}; };
class WriteCallbackBase : public AsyncTransportWrapper::WriteCallback { class WriteCallbackBase : public AsyncTransport::WriteCallback {
public: public:
explicit WriteCallbackBase(SendMsgParamsCallbackBase* mcb = nullptr) explicit WriteCallbackBase(SendMsgParamsCallbackBase* mcb = nullptr)
: state(STATE_WAITING), : state(STATE_WAITING),
...@@ -320,7 +320,7 @@ class WriteCheckTimestampCallback : public WriteCallbackBase { ...@@ -320,7 +320,7 @@ class WriteCheckTimestampCallback : public WriteCallbackBase {
}; };
#endif // FOLLY_HAVE_MSG_ERRQUEUE #endif // FOLLY_HAVE_MSG_ERRQUEUE
class ReadCallbackBase : public AsyncTransportWrapper::ReadCallback { class ReadCallbackBase : public AsyncTransport::ReadCallback {
public: public:
explicit ReadCallbackBase(WriteCallbackBase* wcb) explicit ReadCallbackBase(WriteCallbackBase* wcb)
: wcb_(wcb), state(STATE_WAITING) {} : wcb_(wcb), state(STATE_WAITING) {}
...@@ -771,7 +771,7 @@ void sslsocketpair( ...@@ -771,7 +771,7 @@ void sslsocketpair(
AsyncSSLSocket::UniquePtr* serverSock); AsyncSSLSocket::UniquePtr* serverSock);
class BlockingWriteClient : private AsyncSSLSocket::HandshakeCB, class BlockingWriteClient : private AsyncSSLSocket::HandshakeCB,
private AsyncTransportWrapper::WriteCallback { private AsyncTransport::WriteCallback {
public: public:
explicit BlockingWriteClient(AsyncSSLSocket::UniquePtr socket) explicit BlockingWriteClient(AsyncSSLSocket::UniquePtr socket)
: socket_(std::move(socket)), bufLen_(2500), iovCount_(2000) { : socket_(std::move(socket)), bufLen_(2500), iovCount_(2000) {
...@@ -829,7 +829,7 @@ class BlockingWriteClient : private AsyncSSLSocket::HandshakeCB, ...@@ -829,7 +829,7 @@ class BlockingWriteClient : private AsyncSSLSocket::HandshakeCB,
}; };
class BlockingWriteServer : private AsyncSSLSocket::HandshakeCB, class BlockingWriteServer : private AsyncSSLSocket::HandshakeCB,
private AsyncTransportWrapper::ReadCallback { private AsyncTransport::ReadCallback {
public: public:
explicit BlockingWriteServer(AsyncSSLSocket::UniquePtr socket) explicit BlockingWriteServer(AsyncSSLSocket::UniquePtr socket)
: socket_(std::move(socket)), bufSize_(2500 * 2000), bytesRead_(0) { : socket_(std::move(socket)), bufSize_(2500 * 2000), bytesRead_(0) {
...@@ -898,7 +898,7 @@ class BlockingWriteServer : private AsyncSSLSocket::HandshakeCB, ...@@ -898,7 +898,7 @@ class BlockingWriteServer : private AsyncSSLSocket::HandshakeCB,
}; };
class AlpnClient : private AsyncSSLSocket::HandshakeCB, class AlpnClient : private AsyncSSLSocket::HandshakeCB,
private AsyncTransportWrapper::WriteCallback { private AsyncTransport::WriteCallback {
public: public:
explicit AlpnClient(AsyncSSLSocket::UniquePtr socket) explicit AlpnClient(AsyncSSLSocket::UniquePtr socket)
: nextProto(nullptr), nextProtoLength(0), socket_(std::move(socket)) { : nextProto(nullptr), nextProtoLength(0), socket_(std::move(socket)) {
...@@ -932,7 +932,7 @@ class AlpnClient : private AsyncSSLSocket::HandshakeCB, ...@@ -932,7 +932,7 @@ class AlpnClient : private AsyncSSLSocket::HandshakeCB,
}; };
class AlpnServer : private AsyncSSLSocket::HandshakeCB, class AlpnServer : private AsyncSSLSocket::HandshakeCB,
private AsyncTransportWrapper::ReadCallback { private AsyncTransport::ReadCallback {
public: public:
explicit AlpnServer(AsyncSSLSocket::UniquePtr socket) explicit AlpnServer(AsyncSSLSocket::UniquePtr socket)
: nextProto(nullptr), nextProtoLength(0), socket_(std::move(socket)) { : nextProto(nullptr), nextProtoLength(0), socket_(std::move(socket)) {
...@@ -967,7 +967,7 @@ class AlpnServer : private AsyncSSLSocket::HandshakeCB, ...@@ -967,7 +967,7 @@ class AlpnServer : private AsyncSSLSocket::HandshakeCB,
}; };
class RenegotiatingServer : public AsyncSSLSocket::HandshakeCB, class RenegotiatingServer : public AsyncSSLSocket::HandshakeCB,
public AsyncTransportWrapper::ReadCallback { public AsyncTransport::ReadCallback {
public: public:
explicit RenegotiatingServer(AsyncSSLSocket::UniquePtr socket) explicit RenegotiatingServer(AsyncSSLSocket::UniquePtr socket)
: socket_(std::move(socket)) { : socket_(std::move(socket)) {
...@@ -1010,7 +1010,7 @@ class RenegotiatingServer : public AsyncSSLSocket::HandshakeCB, ...@@ -1010,7 +1010,7 @@ class RenegotiatingServer : public AsyncSSLSocket::HandshakeCB,
#ifndef OPENSSL_NO_TLSEXT #ifndef OPENSSL_NO_TLSEXT
class SNIClient : private AsyncSSLSocket::HandshakeCB, class SNIClient : private AsyncSSLSocket::HandshakeCB,
private AsyncTransportWrapper::WriteCallback { private AsyncTransport::WriteCallback {
public: public:
explicit SNIClient(AsyncSSLSocket::UniquePtr socket) explicit SNIClient(AsyncSSLSocket::UniquePtr socket)
: serverNameMatch(false), socket_(std::move(socket)) { : serverNameMatch(false), socket_(std::move(socket)) {
...@@ -1042,7 +1042,7 @@ class SNIClient : private AsyncSSLSocket::HandshakeCB, ...@@ -1042,7 +1042,7 @@ class SNIClient : private AsyncSSLSocket::HandshakeCB,
}; };
class SNIServer : private AsyncSSLSocket::HandshakeCB, class SNIServer : private AsyncSSLSocket::HandshakeCB,
private AsyncTransportWrapper::ReadCallback { private AsyncTransport::ReadCallback {
public: public:
explicit SNIServer( explicit SNIServer(
AsyncSSLSocket::UniquePtr socket, AsyncSSLSocket::UniquePtr socket,
...@@ -1098,8 +1098,8 @@ class SNIServer : private AsyncSSLSocket::HandshakeCB, ...@@ -1098,8 +1098,8 @@ class SNIServer : private AsyncSSLSocket::HandshakeCB,
#endif #endif
class SSLClient : public AsyncSocket::ConnectCallback, class SSLClient : public AsyncSocket::ConnectCallback,
public AsyncTransportWrapper::WriteCallback, public AsyncTransport::WriteCallback,
public AsyncTransportWrapper::ReadCallback { public AsyncTransport::ReadCallback {
private: private:
EventBase* eventBase_; EventBase* eventBase_;
std::shared_ptr<AsyncSSLSocket> sslSocket_; std::shared_ptr<AsyncSSLSocket> sslSocket_;
...@@ -1251,7 +1251,7 @@ class SSLClient : public AsyncSocket::ConnectCallback, ...@@ -1251,7 +1251,7 @@ class SSLClient : public AsyncSocket::ConnectCallback,
}; };
class SSLHandshakeBase : public AsyncSSLSocket::HandshakeCB, class SSLHandshakeBase : public AsyncSSLSocket::HandshakeCB,
private AsyncTransportWrapper::WriteCallback { private AsyncTransport::WriteCallback {
public: public:
explicit SSLHandshakeBase( explicit SSLHandshakeBase(
AsyncSSLSocket::UniquePtr socket, AsyncSSLSocket::UniquePtr socket,
......
...@@ -56,8 +56,8 @@ struct EvbAndContext { ...@@ -56,8 +56,8 @@ struct EvbAndContext {
}; };
class AttachDetachClient : public AsyncSocket::ConnectCallback, class AttachDetachClient : public AsyncSocket::ConnectCallback,
public AsyncTransportWrapper::WriteCallback, public AsyncTransport::WriteCallback,
public AsyncTransportWrapper::ReadCallback { public AsyncTransport::ReadCallback {
private: private:
// two threads here - we'll create the socket in one, connect // two threads here - we'll create the socket in one, connect
// in the other, and then read/write in the initial one // in the other, and then read/write in the initial one
......
...@@ -55,7 +55,7 @@ class ConnCallback : public folly::AsyncSocket::ConnectCallback { ...@@ -55,7 +55,7 @@ class ConnCallback : public folly::AsyncSocket::ConnectCallback {
VoidCallback errorCallback; VoidCallback errorCallback;
}; };
class WriteCallback : public folly::AsyncTransportWrapper::WriteCallback { class WriteCallback : public folly::AsyncTransport::WriteCallback {
public: public:
WriteCallback() WriteCallback()
: state(STATE_WAITING), : state(STATE_WAITING),
...@@ -88,7 +88,7 @@ class WriteCallback : public folly::AsyncTransportWrapper::WriteCallback { ...@@ -88,7 +88,7 @@ class WriteCallback : public folly::AsyncTransportWrapper::WriteCallback {
VoidCallback errorCallback; VoidCallback errorCallback;
}; };
class ReadCallback : public folly::AsyncTransportWrapper::ReadCallback { class ReadCallback : public folly::AsyncTransport::ReadCallback {
public: public:
explicit ReadCallback(size_t _maxBufferSz = 4096) explicit ReadCallback(size_t _maxBufferSz = 4096)
: state(STATE_WAITING), : state(STATE_WAITING),
......
...@@ -23,8 +23,8 @@ ...@@ -23,8 +23,8 @@
#include <folly/net/NetworkSocket.h> #include <folly/net/NetworkSocket.h>
class BlockingSocket : public folly::AsyncSocket::ConnectCallback, class BlockingSocket : public folly::AsyncSocket::ConnectCallback,
public folly::AsyncTransportWrapper::ReadCallback, public folly::AsyncTransport::ReadCallback,
public folly::AsyncTransportWrapper::WriteCallback { public folly::AsyncTransport::WriteCallback {
public: public:
explicit BlockingSocket(folly::NetworkSocket fd) explicit BlockingSocket(folly::NetworkSocket fd)
: sock_(new folly::AsyncSocket(&eventBase_, fd)) {} : sock_(new folly::AsyncSocket(&eventBase_, fd)) {}
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
namespace folly { namespace folly {
namespace test { namespace test {
class MockAsyncTransport : public AsyncTransportWrapper { class MockAsyncTransport : public AsyncTransport {
public: public:
MOCK_METHOD1(setReadCB, void(ReadCallback*)); MOCK_METHOD1(setReadCB, void(ReadCallback*));
MOCK_CONST_METHOD0(getReadCallback, ReadCallback*()); MOCK_CONST_METHOD0(getReadCallback, ReadCallback*());
...@@ -64,7 +64,7 @@ class MockAsyncTransport : public AsyncTransportWrapper { ...@@ -64,7 +64,7 @@ class MockAsyncTransport : public AsyncTransportWrapper {
MOCK_CONST_METHOD0(getRawBytesReceived, size_t()); MOCK_CONST_METHOD0(getRawBytesReceived, size_t());
MOCK_CONST_METHOD0(isEorTrackingEnabled, bool()); MOCK_CONST_METHOD0(isEorTrackingEnabled, bool());
MOCK_METHOD1(setEorTracking, void(bool)); MOCK_METHOD1(setEorTracking, void(bool));
MOCK_CONST_METHOD0(getWrappedTransport, AsyncTransportWrapper*()); MOCK_CONST_METHOD0(getWrappedTransport, AsyncTransport*());
MOCK_CONST_METHOD0(isReplaySafe, bool()); MOCK_CONST_METHOD0(isReplaySafe, bool());
MOCK_METHOD1( MOCK_METHOD1(
setReplaySafetyCallback, setReplaySafetyCallback,
...@@ -80,7 +80,7 @@ class MockReplaySafetyCallback : public AsyncTransport::ReplaySafetyCallback { ...@@ -80,7 +80,7 @@ class MockReplaySafetyCallback : public AsyncTransport::ReplaySafetyCallback {
} }
}; };
class MockReadCallback : public AsyncTransportWrapper::ReadCallback { class MockReadCallback : public AsyncTransport::ReadCallback {
public: public:
MOCK_METHOD2(getReadBuffer, void(void**, size_t*)); MOCK_METHOD2(getReadBuffer, void(void**, size_t*));
...@@ -111,7 +111,7 @@ class MockReadCallback : public AsyncTransportWrapper::ReadCallback { ...@@ -111,7 +111,7 @@ class MockReadCallback : public AsyncTransportWrapper::ReadCallback {
} }
}; };
class MockWriteCallback : public AsyncTransportWrapper::WriteCallback { class MockWriteCallback : public AsyncTransport::WriteCallback {
public: public:
MOCK_METHOD0(writeSuccess_, void()); MOCK_METHOD0(writeSuccess_, void());
void writeSuccess() noexcept override { void writeSuccess() noexcept override {
......
...@@ -25,16 +25,15 @@ namespace folly { ...@@ -25,16 +25,15 @@ namespace folly {
namespace test { namespace test {
class TestWriteChainAsyncTransportWrapper class TestWriteChainAsyncTransportWrapper
: public WriteChainAsyncTransportWrapper<folly::AsyncTransportWrapper> { : public WriteChainAsyncTransportWrapper<folly::AsyncTransport> {
public: public:
TestWriteChainAsyncTransportWrapper() TestWriteChainAsyncTransportWrapper()
: WriteChainAsyncTransportWrapper<folly::AsyncTransportWrapper>(nullptr) { : WriteChainAsyncTransportWrapper<folly::AsyncTransport>(nullptr) {}
}
MOCK_METHOD3( MOCK_METHOD3(
writeChain, writeChain,
void( void(
folly::AsyncTransportWrapper::WriteCallback*, folly::AsyncTransport::WriteCallback*,
std::shared_ptr<folly::IOBuf>, std::shared_ptr<folly::IOBuf>,
folly::WriteFlags)); folly::WriteFlags));
......
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