mirror of
https://github.com/esphome/esphome.git
synced 2024-12-21 16:27:44 +01:00
[code-quality] udp component (#7602)
Co-authored-by: Tomasz Duda <tomaszduda23@gmai.com> Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
This commit is contained in:
parent
fcfc76b01b
commit
f490585f66
@ -261,7 +261,8 @@ void UDPComponent::setup() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||
// 8266 and RP2040 `Duino
|
||||
for (const auto &address : this->addresses_) {
|
||||
auto ipaddr = IPAddress();
|
||||
@ -370,7 +371,8 @@ void UDPComponent::loop() {
|
||||
for (;;) {
|
||||
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
||||
auto len = this->listen_socket_->read(buf, sizeof(buf));
|
||||
#else
|
||||
#endif
|
||||
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||
auto len = this->udp_client_.parsePacket();
|
||||
if (len > 0)
|
||||
len = this->udp_client_.read(buf, sizeof(buf));
|
||||
@ -587,7 +589,8 @@ void UDPComponent::send_packet_(void *data, size_t len) {
|
||||
if (result < 0)
|
||||
ESP_LOGW(TAG, "sendto() error %d", errno);
|
||||
}
|
||||
#else
|
||||
#endif
|
||||
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||
auto iface = IPAddress(0, 0, 0, 0);
|
||||
for (const auto &saddr : this->ipaddrs_) {
|
||||
if (this->udp_client_.beginPacketMulticast(saddr, this->port_, iface, 128) != 0) {
|
||||
|
@ -9,7 +9,8 @@
|
||||
#endif
|
||||
#if defined(USE_SOCKET_IMPL_BSD_SOCKETS) || defined(USE_SOCKET_IMPL_LWIP_SOCKETS)
|
||||
#include "esphome/components/socket/socket.h"
|
||||
#else
|
||||
#endif
|
||||
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||
#include <WiFiUdp.h>
|
||||
#endif
|
||||
#include <vector>
|
||||
@ -125,7 +126,8 @@ class UDPComponent : public PollingComponent {
|
||||
std::unique_ptr<socket::Socket> broadcast_socket_ = nullptr;
|
||||
std::unique_ptr<socket::Socket> listen_socket_ = nullptr;
|
||||
std::vector<struct sockaddr> sockaddrs_{};
|
||||
#else
|
||||
#endif
|
||||
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||
std::vector<IPAddress> ipaddrs_{};
|
||||
WiFiUDP udp_client_{};
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user