ESP8266: reduces SIGIO signaled to the upper layers

pull/9520/head
Veijo Pesonen 2018-12-18 12:33:22 +02:00
parent a4ed473afc
commit 7d3621dae4
2 changed files with 21 additions and 9 deletions

View File

@ -28,7 +28,6 @@
#include "platform/Callback.h"
#include "platform/mbed_debug.h"
#include "platform/mbed_wait_api.h"
#include "Kernel.h"
#ifndef MBED_CONF_ESP8266_DEBUG
#define MBED_CONF_ESP8266_DEBUG false
@ -495,6 +494,10 @@ int ESP8266Interface::socket_close(void *handle)
err = NSAPI_ERROR_DEVICE_ERROR;
}
_cbs[socket->id].callback = NULL;
_cbs[socket->id].data = NULL;
_cbs[socket->id].deferred = false;
socket->connected = false;
_sock_i[socket->id].open = false;
_sock_i[socket->id].sport = 0;
@ -573,15 +576,12 @@ int ESP8266Interface::socket_send(void *handle, const void *data, unsigned size)
return socket->proto == NSAPI_TCP ? 0 : NSAPI_ERROR_UNSUPPORTED;
}
unsigned long int sendStartTime = rtos::Kernel::get_ms_count();
do {
status = _esp.send(socket->id, data, size);
} while ((sendStartTime - rtos::Kernel::get_ms_count() < 50)
&& (status != NSAPI_ERROR_OK));
status = _esp.send(socket->id, data, size);
if (status == NSAPI_ERROR_WOULD_BLOCK && socket->proto == NSAPI_TCP) {
tr_debug("ESP8266Interface::socket_send(): enqueuing the event call");
_global_event_queue->call_in(100, callback(this, &ESP8266Interface::event));
if (status == NSAPI_ERROR_WOULD_BLOCK && !_cbs[socket->id].deferred && socket->proto == NSAPI_TCP) {
tr_debug("Postponing SIGIO from the device");
_cbs[socket->id].deferred = true;
_global_event_queue->call_in(50, callback(this, &ESP8266Interface::event_deferred));
} else if (status == NSAPI_ERROR_WOULD_BLOCK && socket->proto == NSAPI_UDP) {
status = NSAPI_ERROR_DEVICE_ERROR;
}
@ -731,6 +731,16 @@ void ESP8266Interface::event()
}
}
void ESP8266Interface::event_deferred()
{
for (int i = 0; i < ESP8266_SOCKET_COUNT; i++) {
if (_cbs[i].deferred && _cbs[i].callback) {
_cbs[i].deferred = false;
_cbs[i].callback(_cbs[i].data);
}
}
}
void ESP8266Interface::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
{
_conn_stat_cb = status_cb;

View File

@ -373,8 +373,10 @@ private:
struct {
void (*callback)(void *);
void *data;
bool deferred;
} _cbs[ESP8266_SOCKET_COUNT];
void event();
void event_deferred();
// Connection state reporting to application
nsapi_connection_status_t _conn_stat;