mirror of
https://github.com/esp8266/Arduino.git
synced 2025-04-25 20:02:37 +03:00
Automatically call yield() in WiFiClient::available if called more than once
This commit is contained in:
parent
4942ceef37
commit
8e7a20c08d
@ -49,6 +49,13 @@ extern void (*__init_array_end)(void);
|
||||
static cont_t g_cont;
|
||||
static os_event_t g_loop_queue[LOOP_QUEUE_SIZE];
|
||||
|
||||
static uint32_t g_micros_at_task_start;
|
||||
|
||||
extern "C" uint32_t esp_micros_at_task_start()
|
||||
{
|
||||
return g_micros_at_task_start;
|
||||
}
|
||||
|
||||
extern "C" void abort()
|
||||
{
|
||||
while(1){}
|
||||
@ -86,6 +93,7 @@ static void loop_wrapper()
|
||||
|
||||
static void loop_task(os_event_t *events)
|
||||
{
|
||||
g_micros_at_task_start = system_get_time();
|
||||
cont_run(&g_cont, &loop_wrapper);
|
||||
if (cont_check(&g_cont) != 0)
|
||||
{
|
||||
|
@ -46,7 +46,8 @@ extern "C"
|
||||
static int g_localPort = MIN_LOCAL_PORT;
|
||||
|
||||
ICACHE_FLASH_ATTR WiFiClient::WiFiClient()
|
||||
: _client(0)
|
||||
: _client(0)
|
||||
, _lastPollTime(0)
|
||||
{
|
||||
}
|
||||
|
||||
@ -153,12 +154,20 @@ size_t ICACHE_FLASH_ATTR WiFiClient::write(const uint8_t *buf, size_t size)
|
||||
return _client->write(reinterpret_cast<const char*>(buf), size);
|
||||
}
|
||||
|
||||
extern "C" uint32_t esp_micros_at_task_start();
|
||||
|
||||
int ICACHE_FLASH_ATTR WiFiClient::available()
|
||||
{
|
||||
if (!_client)
|
||||
return 0;
|
||||
|
||||
return _client->getSize();
|
||||
if (_lastPollTime > esp_micros_at_task_start())
|
||||
yield();
|
||||
|
||||
_lastPollTime = micros();
|
||||
|
||||
int result = _client->getSize();
|
||||
return result;
|
||||
}
|
||||
|
||||
int ICACHE_FLASH_ATTR WiFiClient::read()
|
||||
|
@ -66,6 +66,8 @@ private:
|
||||
void _err(int8_t err);
|
||||
|
||||
ClientContext* _client;
|
||||
uint32_t _lastPollTime;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user