mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-11-07 22:46:22 +03:00
Move core functionality to QuicTransportBaseLite [3/n]
Summary: See title. Reviewed By: mjoras Differential Revision: D63917728 fbshipit-source-id: 4e5389c1747b59cf30fea37ed9e5802007f2e49b
This commit is contained in:
committed by
Facebook GitHub Bot
parent
e5c822b9d4
commit
5a9ebd333d
@@ -179,20 +179,8 @@ class QuicSocket : virtual public QuicSocketLite {
|
||||
*/
|
||||
virtual const folly::SocketAddress& getLocalAddress() const = 0;
|
||||
|
||||
/**
|
||||
* Determine if transport is open and ready to read or write.
|
||||
*
|
||||
* return true iff the transport is open and ready, false otherwise.
|
||||
*/
|
||||
virtual bool good() const = 0;
|
||||
|
||||
virtual bool replaySafe() const = 0;
|
||||
|
||||
/**
|
||||
* Determine if an error has occurred with this transport.
|
||||
*/
|
||||
virtual bool error() const = 0;
|
||||
|
||||
/**
|
||||
* Close this socket with a drain period. If closing with an error, it may be
|
||||
* specified.
|
||||
|
||||
@@ -202,6 +202,18 @@ class QuicSocketLite {
|
||||
Optional<QuicErrorCode> streamWriteError;
|
||||
};
|
||||
|
||||
/**
|
||||
* Determine if transport is open and ready to read or write.
|
||||
*
|
||||
* return true iff the transport is open and ready, false otherwise.
|
||||
*/
|
||||
virtual bool good() const = 0;
|
||||
|
||||
/**
|
||||
* Determine if an error has occurred with this transport.
|
||||
*/
|
||||
virtual bool error() const = 0;
|
||||
|
||||
/**
|
||||
* Sets connection setup callback. This callback must be set before using the
|
||||
* socket.
|
||||
|
||||
@@ -186,18 +186,10 @@ QuicTransportBase::~QuicTransportBase() {
|
||||
DCHECK(!socket_.get()); // should be no socket
|
||||
}
|
||||
|
||||
bool QuicTransportBase::good() const {
|
||||
return closeState_ == CloseState::OPEN && hasWriteCipher() && !error();
|
||||
}
|
||||
|
||||
bool QuicTransportBase::replaySafe() const {
|
||||
return (conn_->oneRttWriteCipher != nullptr);
|
||||
}
|
||||
|
||||
bool QuicTransportBase::error() const {
|
||||
return conn_->localConnectionError.has_value();
|
||||
}
|
||||
|
||||
void QuicTransportBase::close(Optional<QuicError> errorCode) {
|
||||
[[maybe_unused]] auto self = sharedGuard();
|
||||
// The caller probably doesn't need a conn callback any more because they
|
||||
|
||||
@@ -27,8 +27,6 @@
|
||||
|
||||
namespace quic {
|
||||
|
||||
enum class CloseState { OPEN, GRACEFUL_CLOSING, CLOSED };
|
||||
|
||||
/**
|
||||
* Base class for the QUIC Transport. Implements common behavior for both
|
||||
* clients and servers. QuicTransportBase assumes the following:
|
||||
@@ -70,12 +68,8 @@ class QuicTransportBase : public QuicSocket,
|
||||
const std::shared_ptr<QLogger> getQLogger() const;
|
||||
|
||||
// QuicSocket interface
|
||||
bool good() const override;
|
||||
|
||||
bool replaySafe() const override;
|
||||
|
||||
bool error() const override;
|
||||
|
||||
void close(Optional<QuicError> error) override;
|
||||
|
||||
void closeGracefully() override;
|
||||
@@ -314,12 +308,6 @@ class QuicTransportBase : public QuicSocket,
|
||||
*/
|
||||
virtual void unbindConnection() = 0;
|
||||
|
||||
/**
|
||||
* Returns whether or not the connection has a write cipher. This will be used
|
||||
* to decide to return the onTransportReady() callbacks.
|
||||
*/
|
||||
virtual bool hasWriteCipher() const = 0;
|
||||
|
||||
/**
|
||||
* Returns a shared_ptr which can be used as a guard to keep this
|
||||
* object alive.
|
||||
@@ -873,7 +861,6 @@ class QuicTransportBase : public QuicSocket,
|
||||
|
||||
QuicSocket::WriteCallback* connWriteCallback_{nullptr};
|
||||
std::map<StreamId, QuicSocket::WriteCallback*> pendingWriteCallbacks_;
|
||||
CloseState closeState_{CloseState::OPEN};
|
||||
bool transportReadyNotified_{false};
|
||||
bool handshakeDoneNotified_{false};
|
||||
|
||||
|
||||
@@ -14,6 +14,14 @@ constexpr auto APP_NO_ERROR = quic::GenericApplicationErrorCode::NO_ERROR;
|
||||
|
||||
namespace quic {
|
||||
|
||||
bool QuicTransportBaseLite::good() const {
|
||||
return closeState_ == CloseState::OPEN && hasWriteCipher() && !error();
|
||||
}
|
||||
|
||||
bool QuicTransportBaseLite::error() const {
|
||||
return conn_->localConnectionError.has_value();
|
||||
}
|
||||
|
||||
void QuicTransportBaseLite::setConnectionSetupCallback(
|
||||
folly::MaybeManagedPtr<ConnectionSetupCallback> callback) {
|
||||
connSetupCallback_ = callback;
|
||||
|
||||
@@ -11,11 +11,23 @@
|
||||
|
||||
namespace quic {
|
||||
|
||||
enum class CloseState { OPEN, GRACEFUL_CLOSING, CLOSED };
|
||||
|
||||
class QuicTransportBaseLite : virtual public QuicSocketLite {
|
||||
public:
|
||||
QuicTransportBaseLite(bool useConnectionEndWithErrorCallback)
|
||||
: useConnectionEndWithErrorCallback_(useConnectionEndWithErrorCallback) {}
|
||||
|
||||
bool good() const override;
|
||||
|
||||
bool error() const override;
|
||||
|
||||
/**
|
||||
* Returns whether or not the connection has a write cipher. This will be used
|
||||
* to decide to return the onTransportReady() callbacks.
|
||||
*/
|
||||
virtual bool hasWriteCipher() const = 0;
|
||||
|
||||
void setConnectionSetupCallback(
|
||||
folly::MaybeManagedPtr<ConnectionSetupCallback> callback) final;
|
||||
|
||||
@@ -42,6 +54,8 @@ class QuicTransportBaseLite : virtual public QuicSocketLite {
|
||||
void processConnectionSetupCallbacks(QuicError&& cancelCode);
|
||||
void processConnectionCallbacks(QuicError&& cancelCode);
|
||||
|
||||
CloseState closeState_{CloseState::OPEN};
|
||||
|
||||
folly::MaybeManagedPtr<ConnectionSetupCallback> connSetupCallback_{nullptr};
|
||||
folly::MaybeManagedPtr<ConnectionCallback> connCallback_{nullptr};
|
||||
// A flag telling transport if the new onConnectionEnd(error) cb must be used.
|
||||
|
||||
Reference in New Issue
Block a user