Skip to content

Commit 21f770e

Browse files
Socket wrapper: fix destructor and check connected
1 parent ee65482 commit 21f770e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

libraries/SocketWrapper/SocketWrapper.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ class ZephyrSocketWrapper {
2222
}
2323

2424
~ZephyrSocketWrapper() {
25-
if (sock_fd != -1) {
26-
::close(sock_fd);
27-
}
2825
}
2926

3027
bool connect(const char *host, uint16_t port) {

libraries/SocketWrapper/ZephyrClient.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ class ZephyrClient : public arduino::Client, ZephyrSocketWrapper {
4040
return ret;
4141
}
4242
#endif
43+
4344
uint8_t connected() override {
45+
if (sock_fd == -1) return false;
46+
47+
uint8_t buf;
48+
int ret = ::recv(sock_fd, &buf, 1, MSG_PEEK | MSG_DONTWAIT);
49+
if (ret == 0) {
50+
_connected = false;
51+
::close(sock_fd);
52+
sock_fd = -1;
53+
return false;
54+
}
4455
return _connected;
4556
}
4657

0 commit comments

Comments
 (0)