1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

fix host emulation on macOS (#5633)

This commit is contained in:
david gauchard 2019-01-19 03:19:17 +01:00 committed by GitHub
parent b666435282
commit bd11d026e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 48 additions and 19 deletions

View File

@ -167,7 +167,7 @@ public:
{ {
return write((uint8_t) n); return write((uint8_t) n);
} }
size_t write(const uint8_t *buffer, size_t size) size_t write(const uint8_t *buffer, size_t size) override
{ {
return uart_write(_uart, (const char*)buffer, size); return uart_write(_uart, (const char*)buffer, size);
} }

View File

@ -43,6 +43,9 @@ extern "C" void esp_yield()
extern "C" void __panic_func(const char* file, int line, const char* func) { extern "C" void __panic_func(const char* file, int line, const char* func) {
(void)file;
(void)line;
(void)func;
abort(); abort();
} }

View File

@ -34,6 +34,7 @@ extern "C" {
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <math.h> #include <math.h>
#include <errno.h>
#include "binary.h" #include "binary.h"
#include "twi.h" #include "twi.h"
@ -249,11 +250,13 @@ extern "C" {
#include "Updater.h" #include "Updater.h"
#include "debug.h" #include "debug.h"
#if 0
#ifndef _GLIBCXX_VECTOR #ifndef _GLIBCXX_VECTOR
// arduino is not compatible with std::vector // arduino is not compatible with std::vector
#define min(a,b) ((a)<(b)?(a):(b)) #define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b)) #define max(a,b) ((a)>(b)?(a):(b))
#endif #endif
#endif
#define _min(a,b) ((a)<(b)?(a):(b)) #define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b)) #define _max(a,b) ((a)>(b)?(a):(b))

View File

@ -39,6 +39,27 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
int mockSockSetup (int sock)
{
if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1)
{
fprintf(stderr, MOCK "socket fcntl(O_NONBLOCK): %s\n", strerror(errno));
close(sock);
return -1;
}
#ifndef MSG_NOSIGNAL
int i = 1;
if (setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, &i, sizeof i) == -1)
{
fprintf(stderr, MOCK "sockopt( SO_NOSIGPIPE)(macOS): %s\n", strerror(errno));
return -1;
}
#endif
return sock;
}
int mockConnect (uint32_t ipv4, int& sock, int port) int mockConnect (uint32_t ipv4, int& sock, int port)
{ {
struct sockaddr_in server; struct sockaddr_in server;
@ -56,14 +77,7 @@ int mockConnect (uint32_t ipv4, int& sock, int port)
return 0; return 0;
} }
if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1) return mockSockSetup(sock) == -1? 0: 1;
{
fprintf(stderr, MOCK "ClientContext::connect: fcntl(O_NONBLOCK): %s\n", strerror(errno));
close(sock);
return 0;
}
return 1;
} }
ssize_t mockFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize) ssize_t mockFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize)
@ -142,8 +156,11 @@ ssize_t mockWrite (int sock, const uint8_t* data, size_t size, int timeout_ms)
} }
if (ret) if (ret)
{ {
//ret = ::write(sock, data, size); #ifndef MSG_NOSIGNAL
ret = ::write(sock, data, size);
#else
ret = ::send(sock, data, size, MSG_NOSIGNAL); ret = ::send(sock, data, size, MSG_NOSIGNAL);
#endif
if (ret == -1) if (ret == -1)
{ {
fprintf(stderr, MOCK "ClientContext::read: write(%d): %s\n", sock, strerror(errno)); fprintf(stderr, MOCK "ClientContext::read: write(%d): %s\n", sock, strerror(errno));

View File

@ -55,13 +55,7 @@ int serverAccept (int srvsock)
perror(MOCK "accept()"); perror(MOCK "accept()");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (fcntl(clisock, F_SETFL, O_NONBLOCK) == -1) return mockSockSetup(clisock);
{
fprintf(stderr, MOCK "ClientContext::accept: fcntl(O_NONBLOCK): %s\n", strerror(errno));
close(clisock);
exit(EXIT_FAILURE);
}
return clisock;
} }
void WiFiServer::begin (uint16_t port) void WiFiServer::begin (uint16_t port)

View File

@ -37,6 +37,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <assert.h> #include <assert.h>
#include <net/if.h>
int mockUDPSocket () int mockUDPSocket ()
{ {
@ -87,7 +88,12 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
mreq.imr_interface.s_addr = htonl(INADDR_ANY); mreq.imr_interface.s_addr = htonl(INADDR_ANY);
if (global_ipv4_netfmt) if (global_ipv4_netfmt)
{ {
#if __APPLE__
int idx = if_nametoindex(host_interface);
if (setsockopt(sock, IPPROTO_TCP, IP_BOUND_IF, &idx, sizeof(idx)) == -1)
#else
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, host_interface, strlen(host_interface)) == -1) if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, host_interface, strlen(host_interface)) == -1)
#endif
fprintf(stderr, MOCK "UDP multicast: can't setup bind/output on interface %s: %s\n", host_interface, strerror(errno)); fprintf(stderr, MOCK "UDP multicast: can't setup bind/output on interface %s: %s\n", host_interface, strerror(errno));
if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &mreq.imr_interface, sizeof(struct in_addr)) == -1) if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &mreq.imr_interface, sizeof(struct in_addr)) == -1)
fprintf(stderr, MOCK "UDP multicast: can't setup bind/input on interface %s: %s\n", host_interface, strerror(errno)); fprintf(stderr, MOCK "UDP multicast: can't setup bind/input on interface %s: %s\n", host_interface, strerror(errno));

