@@ -612,7 +612,7 @@ bool ESP8266::dns_lookup(const char *name, char *ip)
612
612
return done;
613
613
}
614
614
615
- nsapi_error_t ESP8266::send (int id, const void *data, uint32_t amount)
615
+ nsapi_size_or_error_t ESP8266::send (int id, const void *data, uint32_t amount)
616
616
{
617
617
nsapi_error_t ret = NSAPI_ERROR_DEVICE_ERROR;
618
618
unsigned int send_ack_retries = 3 ;
@@ -651,15 +651,21 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
651
651
goto RETRY;
652
652
}
653
653
}
654
+ // This means ESP8266 hasn't even started to receive data
654
655
tr_debug (" send(): Didn't get \" >\" " );
655
- ret = NSAPI_ERROR_WOULD_BLOCK;
656
+ if (_sock_i[id].proto == NSAPI_TCP) {
657
+ ret = NSAPI_ERROR_WOULD_BLOCK;
658
+ } else if (_sock_i[id].proto == NSAPI_UDP) {
659
+ ret = NSAPI_ERROR_NO_MEMORY;
660
+ }
656
661
goto END;
657
662
}
658
663
_ok_received = false ;
659
664
_parser.remove_oob (" OK" );
660
665
661
666
if (_parser.write ((char *)data, (int )amount) < 0 ) {
662
- tr_debug (" Failed to write data" );
667
+ tr_debug (" Failed to write serial data" );
668
+ // Serial is not working, serious error, reset needed.
663
669
ret = NSAPI_ERROR_DEVICE_ERROR;
664
670
goto END;
665
671
}
@@ -669,6 +675,11 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
669
675
if (!_parser.recv (" Recv %d bytes" , &bytes_confirmed)) {
670
676
tr_debug (" Bytes not confirmed." );
671
677
ret = NSAPI_ERROR_DEVICE_ERROR;
678
+ if (_sock_i[id].proto == NSAPI_TCP) {
679
+ ret = NSAPI_ERROR_WOULD_BLOCK;
680
+ } else if (_sock_i[id].proto == NSAPI_UDP) {
681
+ ret = NSAPI_ERROR_NO_MEMORY;
682
+ }
672
683
goto END;
673
684
} else if (bytes_confirmed != amount) {
674
685
tr_debug (" Error: confirmed %d bytes, but expected %d." , bytes_confirmed, amount);
@@ -689,7 +700,7 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
689
700
goto RETRY_SEND_ACK;
690
701
}
691
702
} else {
692
- ret = NSAPI_ERROR_OK ;
703
+ ret = amount ;
693
704
}
694
705
695
706
END:
@@ -711,9 +722,9 @@ nsapi_error_t ESP8266::send(int id, const void *data, uint32_t amount)
711
722
tr_debug (" send(): Connection disrupted." );
712
723
}
713
724
714
- if (!_sock_i[id].open && ret != NSAPI_ERROR_OK) {
725
+ if (!_sock_i[id].open && ret < NSAPI_ERROR_OK) {
715
726
ret = NSAPI_ERROR_CONNECTION_LOST;
716
- tr_debug (" send(): Socket closed abruptly." );
727
+ tr_debug (" send(): Socket %d closed abruptly." , id );
717
728
}
718
729
719
730
set_timeout ();
0 commit comments