-
Notifications
You must be signed in to change notification settings - Fork 5.5k
listener: fix sharedSocket #17090
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
listener: fix sharedSocket #17090
Changes from 8 commits
759a38b
f142345
f55e317
a12492f
06d434b
14b244a
34e6c6f
df2d945
60cdee7
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 |
|---|---|---|
|
|
@@ -80,6 +80,28 @@ template <typename T> class NetworkListenSocket : public ListenSocketImpl { | |
|
|
||
| Socket::Type socketType() const override { return T::type; } | ||
|
|
||
| // These four overrides are introduced to perform check. A null io handle is possible only if the | ||
| // io handle is listener side. | ||
| IoHandle& ioHandle() override { | ||
| ASSERT(io_handle_ != nullptr); | ||
| return *io_handle_; | ||
| } | ||
| const IoHandle& ioHandle() const override { | ||
| ASSERT(io_handle_ != nullptr); | ||
| return *io_handle_; | ||
| } | ||
| void close() override { | ||
| if (io_handle_ != nullptr) { | ||
|
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. In working through my other change, I'm hitting a similar issue on
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. (i.e. why do no bind listeners even have sockets. I realize this is a much larger change and I'm trying to get through my current mess first, but this seems like something we might want to fix in the future.)
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. SetSocketOption should check bind_to_port w/ or w/o PR. At least ListenSocketImpl::setupSocket has a bind_to_port arg.
Good point! I was thinking about create a derived not-bind-listen-socket and you think deeper |
||
| if (io_handle_->isOpen()) { | ||
| io_handle_->close(); | ||
| } | ||
| } | ||
| } | ||
| bool isOpen() const override { | ||
| ASSERT(io_handle_ != nullptr); | ||
| return io_handle_->isOpen(); | ||
| } | ||
|
|
||
| protected: | ||
| void setPrebindSocketOptions() { | ||
| // On Windows, SO_REUSEADDR does not restrict subsequent bind calls when there is a listener as | ||
|
|
@@ -96,12 +118,6 @@ template <> | |
| inline void | ||
| NetworkListenSocket<NetworkSocketTrait<Socket::Type::Datagram>>::setPrebindSocketOptions() {} | ||
|
|
||
| // UDP listen socket desires io handle regardless bind_to_port is true or false. | ||
| template <> | ||
| NetworkListenSocket<NetworkSocketTrait<Socket::Type::Datagram>>::NetworkListenSocket( | ||
| const Address::InstanceConstSharedPtr& address, | ||
| const Network::Socket::OptionsSharedPtr& options, bool bind_to_port); | ||
|
|
||
| template class NetworkListenSocket<NetworkSocketTrait<Socket::Type::Stream>>; | ||
| template class NetworkListenSocket<NetworkSocketTrait<Socket::Type::Datagram>>; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,9 +75,6 @@ class ActiveQuicListenerFactoryPeer { | |
|
|
||
| class ActiveQuicListenerTest : public QuicMultiVersionTest { | ||
| protected: | ||
| using Socket = | ||
| Network::NetworkListenSocket<Network::NetworkSocketTrait<Network::Socket::Type::Datagram>>; | ||
|
|
||
| ActiveQuicListenerTest() | ||
| : version_(GetParam().first), api_(Api::createApiForTest(simulated_time_system_)), | ||
| dispatcher_(api_->allocateDispatcher("test_thread")), clock_(*dispatcher_), | ||
|
|
@@ -208,7 +205,8 @@ class ActiveQuicListenerTest : public QuicMultiVersionTest { | |
| } | ||
|
|
||
| void sendCHLO(quic::QuicConnectionId connection_id) { | ||
| client_sockets_.push_back(std::make_unique<Socket>(local_address_, nullptr, /*bind*/ false)); | ||
| client_sockets_.push_back(std::make_unique<Network::SocketImpl>(Network::Socket::Type::Datagram, | ||
|
Comment on lines
211
to
+208
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. @mattklein123 With this change, the io_handle == nullptr iff bind_to_port for listensocket, both tcp and udp. Now UDP and TCP listener behavior is now unified including what you pointed out |
||
| local_address_, nullptr)); | ||
| Buffer::OwnedImpl payload = generateChloPacketToSend( | ||
| quic_version_, quic_config_, ActiveQuicListenerPeer::cryptoConfig(*quic_listener_), | ||
| connection_id, clock_, envoyIpAddressToQuicSocketAddress(local_address_->ip()), | ||
|
|
@@ -317,7 +315,7 @@ class ActiveQuicListenerTest : public QuicMultiVersionTest { | |
| Init::MockManager init_manager_; | ||
| NiceMock<ProtobufMessage::MockValidationVisitor> validation_visitor_; | ||
|
|
||
| std::list<std::unique_ptr<Socket>> client_sockets_; | ||
| std::list<std::unique_ptr<Network::SocketImpl>> client_sockets_; | ||
| std::list<std::shared_ptr<Network::MockReadFilter>> read_filters_; | ||
| Network::MockFilterChainManager filter_chain_manager_; | ||
| // The following two containers must guarantee pointer stability as addresses | ||
|
|
||
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.
What does "is listener side" mean? Clarify?
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.
Updated to
Is it better?