-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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 #4181
Conversation
setTransportSocketCallbacks(). Add a new class NoOpTransportSocketCallbacks. Add a utility class NoOpTransportSocketCallbacks to hold back callbacks from underlying socket in a TransportSocket implementation which wraps another socket. move files around Signed-off-by: Dan Zhang <[email protected]> add some implementation to mock class Signed-off-by: Dan Zhang <[email protected]> format Signed-off-by: Dan Zhang <[email protected]> header order Signed-off-by: Dan Zhang <[email protected]> format Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
*/ | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah if you delay creating TransportSocketCallbacks, i.e. in parent setTransportSocketCallbacks, you should be able to just take TransportSocketCallbacks&
here.
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.
That's a good point! Done.
I still keep the callbacks() in TransportSocket interface, as it's convenient to access to callbacks_ for underlying socket.
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
test/mocks/network/mocks.h
Outdated
@@ -428,7 +428,9 @@ class MockTransportSocket : public TransportSocket { | |||
MockTransportSocket(); | |||
~MockTransportSocket(); | |||
|
|||
MOCK_METHOD1(setTransportSocketCallbacks, void(TransportSocketCallbacks& callbacks)); | |||
void setTransportSocketCallbacks(TransportSocketCallbacks& callbacks) override { |
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.
Keep this (and callbacks
below) as a MOCK and do ON_CALL(...).WillByDefault in constructor like:
https://github.com/envoyproxy/envoy/pull/4153/files#diff-f1d609046babf8223367556fbdda1721R206
This will allow test to do EXPECT_CALL etc.
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.
done
/** | ||
* @return the TransportSocketCallbacks object passed in through setTransportSocketCallbacks(). | ||
*/ | ||
virtual TransportSocketCallbacks* callbacks() PURE; |
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.
I would remove this as I think where you need get callbacks
is in the scope you set it. No strong opinion on it though. If this is needed internally, ping me on hangout.
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.
done
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
Signed-off-by: Dan Zhang <[email protected]>
Ping? |
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.
LGTM modulo one comment.
|
||
class TestTransportSocketCallbacks : public Network::TransportSocketCallbacks { | ||
public: | ||
TestTransportSocketCallbacks(Network::Connection* connection) : connection_(connection) {} |
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.
if connection_ couldn't be null, make it a reference. also make constructor explicit
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.
done
Signed-off-by: Dan Zhang <[email protected]>
* No-op for these two methods to hold back the callbacks. | ||
*/ | ||
void setReadBufferReady() override {} | ||
void raiseEvent(Network::ConnectionEvent) override {} |
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.
I'm fine with this landing as is, but can you please loop me in when it is used? I have some concerns about these particular events being swallowed. Maybe we can add ASSERTs that they're not used so we'll at least catch it in debug builds if a mistake is made? Hopefully seeing where the code is used will allay my concerns :-)
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.
ACK'ed
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.
@alyssawilk I will merge master and use this in my PR #4153, ASSERT cannot be added here. In #4153, it have to swallow Connected
event from RawBufferSocket, and raise it when handshake is done.
Signed-off-by: Dan Zhang [email protected]
Description:
Add an implementation of TransportSocketCallbacks which does nothing when setReadBufferReady() or raiseEvent() is call. This implementation is supposed to be used in TransportSocket implementation which wraps another socket object. In this case, the underlying socket's callbacks should be suppressed.
Also add callbacks() in TransportSocket interface which is used to get the callbacks passed to setTransportSocketCallbacks().
Risk Level: Low (not enabled in main)
Testing: bazel test //test/...
Docs Changes: N/A
Release Notes: N/A