-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add an unused implementation NoOpTransportSocketCallbacks #4172
Changes from all commits
6626818
4b44ddb
140b6d8
7b84d10
98015bd
f7dcb67
c3bb177
c518b82
f231f18
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "envoy/network/transport_socket.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace TransportSockets { | ||
namespace Alts { | ||
|
||
/** | ||
* A TransportSocketCallbacks for wrapped TransportSocket object. Some | ||
* TransportSocket implementation wraps another socket which does actual I/O. | ||
* This class is used by the wrapped socket as its callbacks instead of the real | ||
* connection to hold back callbacks from the underlying socket to connection. | ||
*/ | ||
class NoOpTransportSocketCallbacks : public Network::TransportSocketCallbacks { | ||
public: | ||
explicit NoOpTransportSocketCallbacks(Network::TransportSocket* parent) : parent_(parent) {} | ||
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. All you need is parent_->callbacks(), so why just not taking a 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. It depends on the timing when NoOpTransportSocketCallbacks is initialized and parent socket's setTransportSocketCallbacks() is called. In #4153 it is initialized before parent knows its callbacks. It can take a TransportSocketCallbacks** too, but I feel not much more simpler. |
||
|
||
int fd() const override { return parent_->callbacks()->fd(); } | ||
Network::Connection& connection() override { return parent_->callbacks()->connection(); } | ||
bool shouldDrainReadBuffer() override { return false; } | ||
/* | ||
* No-op for these two methods to hold back the callbacks. | ||
*/ | ||
void setReadBufferReady() override {} | ||
void raiseEvent(Network::ConnectionEvent) override {} | ||
|
||
private: | ||
Network::TransportSocket* parent_; | ||
}; | ||
|
||
} // namespace Alts | ||
} // namespace TransportSockets | ||
} // namespace Extensions | ||
} // namespace Envoy |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#include "third_party/envoy/src/include/envoy/network/transport_socket.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace TransportSockets { | ||
|
||
/** | ||
* A TransportSocketCallbacks for wrapped TransportSocket object. Some | ||
* TransportSocket implementation wraps another socket which does actual I/O. | ||
* This class is used by the wrapped socket as its callbacks instead of the real | ||
* connection to hold back callbacks from the underlying socket to connection. | ||
*/ | ||
class NoOpTransportSocketCallbacks : public Network::TransportSocketCallbacks { | ||
public: | ||
explicit NoOpTransportSocketCallbacks(Network::TransportSocket* parent) : parent_(parent) {} | ||
|
||
int fd() const override { return parent_->callbacks()->fd(); } | ||
Network::Connection& connection() override { return parent_->callbacks()->connection(); } | ||
bool shouldDrainReadBuffer() override { return false; } | ||
/* | ||
* No-op for these two methods to hold back the callbacks. | ||
*/ | ||
void setReadBufferReady() override {} | ||
void raiseEvent(Network::ConnectionEvent) override {} | ||
|
||
private: | ||
Network::TransportSocket* parent_; | ||
}; | ||
|
||
} // namespace TransportSockets | ||
} // namespace Extensions | ||
} // Envoy |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#include "extensions/transport_sockets/alts/noop_transport_socket_callbacks.h" | ||
|
||
#include "test/mocks/network/mocks.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace Envoy { | ||
namespace Extensions { | ||
namespace TransportSockets { | ||
namespace Alts { | ||
namespace { | ||
|
||
class TestTransportSocketCallbacks : public Network::TransportSocketCallbacks { | ||
public: | ||
TestTransportSocketCallbacks(Network::Connection* connection) : connection_(connection) {} | ||
|
||
int fd() const override { return 1; } | ||
Network::Connection& connection() override { return *connection_; } | ||
bool shouldDrainReadBuffer() override { return false; } | ||
void setReadBufferReady() override { set_read_buffer_ready_ = true; } | ||
void raiseEvent(Network::ConnectionEvent) override { event_raised_ = true; } | ||
|
||
bool event_raised() const { return event_raised_; } | ||
bool set_read_buffer_ready() const { return set_read_buffer_ready_; } | ||
|
||
private: | ||
bool event_raised_{false}; | ||
bool set_read_buffer_ready_{false}; | ||
Network::Connection* connection_; | ||
}; | ||
|
||
class NoOpTransportSocketCallbacksTest : public testing::Test { | ||
protected: | ||
NoOpTransportSocketCallbacksTest() | ||
: wrapper_callbacks_(&connection_), wrapped_callbacks_(&wrapper_socket_) { | ||
wrapper_socket_.setTransportSocketCallbacks(wrapper_callbacks_); | ||
} | ||
|
||
Network::MockConnection connection_; | ||
TestTransportSocketCallbacks wrapper_callbacks_; | ||
Network::MockTransportSocket wrapper_socket_; | ||
NoOpTransportSocketCallbacks wrapped_callbacks_; | ||
}; | ||
|
||
TEST_F(NoOpTransportSocketCallbacksTest, TestAllCallbacks) { | ||
EXPECT_EQ(wrapper_callbacks_.fd(), wrapped_callbacks_.fd()); | ||
EXPECT_EQ(&connection_, &wrapped_callbacks_.connection()); | ||
EXPECT_FALSE(wrapped_callbacks_.shouldDrainReadBuffer()); | ||
|
||
wrapped_callbacks_.setReadBufferReady(); | ||
EXPECT_FALSE(wrapper_callbacks_.set_read_buffer_ready()); | ||
wrapped_callbacks_.raiseEvent(Network::ConnectionEvent::Connected); | ||
EXPECT_FALSE(wrapper_callbacks_.event_raised()); | ||
} | ||
|
||
} // namespace | ||
} // namespace Alts | ||
} // namespace TransportSockets | ||
} // namespace Extensions | ||
} // namespace Envoy |
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.
Why do you need this? (see comments on NoOpTransportSocketCallbacks too)