-
Notifications
You must be signed in to change notification settings - Fork 3k
Socket closing improvements and tests adjustments #8499
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
Conversation
purpose = "Test that TCPSocket::bind(), TCPSocket::listen() and TCPSocket::accept() works", | ||
status = "released", | ||
component= ["mbed-os", "netsocket"], | ||
author = "Juha Ylinen <[email protected]>", |
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.
Don't copy&paste the author line.. You can remove the whole line. It is not used anywhere.
"duts": { | ||
'*': { #requirements for all nodes | ||
"count":2, | ||
"type": "hardware" |
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 is still missing the application field.
@@ -56,17 +61,15 @@ nsapi_error_t InternetSocket::close() | |||
_lock.lock(); | |||
|
|||
nsapi_error_t ret = NSAPI_ERROR_OK; | |||
if (!_stack) { | |||
if (!_socket) { | |||
return ret; |
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.
It should return NSAPI_ERROR_NO_SOCKET
self.command("dut2", "socket " + str(self.client_socket_id) + " delete") | ||
self.command("dut1", "socket " + str(server_socket_id) + " close") | ||
self.command("dut1", "socket " + str(server_base_socket_id) + " close") | ||
self.command("dut2", "socket " + str(self.client_socket_id) + " close") |
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.
Could you please move these close-commands to teardown section.
If the test case raise error, then the close-commands are never called
raise TestStepFail("Received data doesn't match the sent data") | ||
|
||
response = self.command("dut1", "socket " + str(self.server_base_socket_id) + " close") | ||
response = self.command("dut1", "socket " + str(socket_id) + " close") |
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.
Could you please move these close-commands to teardown section.
If the test case raise error, then the close-commands are never called
@@ -72,7 +72,7 @@ def case(self): | |||
if data != sentData: | |||
raise TestStepFail("Received data doesn't match the sent data") | |||
|
|||
self.command("dut1", "socket " + str(socket_id) + " delete") | |||
self.command("dut1", "socket " + str(socket_id) + " close") |
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.
Same as above comment
200f975
to
45a7bb3
Compare
@michalpasztamobica When you push an update (more important after review comments), please write a comment here what has changed - to notify reviewers this is ready for another round of reviews. The question is - is it now? |
@SeppoTakalo , the code is ready for review if you agree with my responses to the questions you raised. What I changed:
|
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 changes still required.
Also, make sure your editor is set to use 4 spaces as a indentation. Not tabs.
Some intends seems off
return handle_nsapi_error("TCPServer::listen()", static_cast<TCPServer &>(info->socket()).listen(backlog)); | ||
if (info->type() == SInfo::TCP_SERVER) { | ||
return handle_nsapi_error("TCPServer::listen()", static_cast<TCPServer &>(info->socket()).listen(backlog)); | ||
} else if (info->type() == SInfo::TCP_CLIENT) { |
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 type has to be TCP_CLIENT
or TCP_SERVER
the Socket::listen()
is in the abstract API., so we could call
if (cmd_parameter_int(argc, argv, "listen", &backlog)) {
return handle_nsapi_error("Socket::listen()", info->socket().listen(backlog));
new_info->id(), addr.get_ip_address(), addr.get_port()); | ||
} | ||
return handle_nsapi_error("TCPServer::accept()", ret); | ||
nsapi_error_t ret; |
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.
Wrong intend here
return handle_nsapi_error("TCPServer::accept()", ret); | ||
nsapi_error_t ret; | ||
if (info->type() != SInfo::TCP_SERVER) { | ||
TCPSocket *new_sock = static_cast<TCPSocket &>(info->socket()).accept(&ret); |
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.
No, not TCPSocket
, we should be able to use any socket here.
So Socket *new_sock = info->socket().accept(&ret);
interface = interfaceUp(self, ["dut2"]) | ||
self.client_ip = interface["dut2"]["ip"] | ||
#response = self.command("dut1", "ifup") | ||
#response = self.command("dut2", "ifup") |
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 these
And.. those The |
45a7bb3
to
1226b97
Compare
5f23045
to
7c16ea3
Compare
@SeppoTakalo , please review |
7c16ea3
to
2c11a07
Compare
@KariHaapalehto review the update |
/morph build |
Build : SUCCESSBuild number : 3464 Triggering tests/morph test |
Test : FAILUREBuild number : 3255 |
Exporter Build : SUCCESSBuild number : 3087 |
Test failures revealed that I did not adjust them to the changes we made. |
Private constructor called in TCPSocket accept, when creating a new Socket. Close() method calls moved "up" to InternetSocket. InternetSocket::close() returns proper error code when no socket available. Add TcpSocket::accept icetea tests. Deleting sockets moved to teardown.
2c11a07
to
0da0f16
Compare
I just pushed a fix agreed with @SeppoTakalo . |
/morph build |
Build : SUCCESSBuild number : 3476 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 3096 |
Test : SUCCESSBuild number : 3265 |
Description
These changes are an improvement for the hard-fault issue when closing a socket. They are based on the idea described in this and this by @sentinelt.
The API remains unchanged. As per API description: "Referencing a returned pointer after a close() call is not allowed and leads to undefined behaviour." - See Socket.h.
I checked that all Socket-related unittests work fine and do not hard-fault.
In a separate commit there is also a change to icetea tests, to make them behave according to documentation. I also added a new icetea test for TcpSocket::accept() method.
Pull request type