mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-05-27 08:18:28 +02:00
Merge branch 'dev' into bump-2021.10.0b1
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
#include "socket.h"
|
||||
#include "esphome/core/defines.h"
|
||||
#include "esphome/core/helpers.h"
|
||||
|
||||
#ifdef USE_SOCKET_IMPL_BSD_SOCKETS
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
#ifdef USE_ESP32
|
||||
#include <esp_idf_version.h>
|
||||
#include <lwip/sockets.h>
|
||||
#endif
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#include <esp_idf_version.h>
|
||||
@@ -17,14 +23,14 @@ std::string format_sockaddr(const struct sockaddr_storage &storage) {
|
||||
const struct sockaddr_in *addr = reinterpret_cast<const struct sockaddr_in *>(&storage);
|
||||
char buf[INET_ADDRSTRLEN];
|
||||
const char *ret = inet_ntop(AF_INET, &addr->sin_addr, buf, sizeof(buf));
|
||||
if (ret == NULL)
|
||||
if (ret == nullptr)
|
||||
return {};
|
||||
return std::string{buf};
|
||||
} else if (storage.ss_family == AF_INET6) {
|
||||
const struct sockaddr_in6 *addr = reinterpret_cast<const struct sockaddr_in6 *>(&storage);
|
||||
char buf[INET6_ADDRSTRLEN];
|
||||
const char *ret = inet_ntop(AF_INET6, &addr->sin6_addr, buf, sizeof(buf));
|
||||
if (ret == NULL)
|
||||
if (ret == nullptr)
|
||||
return {};
|
||||
return std::string{buf};
|
||||
}
|
||||
@@ -36,14 +42,14 @@ class BSDSocketImpl : public Socket {
|
||||
BSDSocketImpl(int fd) : Socket(), fd_(fd) {}
|
||||
~BSDSocketImpl() override {
|
||||
if (!closed_) {
|
||||
close();
|
||||
close(); // NOLINT(clang-analyzer-optin.cplusplus.VirtualCall)
|
||||
}
|
||||
}
|
||||
std::unique_ptr<Socket> accept(struct sockaddr *addr, socklen_t *addrlen) override {
|
||||
int fd = ::accept(fd_, addr, addrlen);
|
||||
if (fd == -1)
|
||||
return {};
|
||||
return std::unique_ptr<BSDSocketImpl>{new BSDSocketImpl(fd)};
|
||||
return make_unique<BSDSocketImpl>(fd);
|
||||
}
|
||||
int bind(const struct sockaddr *addr, socklen_t addrlen) override { return ::bind(fd_, addr, addrlen); }
|
||||
int close() override {
|
||||
@@ -80,7 +86,7 @@ class BSDSocketImpl : public Socket {
|
||||
int listen(int backlog) override { return ::listen(fd_, backlog); }
|
||||
ssize_t read(void *buf, size_t len) override { return ::read(fd_, buf, len); }
|
||||
ssize_t readv(const struct iovec *iov, int iovcnt) override {
|
||||
#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR < 4
|
||||
#if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR < 4
|
||||
// esp-idf v3 doesn't have readv, emulate it
|
||||
ssize_t ret = 0;
|
||||
for (int i = 0; i < iovcnt; i++) {
|
||||
@@ -96,7 +102,7 @@ class BSDSocketImpl : public Socket {
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
#elif defined(USE_ESP32)
|
||||
// ESP-IDF v4 only has symbol lwip_readv
|
||||
return ::lwip_readv(fd_, iov, iovcnt);
|
||||
#else
|
||||
@@ -106,7 +112,7 @@ class BSDSocketImpl : public Socket {
|
||||
ssize_t write(const void *buf, size_t len) override { return ::write(fd_, buf, len); }
|
||||
ssize_t send(void *buf, size_t len, int flags) { return ::send(fd_, buf, len, flags); }
|
||||
ssize_t writev(const struct iovec *iov, int iovcnt) override {
|
||||
#if defined(ARDUINO_ARCH_ESP32) && ESP_IDF_VERSION_MAJOR < 4
|
||||
#if defined(USE_ESP32) && ESP_IDF_VERSION_MAJOR < 4
|
||||
// esp-idf v3 doesn't have writev, emulate it
|
||||
ssize_t ret = 0;
|
||||
for (int i = 0; i < iovcnt; i++) {
|
||||
@@ -123,7 +129,7 @@ class BSDSocketImpl : public Socket {
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
#elif defined(ARDUINO_ARCH_ESP32)
|
||||
#elif defined(USE_ESP32)
|
||||
// ESP-IDF v4 only has symbol lwip_writev
|
||||
return ::lwip_writev(fd_, iov, iovcnt);
|
||||
#else
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
#ifdef USE_SOCKET_IMPL_LWIP_TCP
|
||||
|
||||
#define LWIP_INTERNAL
|
||||
#include <sys/types.h>
|
||||
#include "lwip/inet.h"
|
||||
#include <stdint.h>
|
||||
#include <errno.h>
|
||||
#include <cerrno>
|
||||
#include <cstdint>
|
||||
#include <sys/types.h>
|
||||
|
||||
/* Address families. */
|
||||
#define AF_UNSPEC 0
|
||||
@@ -45,9 +45,10 @@
|
||||
|
||||
#define SOL_SOCKET 0xfff /* options for socket level */
|
||||
|
||||
typedef uint8_t sa_family_t;
|
||||
typedef uint16_t in_port_t;
|
||||
using sa_family_t = uint8_t;
|
||||
using in_port_t = uint16_t;
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sockaddr_in {
|
||||
uint8_t sin_len;
|
||||
sa_family_t sin_family;
|
||||
@@ -57,6 +58,7 @@ struct sockaddr_in {
|
||||
char sin_zero[SIN_ZERO_LEN];
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sockaddr_in6 {
|
||||
uint8_t sin6_len; /* length of this structure */
|
||||
sa_family_t sin6_family; /* AF_INET6 */
|
||||
@@ -66,12 +68,14 @@ struct sockaddr_in6 {
|
||||
uint32_t sin6_scope_id; /* Set of interfaces for scope */
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sockaddr {
|
||||
uint8_t sa_len;
|
||||
sa_family_t sa_family;
|
||||
char sa_data[14];
|
||||
};
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct sockaddr_storage {
|
||||
uint8_t s2_len;
|
||||
sa_family_t ss_family;
|
||||
@@ -79,14 +83,15 @@ struct sockaddr_storage {
|
||||
uint32_t s2_data2[3];
|
||||
uint32_t s2_data3[3];
|
||||
};
|
||||
typedef uint32_t socklen_t;
|
||||
using socklen_t = uint32_t;
|
||||
|
||||
// NOLINTNEXTLINE(readability-identifier-naming)
|
||||
struct iovec {
|
||||
void *iov_base;
|
||||
size_t iov_len;
|
||||
};
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP8266
|
||||
#ifdef USE_ESP8266
|
||||
// arduino-esp8266 declares a global vars called INADDR_NONE/ANY which are invalid with the define
|
||||
#ifdef INADDR_ANY
|
||||
#undef INADDR_ANY
|
||||
@@ -97,7 +102,7 @@ struct iovec {
|
||||
|
||||
#define ESPHOME_INADDR_ANY ((uint32_t) 0x00000000UL)
|
||||
#define ESPHOME_INADDR_NONE ((uint32_t) 0xFFFFFFFFUL)
|
||||
#else // !ARDUINO_ARCH_ESP8266
|
||||
#else // !USE_ESP8266
|
||||
#define ESPHOME_INADDR_ANY INADDR_ANY
|
||||
#define ESPHOME_INADDR_NONE INADDR_NONE
|
||||
#endif
|
||||
@@ -106,26 +111,26 @@ struct iovec {
|
||||
|
||||
#ifdef USE_SOCKET_IMPL_BSD_SOCKETS
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <cstdint>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/uio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef ARDUINO_ARCH_ESP32
|
||||
#ifdef USE_ARDUINO
|
||||
// arduino-esp32 declares a global var called INADDR_NONE which is replaced
|
||||
// by the define
|
||||
#ifdef INADDR_NONE
|
||||
#undef INADDR_NONE
|
||||
#endif
|
||||
// not defined for ESP32
|
||||
typedef uint32_t socklen_t;
|
||||
using socklen_t = uint32_t;
|
||||
|
||||
#define ESPHOME_INADDR_ANY ((uint32_t) 0x00000000UL)
|
||||
#define ESPHOME_INADDR_NONE ((uint32_t) 0xFFFFFFFFUL)
|
||||
#else // !ARDUINO_ARCH_ESP32
|
||||
#else // !USE_ESP32
|
||||
#define ESPHOME_INADDR_ANY INADDR_ANY
|
||||
#define ESPHOME_INADDR_NONE INADDR_NONE
|
||||
#endif
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <cstring>
|
||||
#include <queue>
|
||||
|
||||
#include "esphome/core/helpers.h"
|
||||
#include "esphome/core/log.h"
|
||||
|
||||
namespace esphome {
|
||||
@@ -492,9 +493,9 @@ class LWIPRawImpl : public Socket {
|
||||
// nothing to do here, we just don't push it to the queue
|
||||
return ERR_OK;
|
||||
}
|
||||
auto *sock = new LWIPRawImpl(newpcb);
|
||||
auto sock = make_unique<LWIPRawImpl>(newpcb);
|
||||
sock->init();
|
||||
accepted_sockets_.emplace(sock);
|
||||
accepted_sockets_.push(std::move(sock));
|
||||
return ERR_OK;
|
||||
}
|
||||
void err_fn(err_t err) {
|
||||
@@ -558,7 +559,7 @@ std::unique_ptr<Socket> socket(int domain, int type, int protocol) {
|
||||
auto *pcb = tcp_new();
|
||||
if (pcb == nullptr)
|
||||
return nullptr;
|
||||
auto *sock = new LWIPRawImpl(pcb);
|
||||
auto *sock = new LWIPRawImpl(pcb); // NOLINT(cppcoreguidelines-owning-memory)
|
||||
sock->init();
|
||||
return std::unique_ptr<Socket>{sock};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user