-
Notifications
You must be signed in to change notification settings - Fork 1
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
Remove duplicated NetworkChannel return codes / state #143
Conversation
Benchmark results after merging this PR: Benchmark resultsPerformance:PingPongUc: PingPongC: ReactionLatencyUc: ReactionLatencyC: Memory usage:PingPongUc: PingPongC: ReactionLatencyUc: ReactionLatencyC: |
Memory usage after merging this PR will be: Memory Reportaction_empty_test_c
action_microstep_test_c
action_overwrite_test_c
action_test_c
delayed_conn_test_c
event_payload_pool_test_c
event_queue_test_c
nanopb_test_c
port_test_c
reaction_queue_test_c
request_shutdown_test_c
startup_test_c
tcp_channel_test_c
timer_test_c
|
Okay I think this should be ready for review now :) I am not entirely sure if the runtime internal stuff is implemented correctly. |
case LF_OK: | ||
bundle->network_channel_state_changed(bundle); | ||
ret = chan->try_connect(chan); | ||
if (ret == LF_OK) { |
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.
Shouldn't also the channel state be updated if try_connect failes?
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.
Actually I am not sure because the channel itself should have already notified the bundle, I would need to look deeper into the runtime code tomorrow to see if that is covered
@@ -7,17 +7,15 @@ | |||
#include "net/sock/util.h" | |||
#include <arpa/inet.h> | |||
|
|||
static bool _is_coap_initialized = false; | |||
static bool _is_globals_initialized = false; |
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 need those globals for some kind of handler function?
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 I need Environment
to get the channel bundle list in most callbacks to find the channel based on its socket. (See get_channel_by_remote or similar?)
src/platform/posix/tcp_ip_channel.c
Outdated
@@ -198,7 +210,7 @@ static lf_ret_t TcpIpChannel_check_socket_error(int fd) { | |||
} | |||
} | |||
|
|||
static lf_ret_t TcpIpChannel_try_connect_client(NetworkChannel *untyped_self) { | |||
static lf_ret_t _try_connect_client(NetworkChannel *untyped_self) { |
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.
the underscore is indicating that this is a "private" member function?
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 as far as I understood it the TcpIpChannel Prefix is to mark the functions that implement the interface, so all other internal code structuring functions are easier to differentiate with for example included functions by using underscore to mark them as private
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 am fine with this convention. But I would also be fine with omitting the _
, since the functions are static they will not be visible outside this file anyways.
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.
For me the main advantage of it is to help differentiate between our own static functions and for example included library functions. I can directly see that for example send_coap_message
is a private function and not a RIOT coap API function.
But I also don't have a strong opinion on it
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 mean within that c file of course
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 say:
TcpIpChannel_
means that it is a public facing API through function pointers on a struct, or through the header. _TcpIpChannel_
means private helper functions
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.
Which is in accordance with the first
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 you agree, then could you update the naming so its in accordance with this, and then we can merge this?
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 no problem
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 ;)
src/platform/posix/tcp_ip_channel.c
Outdated
return LF_CONNECTION_CLOSED; | ||
LF_INFO(NET, "Connection closed. Setting last known tag to FOREVER for all input ports"); | ||
if (self->federated_connection) { | ||
self->federated_connection->network_channel_state_changed(self->federated_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 I remember correctly, we talked about removing this call altogether and rely on the runtime checking the network channel state before waiting for input ports to become known at a tag.
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 looks good, I believe this is the first of a two-stage change and I think my questions are both things that will be done in the next stage?
src/federated.c
Outdated
case LF_OK: | ||
break; | ||
case LF_CONNECTION_CLOSED: | ||
if (channel->send_blocking(channel, &msg) != LF_OK) { | ||
self->bundle->network_channel_state_changed(self->bundle); |
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 we remove this "callback"-way of handling network-channel state updates (see my other comment), then this call should probably also be dropped. Instead we check the network channel state each time before going to sleep waiting for some input port to become known at a tag
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.
Regarding all the callback comments I think that change should go into the second PR. I tried to keep the scope of this one only within the deduplication of the return code and state :)
src/platform/posix/tcp_ip_channel.c
Outdated
@@ -198,7 +210,7 @@ static lf_ret_t TcpIpChannel_check_socket_error(int fd) { | |||
} | |||
} | |||
|
|||
static lf_ret_t TcpIpChannel_try_connect_client(NetworkChannel *untyped_self) { | |||
static lf_ret_t _try_connect_client(NetworkChannel *untyped_self) { |
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 am fine with this convention. But I would also be fine with omitting the _
, since the functions are static they will not be visible outside this file anyways.
case NETWORK_CHANNEL_STATE_LOST_CONNECTION: | ||
for (size_t i = 0; i < self->inputs_size; i++) { | ||
FederatedInputConnection *input = self->inputs[i]; | ||
input->last_known_tag = FOREVER_TAG; |
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 think I still don't understand the runtime fully enough, so I am not sure where to set this tag now instead
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 set it in Scheduler_acquire_tag, there we can check the state of the input port before we go to sleep waiting for more messages on it. We can add that in the next PR
Okay so I removed the state_changed callback, but there is one unclear thing remaining (see my comment) |
1bc27d9
to
c45a551
Compare
Okay I implemented the naming convention and rebased with main |
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.
Great stuff Lasse!
Ready to review