Skip to content

Add full setsocketoption to WifiClient and WifiClientSecure #7030

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions libraries/WiFi/src/WiFiClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,14 @@ int WiFiClient::connect(const char *host, uint16_t port, int32_t timeout)

int WiFiClient::setSocketOption(int option, char* value, size_t len)
{
int res = setsockopt(fd(), SOL_SOCKET, option, value, len);
return setSocketOption(SOL_SOCKET, option, (const void*)value, len);
}

int WiFiClient::setSocketOption(int level, int option, const void* value, size_t len)
{
int res = setsockopt(fd(), level, option, value, len);
if(res < 0) {
log_e("%X : %d", option, errno);
log_e("fail on %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
}
return res;
}
Expand All @@ -330,11 +335,7 @@ int WiFiClient::setTimeout(uint32_t seconds)

int WiFiClient::setOption(int option, int *value)
{
int res = setsockopt(fd(), IPPROTO_TCP, option, (char *) value, sizeof(int));
if(res < 0) {
log_e("fail on fd %d, errno: %d, \"%s\"", fd(), errno, strerror(errno));
}
return res;
return setSocketOption(IPPROTO_TCP, option, (const void*)value, sizeof(int));
}

int WiFiClient::getOption(int option, int *value)
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 @@ -87,6 +87,7 @@ class WiFiClient : public ESPLwIPClient
int fd() const;

int setSocketOption(int option, char* value, size_t len);
int setSocketOption(int level, int option, const void* value, size_t len);
int setOption(int option, int *value);
int getOption(int option, int *value);
int setTimeout(uint32_t seconds);
Expand Down
9 changes: 7 additions & 2 deletions libraries/WiFiClientSecure/src/WiFiClientSecure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,14 @@ int WiFiClientSecure::setTimeout(uint32_t seconds)
}
int WiFiClientSecure::setSocketOption(int option, char* value, size_t len)
{
int res = setsockopt(sslclient->socket, SOL_SOCKET, option, value, len);
return setSocketOption(SOL_SOCKET, option, (const void*)value, len);
}

int WiFiClientSecure::setSocketOption(int level, int option, const void* value, size_t len)
{
int res = setsockopt(sslclient->socket, level, option, value, len);
if(res < 0) {
log_e("%X : %d", option, errno);
log_e("fail on %d, errno: %d, \"%s\"", sslclient->socket, errno, strerror(errno));
}
return res;
}
1 change: 1 addition & 0 deletions libraries/WiFiClientSecure/src/WiFiClientSecure.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class WiFiClientSecure : public WiFiClient
bool getFingerprintSHA256(uint8_t sha256_result[32]) { return get_peer_fingerprint(sslclient, sha256_result); };
int setTimeout(uint32_t seconds);
int setSocketOption(int option, char* value, size_t len);
int setSocketOption(int level, int option, const void* value, size_t len);

operator bool()
{
Expand Down