View File

@ -44,7 +44,7 @@ typedef signed long long sint64_t;
typedef float real32_t; typedef float real32_t;
typedef double real64_t; typedef double real64_t;
typedef unsigned char uint8; // CONFLICT typedef unsigned char uint8;
typedef unsigned char u8; typedef unsigned char u8;
typedef signed char sint8; typedef signed char sint8;
typedef signed char int8; typedef signed char int8;
@ -53,7 +53,7 @@ typedef unsigned short uint16;
typedef unsigned short u16; typedef unsigned short u16;
typedef signed short sint16; typedef signed short sint16;
typedef signed short s16; typedef signed short s16;
typedef unsigned int uint32; // CONFLICT typedef unsigned int uint32;
typedef unsigned int u_int; typedef unsigned int u_int;
typedef unsigned int u32; typedef unsigned int u32;
typedef signed int sint32; typedef signed int sint32;

View File

@ -198,6 +198,7 @@ public:
bool wait_until_sent(int max_wait_ms = WIFICLIENT_MAX_FLUSH_WAIT_MS) bool wait_until_sent(int max_wait_ms = WIFICLIENT_MAX_FLUSH_WAIT_MS)
{ {
(void)max_wait_ms;
return true; return true;
} }

View File

@ -95,6 +95,7 @@ extern uint32_t global_ipv4_netfmt; // selected interface addresse to bind to
#endif #endif
// tcp // tcp
int mockSockSetup (int sock);
int mockConnect (uint32_t addr, int& sock, int port); int mockConnect (uint32_t addr, int& sock, int port);
ssize_t mockFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize); ssize_t mockFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize);
ssize_t mockPeekBytes (int sock, char* dst, size_t size, int timeout_ms, char* buf, size_t& bufsize); ssize_t mockPeekBytes (int sock, char* dst, size_t size, int timeout_ms, char* buf, size_t& bufsize);

View File

@ -175,6 +175,7 @@ uint8 wifi_get_listen_interval (void)
bool wifi_get_macaddr(uint8 if_index, uint8 *macaddr) bool wifi_get_macaddr(uint8 if_index, uint8 *macaddr)
{ {
(void)if_index;
macaddr[0] = 0xde; macaddr[0] = 0xde;
macaddr[1] = 0xba; macaddr[1] = 0xba;
macaddr[2] = 0x7a; macaddr[2] = 0x7a;
@ -237,6 +238,7 @@ bool wifi_set_opmode_current (uint8 opmode)
bool wifi_set_phy_mode (phy_mode_t mode) bool wifi_set_phy_mode (phy_mode_t mode)
{ {
(void)mode;
return true; return true;
} }
@ -398,6 +400,7 @@ bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg)
bool wifi_station_scan(struct scan_config *config, scan_done_cb_t cb) bool wifi_station_scan(struct scan_config *config, scan_done_cb_t cb)
{ {
(void)config;
cb(nullptr, FAIL); cb(nullptr, FAIL);
return false; return false;
} }
@ -434,6 +437,7 @@ void dns_setserver (u8_t numdns, ip_addr_t *dnsserver)
ip_addr_t dns_getserver (u8_t numdns) ip_addr_t dns_getserver (u8_t numdns)
{ {
(void)numdns;
ip_addr_t addr = { 0x7f000001 }; ip_addr_t addr = { 0x7f000001 };
return addr; return addr;
} }