File tree 1 file changed +10
-15
lines changed
libraries/WiFiClientSecure/src
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)
156
156
int WiFiClientSecure::read ()
157
157
{
158
158
uint8_t data = -1 ;
159
-
160
- if (_peek >= 0 ){
161
- data = _peek;
162
- _peek = -1 ;
163
- return data;
164
- }
165
-
166
159
int res = read (&data, 1 );
167
160
if (res < 0 ) {
168
161
return res;
@@ -186,7 +179,8 @@ size_t WiFiClientSecure::write(const uint8_t *buf, size_t size)
186
179
int WiFiClientSecure::read (uint8_t *buf, size_t size)
187
180
{
188
181
int peeked = 0 ;
189
- if ((!buf && size) || (_peek < 0 && !available ())) {
182
+ int avail = available ();
183
+ if ((!buf && size) || avail <= 0 ) {
190
184
return -1 ;
191
185
}
192
186
if (!size){
@@ -196,7 +190,8 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size)
196
190
buf[0 ] = _peek;
197
191
_peek = -1 ;
198
192
size--;
199
- if (!size || !available ()){
193
+ avail--;
194
+ if (!size || !avail){
200
195
return 1 ;
201
196
}
202
197
buf++;
@@ -206,23 +201,23 @@ int WiFiClientSecure::read(uint8_t *buf, size_t size)
206
201
int res = get_ssl_receive (sslclient, buf, size);
207
202
if (res < 0 ) {
208
203
stop ();
209
- return res;
204
+ return peeked?peeked: res;
210
205
}
211
206
return res + peeked;
212
207
}
213
208
214
209
int WiFiClientSecure::available ()
215
210
{
211
+ int peeked = (_peek >= 0 );
216
212
if (!_connected) {
217
- return 0 ;
213
+ return peeked ;
218
214
}
219
215
int res = data_to_read (sslclient);
220
- if (res < 0 ) {
216
+ if (res < 0 ) {
221
217
stop ();
222
- } else if (_peek >= 0 ) {
223
- res += 1 ;
218
+ return peeked?peeked:res;
224
219
}
225
- return res;
220
+ return res+peeked ;
226
221
}
227
222
228
223
uint8_t WiFiClientSecure::connected ()
You can’t perform that action at this time.
0 commit comments