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