Skip to content
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

WiFi library - os crash on Giga R1 when WiFiClient global #753

Closed
megacct opened this issue Nov 7, 2023 · 8 comments
Closed

WiFi library - os crash on Giga R1 when WiFiClient global #753

megacct opened this issue Nov 7, 2023 · 8 comments

Comments

@megacct
Copy link

megacct commented Nov 7, 2023

As per the thread below, os crashes on Giga R1 when WiFiClient is declared as global.

https://forum.arduino.cc/t/call-to-server-available-fails-if-client-is-a-global-variable/1137604

@alranel
Copy link
Member

alranel commented Nov 7, 2023

This seems to be caused by the way the assignment operator of WiFiClient is implemented:

void copyClient(const MbedClient& orig) {
auto _sock = orig.sock;
auto _m = (MbedClient*)&orig;
_m->borrowed_socket = true;
_m->stop();
this->setSocket(_sock);
}
public:
MbedClient();
// Copy constructor, to be used when a Client returned by server.available()
// needs to "survive" event if it goes out of scope
// Sample usage: Client* new_client = new Client(existing_client)
MbedClient(const MbedClient& orig) {
copyClient(orig);
}
MbedClient& operator=(const MbedClient& orig) {
copyClient(orig);
return *this;
}

When doing client = server.available() as in the linked example from the forum, stop() is called on the newly returned client object.

@alranel
Copy link
Member

alranel commented Nov 7, 2023

@facchinm if I understand correctly the logic that this helper method implements, why don't we use shared_ptr instead?

@megacct
Copy link
Author

megacct commented Nov 13, 2023

@facchinm @alranel guys, any update regarding this issue? This functionality is essential for me and a blocker to my GIGA migration. Thanks for all the work

@facchinm
Copy link
Member

We are working on it, don't worry

@rickclemenzi
Copy link

rickclemenzi commented Dec 12, 2023

The root problem described is solved in #766, but there are more: status() is not returning WL_CONNECTED when it is connected. It's returning '1' which per wl_definitions.h is WL_NO_SSID_AVAIL. It did connect to a known SSID so this cannot be correct.

@JAndrassy
Copy link
Contributor

JAndrassy commented Dec 12, 2023

@rickclemenzi client.status() doesn't return WL_ constants. it should return TCP states
https://github.com/JAndrassy/Arduino-Networking-API/blob/main/ArduinoNetAPIDev.md#status-optional

@rickclemenzi
Copy link

rickclemenzi commented Dec 12, 2023

@JAndrassy Thanks and I hear you, but there is a significant disconnect here that needs clearing up. WiFi.status() per the online manual is clearly WL_... based, and WiFi.cpp from the mbed_giga library is WL_.. based as well (my address C:\Users\RC2\AppData\Local\Arduino15\packages\arduino\hardware\mbed_giga\4.0.10\libraries\WiFi). It seems there are two half separate library threads involved, but I don't see how the WiFi.cpp is not the one setting status in for WiFiClient. Sorry to be thick, but I don't see how all these facts fit together and would appreciate clarification. The documentation was 100% correct for my earlier ports to the Uno Wifi Rev 2.

Looking again I see there are actually 2 status() definitions at the link you gave -- one your link and https://github.com/JAndrassy/Arduino-Networking-API/blob/main/ArduinoNetAPIDev.md#status

@JAndrassy
Copy link
Contributor

JAndrassy commented Dec 12, 2023

@rickclemenzi this issue is about the WiFiClient and the PR you linked is about Client and Server. why would you mention WiFi.status here?

@megacct megacct closed this as completed Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants