Skip to content

Commit bd11d02

Browse files
authored
fix host emulation on macOS (#5633)
1 parent b666435 commit bd11d02

10 files changed

+48
-19
lines changed

Diff for: cores/esp8266/HardwareSerial.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class HardwareSerial: public Stream
167167
{
168168
return write((uint8_t) n);
169169
}
170-
size_t write(const uint8_t *buffer, size_t size)
170+
size_t write(const uint8_t *buffer, size_t size) override
171171
{
172172
return uart_write(_uart, (const char*)buffer, size);
173173
}

Diff for: tests/host/common/Arduino.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ extern "C" void esp_yield()
4343

4444

4545
extern "C" void __panic_func(const char* file, int line, const char* func) {
46+
(void)file;
47+
(void)line;
48+
(void)func;
4649
abort();
4750
}
4851

Diff for: tests/host/common/Arduino.h

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ extern "C" {
3434
#include <stdio.h>
3535
#include <string.h>
3636
#include <math.h>
37+
#include <errno.h>
3738

3839
#include "binary.h"
3940
#include "twi.h"
@@ -249,11 +250,13 @@ extern "C" {
249250
#include "Updater.h"
250251
#include "debug.h"
251252

253+
#if 0
252254
#ifndef _GLIBCXX_VECTOR
253255
// arduino is not compatible with std::vector
254256
#define min(a,b) ((a)<(b)?(a):(b))
255257
#define max(a,b) ((a)>(b)?(a):(b))
256258
#endif
259+
#endif
257260

258261
#define _min(a,b) ((a)<(b)?(a):(b))
259262
#define _max(a,b) ((a)>(b)?(a):(b))

Diff for: tests/host/common/ClientContextSocket.cpp

+26-9
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@
3939
#include <fcntl.h>
4040
#include <errno.h>
4141

42+
int mockSockSetup (int sock)
43+
{
44+
if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1)
45+
{
46+
fprintf(stderr, MOCK "socket fcntl(O_NONBLOCK): %s\n", strerror(errno));
47+
close(sock);
48+
return -1;
49+
}
50+
51+
#ifndef MSG_NOSIGNAL
52+
int i = 1;
53+
if (setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, &i, sizeof i) == -1)
54+
{
55+
fprintf(stderr, MOCK "sockopt( SO_NOSIGPIPE)(macOS): %s\n", strerror(errno));
56+
return -1;
57+
}
58+
#endif
59+
60+
return sock;
61+
}
62+
4263
int mockConnect (uint32_t ipv4, int& sock, int port)
4364
{
4465
struct sockaddr_in server;
@@ -56,14 +77,7 @@ int mockConnect (uint32_t ipv4, int& sock, int port)
5677
return 0;
5778
}
5879

59-
if (fcntl(sock, F_SETFL, O_NONBLOCK) == -1)
60-
{
61-
fprintf(stderr, MOCK "ClientContext::connect: fcntl(O_NONBLOCK): %s\n", strerror(errno));
62-
close(sock);
63-
return 0;
64-
}
65-
66-
return 1;
80+
return mockSockSetup(sock) == -1? 0: 1;
6781
}
6882

6983
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)
142156
}
143157
if (ret)
144158
{
145-
//ret = ::write(sock, data, size);
159+
#ifndef MSG_NOSIGNAL
160+
ret = ::write(sock, data, size);
161+
#else
146162
ret = ::send(sock, data, size, MSG_NOSIGNAL);
163+
#endif
147164
if (ret == -1)
148165
{
149166
fprintf(stderr, MOCK "ClientContext::read: write(%d): %s\n", sock, strerror(errno));

Diff for: tests/host/common/MockWiFiServerSocket.cpp

+1-7
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,7 @@ int serverAccept (int srvsock)
5555
perror(MOCK "accept()");
5656
exit(EXIT_FAILURE);
5757
}
58-
if (fcntl(clisock, F_SETFL, O_NONBLOCK) == -1)
59-
{
60-
fprintf(stderr, MOCK "ClientContext::accept: fcntl(O_NONBLOCK): %s\n", strerror(errno));
61-
close(clisock);
62-
exit(EXIT_FAILURE);
63-
}
64-
return clisock;
58+
return mockSockSetup(clisock);
6559
}
6660

6761
void WiFiServer::begin (uint16_t port)

Diff for: tests/host/common/UdpContextSocket.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <fcntl.h>
3838
#include <errno.h>
3939
#include <assert.h>
40+
#include <net/if.h>
4041

4142
int mockUDPSocket ()
4243
{
@@ -87,7 +88,12 @@ bool mockUDPListen (int sock, uint32_t dstaddr, uint16_t port, uint32_t mcast)
8788
mreq.imr_interface.s_addr = htonl(INADDR_ANY);
8889
if (global_ipv4_netfmt)
8990
{
91+
#if __APPLE__
92+
int idx = if_nametoindex(host_interface);
93+
if (setsockopt(sock, IPPROTO_TCP, IP_BOUND_IF, &idx, sizeof(idx)) == -1)
94+
#else
9095
if (setsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, host_interface, strlen(host_interface)) == -1)
96+
#endif
9197
fprintf(stderr, MOCK "UDP multicast: can't setup bind/output on interface %s: %s\n", host_interface, strerror(errno));
9298
if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_IF, &mreq.imr_interface, sizeof(struct in_addr)) == -1)
9399
fprintf(stderr, MOCK "UDP multicast: can't setup bind/input on interface %s: %s\n", host_interface, strerror(errno));

Diff for: tests/host/common/c_types.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef signed long long sint64_t;
4444
typedef float real32_t;
4545
typedef double real64_t;
4646

47-
typedef unsigned char uint8;
47+
// CONFLICT typedef unsigned char uint8;
4848
typedef unsigned char u8;
4949
typedef signed char sint8;
5050
typedef signed char int8;
@@ -53,7 +53,7 @@ typedef unsigned short uint16;
5353
typedef unsigned short u16;
5454
typedef signed short sint16;
5555
typedef signed short s16;
56-
typedef unsigned int uint32;
56+
// CONFLICT typedef unsigned int uint32;
5757
typedef unsigned int u_int;
5858
typedef unsigned int u32;
5959
typedef signed int sint32;

Diff for: tests/host/common/include/ClientContext.h

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ class ClientContext
198198

199199
bool wait_until_sent(int max_wait_ms = WIFICLIENT_MAX_FLUSH_WAIT_MS)
200200
{
201+
(void)max_wait_ms;
201202
return true;
202203
}
203204

Diff for: tests/host/common/mock.h

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ extern uint32_t global_ipv4_netfmt; // selected interface addresse to bind to
9595
#endif
9696

9797
// tcp
98+
int mockSockSetup (int sock);
9899
int mockConnect (uint32_t addr, int& sock, int port);
99100
ssize_t mockFillInBuf (int sock, char* ccinbuf, size_t& ccinbufsize);
100101
ssize_t mockPeekBytes (int sock, char* dst, size_t size, int timeout_ms, char* buf, size_t& bufsize);

Diff for: tests/host/common/user_interface.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ uint8 wifi_get_listen_interval (void)
175175

176176
bool wifi_get_macaddr(uint8 if_index, uint8 *macaddr)
177177
{
178+
(void)if_index;
178179
macaddr[0] = 0xde;
179180
macaddr[1] = 0xba;
180181
macaddr[2] = 0x7a;
@@ -237,6 +238,7 @@ bool wifi_set_opmode_current (uint8 opmode)
237238

238239
bool wifi_set_phy_mode (phy_mode_t mode)
239240
{
241+
(void)mode;
240242
return true;
241243
}
242244

@@ -398,6 +400,7 @@ bool wifi_softap_set_dhcps_offer_option(uint8 level, void* optarg)
398400

399401
bool wifi_station_scan(struct scan_config *config, scan_done_cb_t cb)
400402
{
403+
(void)config;
401404
cb(nullptr, FAIL);
402405
return false;
403406
}
@@ -434,6 +437,7 @@ void dns_setserver (u8_t numdns, ip_addr_t *dnsserver)
434437

435438
ip_addr_t dns_getserver (u8_t numdns)
436439
{
440+
(void)numdns;
437441
ip_addr_t addr = { 0x7f000001 };
438442
return addr;
439443
}

0 commit comments

Comments
 (0)