8000 Merge branch 'master' into uart_read_faster · SuGlider/arduino-esp32@638d0ff · GitHub
[go: up one dir, main page]

Skip to content

Commit 638d0ff

Browse files
authored
Merge branch 'master' into uart_read_faster
2 parents d37a199 + 394f721 commit 638d0ff

File tree

11 files changed

+93
-32
lines changed

11 files changed

+93
-32
lines changed

libraries/FS/src/FS.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,22 @@ File File::openNextFile(const char* mode)
187187
return _p->openNextFile(mode);
188188
}
189189

190+
boolean File::seekDir(long position){
191+
if(!_p){
192+
return false;
193+
}
194+
return _p->seekDir(position);
195+
}
196+
197+
String File::getNextFileName(void)
198+
{
199+
if (!_p) {
200+
return "";
201+
}
202+
return _p->getNextFileName();
203+
204+
}
205+
190206
void File::rewindDirectory(void)
191207
{
192208
if (!*this) {

libraries/FS/src/FS.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,9 @@ class File : public Stream
7878
const char* name() const;
7979

8080
boolean isDirectory(void);
81+
boolean seekDir(long position);
8182
File openNextFile(const char* mode = FILE_READ);
83+
String getNextFileName(void);
8284
void rewindDirectory(void);
8385

8486
protected:

libraries/FS/src/FSImpl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ class FileImpl
4343
virtual const char* name() const = 0;
4444
virtual boolean isDirectory(void) = 0;
4545
virtual FileImplPtr openNextFile(const char* mode) = 0;
46+
virtual boolean seekDir(long position);
47+
virtual String getNextFileName(void);
4648
virtual void rewindDirectory(void) = 0;
4749
virtual operator bool() = 0;
4850
};

libraries/FS/src/vfs_api.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,36 @@ FileImplPtr VFSFileImpl::openNextFile(const char* mode)
476476
return std::make_shared<VFSFileImpl>(_fs, name.c_str(), mode);
477477
}
478478

479+
boolean VFSFileImpl::seekDir(long position){
480+
if(!_d){
481+
return false;
482+
}
483+
seekdir(_d, position);
484+
return true;
485+
}
486+
487+
488+
String VFSFileImpl::getNextFileName()
489+
{
490+
if (!_isDirectory || !_d) {
491+
return "";
492+
}
493+
struct dirent *file = readdir(_d);
494+
if (file == NULL) {
495+
return "";
496+
}
497+
if (file->d_type != DT_REG && file->d_type != DT_DIR) {
498+
return "";
499+
}
500+
String fname = String(file->d_name);
501+
String name = String(_path);
502+
if (!fname.startsWith("/") && !name.endsWith("/")) {
503+
name += "/";
504+
}
505+
name += fname;
506+
return name;
507+
}
508+
479509
void VFSFileImpl::rewindDirectory(void)
480510
{
481511
if(!_isDirectory || !_d) {

libraries/FS/src/vfs_api.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class VFSFileImpl : public FileImpl
7171
const char* name() const override;
7272
time_t getLastWrite() override;
7373
boolean isDirectory(void) override;
74+
boolean seekDir(long position) override;
75+
String getNextFileName(void) override;
7476
FileImplPtr openNextFile(const char* mode) override;
7577
void rewindDirectory(void) override;
7678
operator bool();

libraries/WiFi/src/WiFiClient.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ class WiFiClient : public ESPLwIPClient
8484
return !this->operator==(rhs);
8585
};
8686

87-
int fd() const;
87+
virtual int fd() const;
8888

8989
int setSocketOption(int option, char* value, size_t len);
9090
int setSocketOption(int level, int option, const void* value, size_t len);

libraries/WiFi/src/WiFiGeneric.cpp

Lines changed: 19 additions & 16 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -1447,28 +1447,31 @@ static void wifi_dns_found_callback(const char *name, const ip_addr_t *ipaddr, v
14471447
}
14481448

14491449
/**
1450-
* Resolve the given hostname to an IP address.
1451-
* @param aHostname Name to be resolved
1450+
* Resolve the given hostname to an IP address. If passed hostname is an IP address, it will be parsed into IPAddress structure.
1451+
* @param aHostname Name to be resolved or string containing IP address
14521452
* @param aResult IPAddress structure to store the returned IP address
14531453
* @return 1 if aIPAddrString was successfully converted to an IP address,
14541454
* else error code
14551455
*/
14561456
int WiFiGenericClass::hostByName(const char* aHostname, IPAddress& aResult)
14571457
{
1458-
ip_addr_t addr;
1459-
aResult = static_cast<uint32_t>(0);
1460-
waitStatusBits(WIFI_DNS_IDLE_BIT, 16000);
1461-
clearStatusBits(WIFI_DNS_IDLE_BIT | WIFI_DNS_DONE_BIT);
1462-
err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
1463-
if(err == ERR_OK && addr.u_addr.ip4.addr) {
1464-
aResult = addr.u_addr.ip4.addr;
1465-
} else if(err == ERR_INPROGRESS) {
1466-
waitStatusBits(WIFI_DNS_DONE_BIT, 15000); //real internal timeout in lwip library is 14[s]
1467-
clearStatusBits(WIFI_DNS_DONE_BIT);
1468-
}
1469-
setStatusBits(WIFI_DNS_IDLE_BIT);
1470-
if((uint32_t)aResult == 0){
1471-
log_e("DNS Failed for %s", aHostname);
1458+
if (!aResult.fromString(aHostname))
1459+
{
1460+
ip_addr_t addr;
1461+
aResult = static_cast<uint32_t>(0);
1462+
waitStatusBits(WIFI_DNS_IDLE_BIT, 16000);
1463+
clearStatusBits(WIFI_DNS_IDLE_BIT | WIFI_DNS_DONE_BIT);
1464+
err_t err = dns_gethostbyname(aHostname, &addr, &wifi_dns_found_callback, &aResult);
1465+
if(err == ERR_OK && addr.u_addr.ip4.addr) {
1466+
aResult = addr.u_addr.ip4.addr;
1467+
} else if(err == ERR_INPROGRESS) {
1468+
waitStatusBits(WIFI_DNS_DONE_BIT, 15000); //real internal timeout in lwip library is 14[s]
1469+
clearStatusBits(WIFI_DNS_DONE_BIT);
1470+
}
1471+
setStatusBits(WIFI_DNS_IDLE_BIT);
1472+
if((uint32_t)aResult == 0){
1473+
log_e("DNS Failed for %s", aHostname);
1474+
}
14721475
}
14731476
return (uint32_t)aResult != 0;
14741477
}

libraries/WiFiClientSecure/src/WiFiClientSecure.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -376,16 +376,9 @@ int WiFiClientSecure::setTimeout(uint32_t seconds)
376376
return 0;
377377
}
378378
}
379-
int WiFiClientSecure::setSocketOption(int option, char* value, size_t len)
380-
{
381-
return setSocketOption(SOL_SOCKET, option, (const void*)value, len);
382-
}
383379

384-
int WiFiClientSecure::setSocketOption(int level, int option, const void* value, size_t len)
380+
int WiFiClientSecure::fd() const
385381
{
386-
int res = setsockopt(sslclient->socket, level, option, value, len);
387-
if(res < 0) {
388-
log_e("fail on %d, errno: %d, \"%s\"", sslclient->socket, errno, strerror(errno));
389-
}
390-
return res;
382+
return sslclient->socket;
391383
}
384+

libraries/WiFiClientSecure/src/WiFiClientSecure.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ class WiFiClientSecure : public WiFiClient
8080
const mbedtls_x509_crt* getPeerCertificate() { return mbedtls_ssl_get_peer_cert(&sslclient->ssl_ctx); };
8181
bool getFingerprintSHA256(uint8_t sha256_result[32]) { return get_peer_fingerprint(sslclient, sha256_result); };
8282
int setTimeout(uint32_t seconds);
83-
int setSocketOption(int option, char* value, size_t len);
84-
int setSocketOption(int level, int option, const void* value, size_t len);
83+
int fd() const;
8584

8685
operator bool()
8786
{

libraries/WiFiClientSecure/src/ssl_client.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
9090
timeout = 30000; // Milli seconds.
9191
}
9292

93+
ssl_client->socket_timeout = timeout;
94+
9395
fd_set fdset;
9496
struct timeval tv;
9597
FD_ZERO(&fdset);
@@ -341,12 +343,15 @@ void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, cons
341343
mbedtls_ctr_drbg_free(&ssl_client->drbg_ctx);
342344
mbedtls_entropy_free(&ssl_client->entropy_ctx);
343345

344-
// save only interesting field
345-
int timeout = ssl_client->handshake_timeout;
346+
// save only interesting fields
347+
int handshake_timeout = ssl_client->handshake_timeout;
348+
int socket_timeout = ssl_client->socket_timeout;
349+
346350
// reset embedded pointers to zero
347351
memset(ssl_client, 0, sizeof(sslclient_context));
348352

349-
ssl_client->handshake_timeout = timeout;
353+
ssl_client->handshake_timeout = handshake_timeout;
354+
ssl_client->socket_timeout = socket_timeout;
350355
}
351356

352357

@@ -369,11 +374,19 @@ int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, size_t len
369374
log_v("Writing HTTP request with %d bytes...", len); //for low level debug
370375
int ret = -1;
371376

377+
unsigned long write_start_time=millis();
378+
372379
while ((ret = mbedtls_ssl_write(&ssl_client->ssl_ctx, data, len)) <= 0) {
380+
if((millis()-write_start_time)>ssl_client->socket_timeout) {
381+
log_v("SSL write timed out.");
382+
return -1;
383+
}
384+
373385
if (ret != MBEDTLS_ERR_SSL_WANT_READ && ret != MBEDTLS_ERR_SSL_WANT_WRITE && ret < 0) {
374386
log_v("Handling error %d", ret); //for low level debug
375387
return handle_error(ret);
376388
}
389+
377390
//wait for space to become available
378391
vTaskDelay(2);
379392
}

0 commit comments

Comments
 (0)
0