-
Notifications
You must be signed in to change notification settings - Fork 5.3k
ClientConnectionImpl: Delay setTransportSocketCallbacks() until end of the constructor. #5307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,6 +44,16 @@ void ConnectionImplUtility::updateBufferStats(uint64_t delta, uint64_t new_total | |
|
|
||
| std::atomic<uint64_t> ConnectionImpl::next_global_id_; | ||
|
|
||
| std::unique_ptr<ConnectionImpl> | ||
| ConnectionImpl::createServerConnection(Event::Dispatcher& dispatcher, ConnectionSocketPtr&& socket, | ||
| TransportSocketPtr&& transport_socket) { | ||
| // make_shared<> requires a public constructor so we can't use it here. | ||
| std::unique_ptr<Network::ConnectionImpl> conn(new Network::ConnectionImpl( | ||
| dispatcher, std::move(socket), std::move(transport_socket), true)); | ||
| conn->transport_socket_->setTransportSocketCallbacks(*conn); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a comment here and below (or just refer one to the other) of why we need to do this for future readers?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will do. |
||
| return conn; | ||
| } | ||
|
|
||
| ConnectionImpl::ConnectionImpl(Event::Dispatcher& dispatcher, ConnectionSocketPtr&& socket, | ||
| TransportSocketPtr&& transport_socket, bool connected) | ||
| : transport_socket_(std::move(transport_socket)), filter_manager_(*this, *this), | ||
|
|
@@ -65,8 +75,6 @@ ConnectionImpl::ConnectionImpl(Event::Dispatcher& dispatcher, ConnectionSocketPt | |
| file_event_ = dispatcher_.createFileEvent( | ||
| fd(), [this](uint32_t events) -> void { onFileEvent(events); }, Event::FileTriggerType::Edge, | ||
| Event::FileReadyType::Read | Event::FileReadyType::Write); | ||
|
|
||
| transport_socket_->setTransportSocketCallbacks(*this); | ||
| } | ||
|
|
||
| ConnectionImpl::~ConnectionImpl() { | ||
|
|
@@ -593,6 +601,18 @@ void ConnectionImpl::onDelayedCloseTimeout() { | |
| closeSocket(ConnectionEvent::LocalClose); | ||
| } | ||
|
|
||
| std::unique_ptr<ClientConnectionImpl> ClientConnectionImpl::createClientConnection( | ||
| Event::Dispatcher& dispatcher, const Address::InstanceConstSharedPtr& remote_address, | ||
| const Address::InstanceConstSharedPtr& source_address, | ||
| Network::TransportSocketPtr&& transport_socket, | ||
| const Network::ConnectionSocket::OptionsSharedPtr& options) { | ||
| // make_shared<> requires a public constructor so we can't use it here. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make_unique?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. |
||
| std::unique_ptr<Network::ClientConnectionImpl> conn(new Network::ClientConnectionImpl( | ||
| dispatcher, remote_address, source_address, std::move(transport_socket), options)); | ||
| conn->transport_socket_->setTransportSocketCallbacks(*conn); | ||
| return conn; | ||
| } | ||
|
|
||
| ClientConnectionImpl::ClientConnectionImpl( | ||
| Event::Dispatcher& dispatcher, const Address::InstanceConstSharedPtr& remote_address, | ||
| const Network::Address::InstanceConstSharedPtr& source_address, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,10 +51,14 @@ class ConnectionImpl : public virtual Connection, | |
| public BufferSource, | ||
| public TransportSocketCallbacks, | ||
| protected Logger::Loggable<Logger::Id::connection> { | ||
| public: | ||
| protected: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: unless it can't be done, please move so the class is defined from public -> protected -> private. Same below.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be doable. |
||
| ConnectionImpl(Event::Dispatcher& dispatcher, ConnectionSocketPtr&& socket, | ||
| TransportSocketPtr&& transport_socket, bool connected); | ||
|
|
||
| public: | ||
| static std::unique_ptr<ConnectionImpl> | ||
| createServerConnection(Event::Dispatcher& dispatcher, ConnectionSocketPtr&& socket, | ||
| TransportSocketPtr&& transport_socket); | ||
| ~ConnectionImpl(); | ||
|
|
||
| // Network::FilterManager | ||
|
|
@@ -200,13 +204,21 @@ class ConnectionImpl : public virtual Connection, | |
| * libevent implementation of Network::ClientConnection. | ||
| */ | ||
| class ClientConnectionImpl : public ConnectionImpl, virtual public ClientConnection { | ||
| public: | ||
| protected: | ||
| ClientConnectionImpl(Event::Dispatcher& dispatcher, | ||
| const Address::InstanceConstSharedPtr& remote_address, | ||
| const Address::InstanceConstSharedPtr& source_address, | ||
| Network::TransportSocketPtr&& transport_socket, | ||
| const Network::ConnectionSocket::OptionsSharedPtr& options); | ||
|
|
||
| public: | ||
| static std::unique_ptr<ClientConnectionImpl> | ||
| createClientConnection(Event::Dispatcher& dispatcher, | ||
| const Address::InstanceConstSharedPtr& remote_address, | ||
| const Address::InstanceConstSharedPtr& source_address, | ||
| Network::TransportSocketPtr&& transport_socket, | ||
| const Network::ConnectionSocket::OptionsSharedPtr& options); | ||
|
|
||
| // Network::ClientConnection | ||
| void connect() override; | ||
| }; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #include "server/config_validation/connection.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Network { | ||
|
|
||
| std::unique_ptr<ConfigValidateConnection> | ||
| ConfigValidateConnection::create(Event::ValidationDispatcher& dispatcher, | ||
| const Address::InstanceConstSharedPtr& remote_address, | ||
| const Address::InstanceConstSharedPtr& source_address, | ||
| Network::TransportSocketPtr&& transport_socket, | ||
| const Network::ConnectionSocket::OptionsSharedPtr& options) { | ||
| // make_shared<> requires a public constructor so we can't use it here. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make_unique?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto. |
||
| std::unique_ptr<ConfigValidateConnection> conn(new ConfigValidateConnection( | ||
| dispatcher, remote_address, source_address, std::move(transport_socket), options)); | ||
| conn->transport_socket_->setTransportSocketCallbacks(*conn); | ||
| return conn; | ||
| } | ||
|
|
||
| } // namespace Network | ||
| } // namespace Envoy | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,7 @@ namespace Network { | |
| overridden with no-op implementations. | ||
| */ | ||
| class ConfigValidateConnection : public Network::ClientConnectionImpl { | ||
| public: | ||
| private: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. order |
||
| ConfigValidateConnection(Event::ValidationDispatcher& dispatcher, | ||
| Network::Address::InstanceConstSharedPtr remote_address, | ||
| Network::Address::InstanceConstSharedPtr source_address, | ||
|
|
@@ -22,6 +22,14 @@ class ConfigValidateConnection : public Network::ClientConnectionImpl { | |
| : Network::ClientConnectionImpl(dispatcher, remote_address, source_address, | ||
| std::move(transport_socket), options) {} | ||
|
|
||
| public: | ||
| static std::unique_ptr<ConfigValidateConnection> | ||
| create(Event::ValidationDispatcher& dispatcher, | ||
| const Address::InstanceConstSharedPtr& remote_address, | ||
| const Address::InstanceConstSharedPtr& source_address, | ||
| Network::TransportSocketPtr&& transport_socket, | ||
| const Network::ConnectionSocket::OptionsSharedPtr& options); | ||
|
|
||
| // Unit tests may instantiate it without proper event machine and leave opened sockets. | ||
| // Do some cleanup before invoking base class's destructor. | ||
| virtual ~ConfigValidateConnection() { close(ConnectionCloseType::NoFlush); } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: You mean make_unique?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will fix.