Skip to content

Commit 9619ec8

Browse files
committed
Drastically speedup client.read() operation
Since the data being consumed by the reader thread is going to be read somewhere via read() APIs (that are known to be fair and call yield()), we can avoid the delay() when the buffer needs to be flushed by setting the reader thread priority to something lower than the main thread. To be tested on some real world applications (by now, tested with Ethernet/WiFi Client/Server "basic" examples)
1 parent 9eeba8d commit 9619ec8

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

libraries/SocketWrapper/src/MbedClient.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ void arduino::MbedClient::readSocket() {
2121
do {
2222
if (rxBuffer.availableForStore() == 0) {
2323
yield();
24-
delay(100);
2524
continue;
2625
}
2726
mutex->lock();
@@ -34,7 +33,6 @@ void arduino::MbedClient::readSocket() {
3433
}
3534
if (ret == NSAPI_ERROR_WOULD_BLOCK || ret == 0) {
3635
yield();
37-
delay(100);
3836
mutex->unlock();
3937
continue;
4038
}
@@ -71,7 +69,7 @@ void arduino::MbedClient::configureSocket(Socket *_s) {
7169
}
7270
mutex->lock();
7371
if (reader_th == nullptr) {
74-
reader_th = new rtos::Thread;
72+
reader_th = new rtos::Thread(osPriorityNormal - 2);
7573
reader_th->start(mbed::callback(this, &MbedClient::readSocket));
7674
}
7775
mutex->unlock();

libraries/SocketWrapper/src/MbedClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class MbedClient : public arduino::Client {
7373
int connectSSL(IPAddress ip, uint16_t port);
7474
int connectSSL(const char* host, uint16_t port, bool disableSNI = false);
7575
size_t write(uint8_t);
76-
size_t write(const uint8_t* buf, size_t size);
76+
size_t write(const uint8_t* buf, size_t size) override;
7777
int available();
7878
int read();
7979
int read(uint8_t* buf, size_t size);

0 commit comments

Comments
 (0)