-
-
Notifications
You must be signed in to change notification settings - Fork 345
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
TCP improvements #1595
TCP improvements #1595
Conversation
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.
Small things to double-check.
Sming/SmingCore/Network/MqttClient.h
Outdated
#include "Data/ObjectQueue.h" | ||
#include "Mqtt/MqttPayloadParser.h" | ||
#include "../mqtt-codec/src/message.h" | ||
#include "../mqtt-codec/src/serialiser.h" | ||
#include "../mqtt-codec/src/parser.h" | ||
#include <functional> | ||
//#include <functional> |
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.
Remove the commented line.
@@ -316,9 +322,9 @@ class MqttClient : protected TcpClient | |||
|
|||
#ifndef MQTT_NO_COMPAT | |||
// @deprecated | |||
MqttMessageDeliveredCallback onDelivery = 0; | |||
MqttMessageDeliveredCallback onDelivery = nullptr; |
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.
Since these are the old-style C++ delegates I think that using nullptr instead of 0 will not work as expected. I seem to recall that we already had such an issue but I am not 100% certain.
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.
Should match Delegate(FunctionDeclaration m)
constructor as FunctionDeclaration
is a pointer type ReturnType (*FunctionDeclaration)(ParamsList...)
. Can't see how else it could be interpreted?
// @deprecated | ||
MqttStringSubscriptionCallback subscriptionCallback = 0; | ||
MqttStringSubscriptionCallback subscriptionCallback = nullptr; |
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.
Using nullptr instead of 0 for old-style C++ delegates might not work as expected. Has to be checked.
@@ -228,6 +268,16 @@ class TcpConnection | |||
virtual err_t onSslConnected(SSL* ssl); | |||
#endif | |||
|
|||
// These do most of the work - called from static methods | |||
err_t tcpOnConnected(err_t err); |
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.
Can you rename the tcpOn*
to interalOn*
? Otherwise having staticOnConnect, tcpOnConnect, onConnect will cause additional confusion as to which method is the right one to use.
While internalOn*
might be a bit better than tcpOn*
and not quite happy with it so I am also open to suggestions from your side.
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.
We could adopt the LWIP convention e.g. tcp_connected
instead of tcpOnConnect
to indicate it's all happening at a lower level. Could do the same with the static methods, e.g. static_tcp_connected
.
It would be helpful to have a consistent naming convention for these 'glue' functions/methods. Closures could replace the static
methods but in this instance I think keeping the static methods makes the code easier to follow.
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.
Just noticed, we already have an internalTcpConnect
!
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.
This will come up again handling HTTP and Websocket parser callbacks. These are simpler though as the static methods are all virtually identical (just a null pointer check then call the method). Both parsers use a function table, so I adopted the same names as those to help make things clearer, e.g. HttpConnection::on_message_begin
.
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.
Just noticed, we already have an
internalTcpConnect
!
Nice catch :)
For consistency I can suggest the following method renames:
internalTcpConnect -> internalConnect
tcpOn* -> internalOn* (Ex: tcpOnConnected -> internalOnConnected )
Can you do that change? And don't forget to remove the commented line 20 in Sming/SmingCore/Network/MqttClient.h.
Consistent use of braces Tidy #includes NULL -> nullptr Move trivial code into header Some methods are const Ensure ALL member variables have initializers; remove corresponding redundant assignments from constructors Used unsigned types where appropriate
b7c40bd
to
d879a47
Compare
…nnect` Remove unused statements Replace commented-out `debug_d` statements with `debug_tcp`, conditionally defined
d879a47
to
41041f2
Compare
@mikee47 Is the PR tested from your side and ready for merging or you plan to add more changes? |
That's it for this PR. |
Consistent use of braces
Tidy #includes
NULL -> nullptr
Move trivial code into header
Some methods are const
Ensure ALL member variables have initializers; remove corresponding redundant assignments from constructors
Used unsigned types where appropriate
Remove
TcpServer
as friend ofTcpConnection
, use accessor methods insteadTcpConnection
: Move callback handler code out of static methods