fix for compiling on Mac OSX Apple Silicon

This commit is contained in:
proddy
2024-07-11 16:26:33 +02:00
parent d3d303cfc4
commit 2b7b8c1bd9

View File

@@ -13,8 +13,8 @@ the LICENSE file.
namespace espMqttClientInternals {
ClientPosix::ClientPosix()
: _sockfd(-1)
, _host() {
: _sockfd(-1)
, _host() {
// empty
}
@@ -23,7 +23,8 @@ ClientPosix::~ClientPosix() {
}
bool ClientPosix::connect(IPAddress ip, uint16_t port) {
if (connected()) stop();
if (connected())
stop();
_sockfd = ::socket(AF_INET, SOCK_STREAM, 0);
if (_sockfd < 0) {
@@ -38,9 +39,11 @@ bool ClientPosix::connect(IPAddress ip, uint16_t port) {
memset(&_host, 0, sizeof(_host));
_host.sin_family = AF_INET;
_host.sin_addr.s_addr = htonl(uint32_t(ip));
#ifndef __APPLE__
_host.sin_port = ::htons(port);
#endif
int ret = ::connect(_sockfd, reinterpret_cast<sockaddr*>(&_host), sizeof(_host));
int ret = ::connect(_sockfd, reinterpret_cast<sockaddr *>(&_host), sizeof(_host));
if (ret < 0) {
emc_log_e("Error connecting: %d - (%d) %s", ret, errno, strerror(errno));
@@ -51,18 +54,18 @@ bool ClientPosix::connect(IPAddress ip, uint16_t port) {
return true;
}
bool ClientPosix::connect(const char* host, uint16_t port) {
bool ClientPosix::connect(const char * host, uint16_t port) {
// tbi
(void) host;
(void) port;
(void)host;
(void)port;
return false;
}
size_t ClientPosix::write(const uint8_t* buf, size_t size) {
size_t ClientPosix::write(const uint8_t * buf, size_t size) {
return ::send(_sockfd, buf, size, 0);
}
int ClientPosix::read(uint8_t* buf, size_t size) {
int ClientPosix::read(uint8_t * buf, size_t size) {
int ret = ::recv(_sockfd, buf, size, MSG_DONTWAIT);
/*
if (ret < 0) {