|
28 | 28 | #include "platform/Callback.h"
|
29 | 29 | #include "platform/mbed_debug.h"
|
30 | 30 | #include "platform/mbed_wait_api.h"
|
31 |
| -#include "Kernel.h" |
32 | 31 |
|
33 | 32 | #ifndef MBED_CONF_ESP8266_DEBUG
|
34 | 33 | #define MBED_CONF_ESP8266_DEBUG false
|
@@ -495,6 +494,10 @@ int ESP8266Interface::socket_close(void *handle)
|
495 | 494 | err = NSAPI_ERROR_DEVICE_ERROR;
|
496 | 495 | }
|
497 | 496 |
|
| 497 | + _cbs[socket->id].callback = NULL; |
| 498 | + _cbs[socket->id].data = NULL; |
| 499 | + _cbs[socket->id].deferred = false; |
| 500 | + |
498 | 501 | socket->connected = false;
|
499 | 502 | _sock_i[socket->id].open = false;
|
500 | 503 | _sock_i[socket->id].sport = 0;
|
@@ -573,15 +576,12 @@ int ESP8266Interface::socket_send(void *handle, const void *data, unsigned size)
|
573 | 576 | return socket->proto == NSAPI_TCP ? 0 : NSAPI_ERROR_UNSUPPORTED;
|
574 | 577 | }
|
575 | 578 |
|
576 |
| - unsigned long int sendStartTime = rtos::Kernel::get_ms_count(); |
577 |
| - do { |
578 |
| - status = _esp.send(socket->id, data, size); |
579 |
| - } while ((sendStartTime - rtos::Kernel::get_ms_count() < 50) |
580 |
| - && (status != NSAPI_ERROR_OK)); |
| 579 | + status = _esp.send(socket->id, data, size); |
581 | 580 |
|
582 |
| - if (status == NSAPI_ERROR_WOULD_BLOCK && socket->proto == NSAPI_TCP) { |
583 |
| - tr_debug("ESP8266Interface::socket_send(): enqueuing the event call"); |
584 |
| - _global_event_queue->call_in(100, callback(this, &ESP8266Interface::event)); |
| 581 | + if (status == NSAPI_ERROR_WOULD_BLOCK && !_cbs[socket->id].deferred && socket->proto == NSAPI_TCP) { |
| 582 | + tr_debug("Postponing SIGIO from the device"); |
| 583 | + _cbs[socket->id].deferred = true; |
| 584 | + _global_event_queue->call_in(50, callback(this, &ESP8266Interface::event_deferred)); |
585 | 585 | } else if (status == NSAPI_ERROR_WOULD_BLOCK && socket->proto == NSAPI_UDP) {
|
586 | 586 | status = NSAPI_ERROR_DEVICE_ERROR;
|
587 | 587 | }
|
@@ -731,6 +731,16 @@ void ESP8266Interface::event()
|
731 | 731 | }
|
732 | 732 | }
|
733 | 733 |
|
| 734 | +void ESP8266Interface::event_deferred() |
| 735 | +{ |
| 736 | + for (int i = 0; i < ESP8266_SOCKET_COUNT; i++) { |
| 737 | + if (_cbs[i].deferred && _cbs[i].callback) { |
| 738 | + _cbs[i].deferred = false; |
| 739 | + _cbs[i].callback(_cbs[i].data); |
| 740 | + } |
| 741 | + } |
| 742 | +} |
| 743 | + |
734 | 744 | void ESP8266Interface::attach(Callback<void(nsapi_event_t, intptr_t)> status_cb)
|
735 | 745 | {
|
736 | 746 | _conn_stat_cb = status_cb;
|
|
0 commit comments