File tree Expand file tree Collapse file tree 1 file changed +10
-15
lines changed 
libraries/WiFiClientSecure/src Expand file tree Collapse file tree 1 file changed +10
-15
lines changed Original file line number Diff line number Diff line change @@ -156,13 +156,6 @@ size_t WiFiClientSecure::write(uint8_t data)
156156int  WiFiClientSecure::read ()
157157{
158158    uint8_t  data = -1 ;
159- 
160-     if (_peek >= 0 ){
161-         data = _peek;
162-         _peek = -1 ;
163-         return  data;
164-     }
165- 
166159    int  res = read (&data, 1 );
167160    if  (res < 0 ) {
168161        return  res;
@@ -186,7 +179,8 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
186179int  WiFiClientSecure::read (uint8_t  *buf, size_t  size)
187180{
188181    int  peeked = 0 ;
189-     if  ((!buf && size) || (_peek < 0  && !available ())) {
182+     int  avail = available ();
183+     if  ((!buf && size) || avail <= 0 ) {
190184        return  -1 ;
191185    }
192186    if (!size){
@@ -196,7 +190,8 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size)
196190        buf[0 ] = _peek;
197191        _peek = -1 ;
198192        size--;
199-         if (!size || !available ()){
193+         avail--;
194+         if (!size || !avail){
200195            return  1 ;
201196        }
202197        buf++;
@@ -206,23 +201,23 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size)
206201    int  res = get_ssl_receive (sslclient, buf, size);
207202    if  (res < 0 ) {
208203        stop ();
209-         return  res;
204+         return  peeked?peeked: res;
210205    }
211206    return  res + peeked;
212207}
213208
214209int  WiFiClientSecure::available ()
215210{
211+     int  peeked = (_peek >= 0 );
216212    if  (!_connected) {
217-         return  0 ;
213+         return  peeked ;
218214    }
219215    int  res = data_to_read (sslclient);
220-     if  (res < 0   ) {
216+     if  (res < 0 ) {
221217        stop ();
222-     } else  if (_peek >= 0 ) {
223-         res += 1 ;
218+         return  peeked?peeked:res;
224219    }
225-     return  res;
220+     return  res+peeked ;
226221}
227222
228223uint8_t  WiFiClientSecure::connected ()
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments