Skip to content

Commit

Permalink
Add missing function getSocketOption (espressif#7807)
Browse files Browse the repository at this point in the history
* Update WiFiClient.h

Added missing getSocketOption() with full access to level and option

* Update WiFiClient.h

* Handle timeout settings below 1 second

Fix error with connect timeout settings below 1000ms.
Add getsocketoptions function.

* Add cast for setsockopt length

---------

Co-authored-by: Me No Dev <[email protected]>
  • Loading branch information
rtpmsys and me-no-dev authored Nov 29, 2023
1 parent ac1c001 commit e99437c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libraries/WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,16 @@ int WiFiClient::setSocketOption(int level, int option, const void* value, size_t
return res;
}

int WiFiClient::getSocketOption(int level, int option, const void* value, size_t size)
{
int res = getsockopt(fd(), level, option, (char *)value, (socklen_t*)&size);
if(res < 0) {
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
}
return res;
}


int WiFiClient::setTimeout(uint32_t seconds)
{
Client::setTimeout(seconds * 1000); // This should be here?
Expand Down
1 change: 1 addition & 0 deletions libraries/WiFi/src/WiFiClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class WiFiClient : public ESPLwIPClient

int setSocketOption(int option, char* value, size_t len);
int setSocketOption(int level, int option, const void* value, size_t len);
int getSocketOption(int level, int option, const void* value, size_t size);
int setOption(int option, int *value);
int getOption(int option, int *value);
int setTimeout(uint32_t seconds);
Expand Down

0 comments on commit e99437c

Please sign in to comment.