1
0
mirror of https://github.com/esphome/esphome.git synced 2025-02-25 14:28:14 +00:00

[socket] add connect method (#8308)

This commit is contained in:
Kevin Ahrendt 2025-02-24 14:32:54 -06:00 committed by GitHub
parent 96682f5cbe
commit 3410aee42e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 1 deletions

View File

@ -46,6 +46,7 @@ class BSDSocketImpl : public Socket {
close(); // NOLINT(clang-analyzer-optin.cplusplus.VirtualCall)
}
}
int connect(const struct sockaddr *addr, socklen_t addrlen) override { return ::connect(fd_, addr, addrlen); }
std::unique_ptr<Socket> accept(struct sockaddr *addr, socklen_t *addrlen) override {
int fd = ::accept(fd_, addr, addrlen);
if (fd == -1)

View File

@ -39,6 +39,7 @@ class LwIPSocketImpl : public Socket {
close(); // NOLINT(clang-analyzer-optin.cplusplus.VirtualCall)
}
}
int connect(const struct sockaddr *addr, socklen_t addrlen) override { return lwip_connect(fd_, addr, addrlen); }
std::unique_ptr<Socket> accept(struct sockaddr *addr, socklen_t *addrlen) override {
int fd = lwip_accept(fd_, addr, addrlen);
if (fd == -1)

View File

@ -21,7 +21,9 @@ class Socket {
virtual int close() = 0;
// not supported yet:
// virtual int connect(const std::string &address) = 0;
// virtual int connect(const struct sockaddr *addr, socklen_t addrlen) = 0;
#if defined(USE_SOCKET_IMPL_LWIP_SOCKETS) || defined(USE_SOCKET_IMPL_BSD_SOCKETS)
virtual int connect(const struct sockaddr *addr, socklen_t addrlen) = 0;
#endif
virtual int shutdown(int how) = 0;
virtual int getpeername(struct sockaddr *addr, socklen_t *addrlen) = 0;