Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
27d36d8
Fix MacOS (case) filename clashes
manchoz Jul 6, 2021
357dba7
Add examples
manchoz Jul 6, 2021
c39cfee
Add helpers begin methods
manchoz Feb 1, 2021
05a1b80
Fix WebClient example
manchoz Feb 1, 2021
540e0ab
Add Static IP support
manchoz Jul 5, 2021
a5e512a
Manage Client status
manchoz Jul 5, 2021
d1501d0
Add support for Static Network configuration
manchoz Jul 5, 2021
b04124a
Update examples
manchoz Jul 5, 2021
817b47a
Add forgotten mac parameter
manchoz Jul 5, 2021
cf184fd
Add checks on socket validity before operations
manchoz Jul 6, 2021
9172c17
Manage sockets already connected
manchoz Jul 6, 2021
4aad72b
Add client socket management
manchoz Jul 6, 2021
5f802c1
WiFi: Cleanup libraries and error handling
facchinm Jul 7, 2021
4ded56c
WiFi: make library compliant with Arduino APIs
facchinm Jul 7, 2021
ec4109d
Initial: start moving WiFi generic classes into a standalone library
facchinm Jul 8, 2021
e0e8647
WiFi: port Client and Server to the new wrapper class
facchinm Jul 8, 2021
02b1239
TEMP: MbedClient: add horrible Client "constructor"
facchinm Jul 8, 2021
73cbc6b
WiFi: port UDP to new MbedUdp class
facchinm Jul 8, 2021
175d09f
Ethernet: port library to SocketWrapper
facchinm Jul 8, 2021
37edb74
MbedClient: fix copy constructor
facchinm Jul 8, 2021
974f4c2
Network: cleanup libraries and licenses
facchinm Jul 9, 2021
d4bb9d8
Network: apply clang-format on libraries
facchinm Jul 9, 2021
4340946
MbedUdp: make socket non blocking
facchinm Jul 9, 2021
123694b
SocketWrapper: fix download() API visibility
facchinm Jul 9, 2021
bc92047
MbedUDP: take into account write() errors
facchinm Jul 9, 2021
7fd7c9a
Remove protected leftovers
manchoz Jul 13, 2021
d9fa625
Add EthernetServer::available()
manchoz Jul 13, 2021
8c7962f
Add ::dnsServerIP
manchoz Jul 13, 2021
a175f35
Unlock mutexes before return
manchoz Jul 13, 2021
15ca271
Fix Typo
manchoz Jul 13, 2021
d3e8ee3
Manage copy and assignement
manchoz Jul 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WiFi: Cleanup libraries and error handling
  • Loading branch information
facchinm authored and manchoz committed Jul 14, 2021
commit 5f802c199622885c3c42e12fa45fb752cbaa0492
5 changes: 3 additions & 2 deletions libraries/WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void arduino::WiFiClient::getStatus() {
if (ret < 0 && ret != NSAPI_ERROR_WOULD_BLOCK) {
_status = false;
}
_status = true;
}

int arduino::WiFiClient::connect(SocketAddress socketAddress) {
Expand Down Expand Up @@ -111,14 +112,14 @@ int arduino::WiFiClient::connectSSL(const char *host, uint16_t port) {

size_t arduino::WiFiClient::write(uint8_t c) {
if (sock == nullptr)
return -1;
return 0;
auto ret = sock->send(&c, 1);
return ret;
}

size_t arduino::WiFiClient::write(const uint8_t *buf, size_t size) {
if (sock == nullptr)
return -1;
return 0;

auto ret = sock->send(buf, size);
return ret;
Expand Down
2 changes: 1 addition & 1 deletion libraries/WiFi/src/WiFiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class WiFiClient : public arduino::Client {

public:
WiFiClient();
~WiFiClient() {
virtual ~WiFiClient() {
stop();
}

Expand Down
3 changes: 3 additions & 0 deletions libraries/WiFi/src/WiFiSSLClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ class WiFiSSLClient : public arduino::WiFiClient {

public:
WiFiSSLClient();
virtual ~WiFiSSLClient() {
stop();
}

int connect(IPAddress ip, uint16_t port) {
return connectSSL(ip, port);
Expand Down
23 changes: 18 additions & 5 deletions libraries/WiFi/src/WiFiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,38 @@ uint8_t arduino::WiFiServer::status() {
}

void arduino::WiFiServer::begin() {
if (sock == NULL) {
if (sock == nullptr) {
sock = new TCPSocket();
((TCPSocket*)sock)->open(WiFi.getNetwork());
}
sock->bind(_port);
sock->listen(5);
if (sock) {
sock->bind(_port);
sock->listen(5);
}
}

size_t arduino::WiFiServer::write(uint8_t c) {
sock->send(&c, 1);
if (sock) {
sock->send(&c, 1);
return 1;
}
return 0;
}

size_t arduino::WiFiServer::write(const uint8_t *buf, size_t size) {
sock->send(buf, size);
if (sock) {
sock->send(buf, size);
return size;
}
return 0;
}

arduino::WiFiClient arduino::WiFiServer::available(uint8_t* status) {
WiFiClient client;
nsapi_error_t error;
if (sock == nullptr) {
return client;
}
TCPSocket* clientSocket = sock->accept(&error);
if(status != nullptr) {
*status = error == NSAPI_ERROR_OK ? 1 : 0;
Expand Down
8 changes: 7 additions & 1 deletion libraries/WiFi/src/WiFiServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,15 @@ class WiFiClient;
class WiFiServer : public arduino::Server {
private:
uint16_t _port;
TCPSocket* sock;
TCPSocket* sock = nullptr;
public:
WiFiServer(uint16_t);
virtual ~WiFiServer() {
if (sock) {
delete sock;
sock = nullptr;
}
}
arduino::WiFiClient available(uint8_t* status = NULL);
void begin();
virtual size_t write(uint8_t);
Expand Down