@@ -552,26 +552,29 @@ void ESP8266::process_oob(uint32_t timeout, bool all) {
552
552
int32_t ESP8266::_recv_tcp_passive (int id, void *data, uint32_t amount, uint32_t timeout)
553
553
{
554
554
int32_t len;
555
- int32_t ret;
555
+ int32_t ret = ( int32_t )NSAPI_ERROR_WOULD_BLOCK ;
556
556
557
557
_smutex.lock ();
558
558
559
- bool done = _parser.send (" AT+CIPRECVDATA=%d,%lu" , id, amount);
560
- if (!done) {
561
- _smutex.unlock ();
562
- return NSAPI_ERROR_DEVICE_ERROR;
563
- }
564
559
// NOTE: documentation v3.0 says '+CIPRECVDATA:<data_len>,' but it's not how the FW responds...
565
- done = _parser.recv (" +CIPRECVDATA,%ld:" , &len)
560
+ bool done = _parser.send (" AT+CIPRECVDATA=%d,%lu" , id, amount)
561
+ && _parser.recv (" +CIPRECVDATA,%ld:" , &len)
566
562
&& _parser.read ((char *)data, len)
567
563
&& _parser.recv (" OK\n " );
568
564
569
- // Got data?
570
565
if (done) {
571
- ret = len;
572
- } else {
573
- // Socket still open?
574
- ret = _socket_open[id].id != id ? 0 : (int32_t )NSAPI_ERROR_WOULD_BLOCK;
566
+ _smutex.unlock ();
567
+ return len;
568
+ }
569
+
570
+ // Socket closed, doesn't mean there couldn't be data left
571
+ if (_socket_open[id].id != id) {
572
+ done = _parser.send (" AT+CIPRECVDATA=%d,%lu" , id, amount)
573
+ && _parser.recv (" +CIPRECVDATA,%ld:" , &len)
574
+ && _parser.read ((char *)data, len)
575
+ && _parser.recv (" OK\n " );
576
+
577
+ ret = done ? len : 0 ;
575
578
}
576
579
577
580
_smutex.unlock ();
0 commit comments