MinGW: Initial compile environment support

This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2023-04-12 10:06:46 +01:00
1 parent aee4c3fa6e
commit 964bd69481
17 files changed
+156 -38

No files matched your search

+16
View File
@@ -241,50 +241,66 @@ coap_resolve_address_info(const coap_str_const_t *server,
if (scheme_hint_bits & (1 << scheme)) {
switch (scheme) {
case COAP_URI_SCHEME_COAP:
#if !defined(__MINGW32__)
if (ainfo->ai_socktype != SOCK_DGRAM)
continue;
#endif /* ! __MINGW32__ */
break;
case COAP_URI_SCHEME_COAPS:
if (!coap_dtls_is_supported())
continue;
#if !defined(__MINGW32__)
if (ainfo->ai_socktype != SOCK_DGRAM)
continue;
#endif /* ! __MINGW32__ */
break;
case COAP_URI_SCHEME_COAP_TCP:
if (!coap_tcp_is_supported())
continue;
#if !defined(__MINGW32__)
if (ainfo->ai_socktype != SOCK_STREAM)
continue;
#endif /* ! __MINGW32__ */
break;
case COAP_URI_SCHEME_COAPS_TCP:
if (!coap_tls_is_supported())
continue;
#if !defined(__MINGW32__)
if (ainfo->ai_socktype != SOCK_STREAM)
continue;
#endif /* ! __MINGW32__ */
break;
case COAP_URI_SCHEME_HTTP:
if (!coap_tcp_is_supported())
continue;
#if !defined(__MINGW32__)
if (ainfo->ai_socktype != SOCK_STREAM)
continue;
#endif /* ! __MINGW32__ */
break;
case COAP_URI_SCHEME_HTTPS:
if (!coap_tls_is_supported())
continue;
#if !defined(__MINGW32__)
if (ainfo->ai_socktype != SOCK_STREAM)
continue;
#endif /* ! __MINGW32__ */
break;
case COAP_URI_SCHEME_COAP_WS:
if (!coap_ws_is_supported())
continue;
#if !defined(__MINGW32__)
if (ainfo->ai_socktype != SOCK_STREAM)
continue;
#endif /* ! __MINGW32__ */
break;
case COAP_URI_SCHEME_COAPS_WS:
if (!coap_wss_is_supported())
continue;
#if !defined(__MINGW32__)
if (ainfo->ai_socktype != SOCK_STREAM)
continue;
#endif /* ! __MINGW32__ */
break;
case COAP_URI_SCHEME_LAST:
default:
+2 -2
View File
@@ -145,7 +145,7 @@ print_timestamp(char *s, size_t len, coap_tick_t t) {
#endif /* HAVE_TIME_H */
#ifndef HAVE_STRNLEN
#if !defined(HAVE_STRNLEN) && !defined(__MINGW32__)
/**
* A length-safe strlen() fake.
*
@@ -161,7 +161,7 @@ strnlen(const char *s, size_t maxlen) {
++n;
return n;
}
#endif /* HAVE_STRNLEN */
#endif /* HAVE_STRNLEN && !__MINGW32__ */
static size_t
print_readable( const uint8_t *data, size_t len,
+15 -9
View File
@@ -716,6 +716,7 @@ coap_socket_read(coap_socket_t *sock, uint8_t *data, size_t data_len) {
/* define struct in6_pktinfo and struct in_pktinfo if not available
FIXME: check with configure
*/
#if !defined(__MINGW32__)
struct in6_pktinfo {
struct in6_addr ipi6_addr; /* src/dst IPv6 address */
unsigned int ipi6_ifindex; /* send/recv interface index */
@@ -726,6 +727,7 @@ struct in_pktinfo {
struct in_addr ipi_spec_dst;
struct in_addr ipi_addr;
};
#endif /* ! __MINGW32__ */
#endif
#endif /* ! WITH_LWIP */
@@ -736,7 +738,9 @@ struct in_pktinfo {
#if defined(_WIN32)
#include <mswsock.h>
#if !defined(__MINGW32__)
static __declspec(thread) LPFN_WSARECVMSG lpWSARecvMsg = NULL;
#endif /* ! __MINGW32__ */
/* Map struct WSABUF fields to their posix counterpart */
#define msghdr _WSAMSG
#define msg_name name
@@ -752,7 +756,9 @@ static __declspec(thread) LPFN_WSARECVMSG lpWSARecvMsg = NULL;
#undef CMSG_DATA
#define CMSG_DATA WSA_CMSG_DATA
#define ipi_spec_dst ipi_addr
#if !defined(__MINGW32__)
#pragma warning( disable : 4116 )
#endif /* ! __MINGW32__ */
#else
#define iov_len_t size_t
#endif
@@ -780,10 +786,10 @@ coap_socket_send(coap_socket_t *sock, const coap_session_t *session, const uint8
bytes_written = send(sock->fd, data, datalen, 0);
#endif
} else {
#ifdef _WIN32
#if defined(_WIN32) && !defined(__MINGW32__)
DWORD dwNumberOfBytesSent = 0;
int r;
#endif
#endif /* _WIN32 && !__MINGW32__ */
#ifdef HAVE_STRUCT_CMSGHDR
/* a buffer large enough to hold all packet info types, ipv6 is the largest */
char buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
@@ -906,21 +912,21 @@ coap_socket_send(coap_socket_t *sock, const coap_session_t *session, const uint8
}
#endif /* HAVE_STRUCT_CMSGHDR */
#ifdef _WIN32
#if defined(_WIN32) && !defined(__MINGW32__)
r = WSASendMsg(sock->fd, &mhdr, 0 /*dwFlags*/, &dwNumberOfBytesSent, NULL /*lpOverlapped*/, NULL /*lpCompletionRoutine*/);
if (r == 0)
bytes_written = (ssize_t)dwNumberOfBytesSent;
else
bytes_written = -1;
#else
#else /* !_WIN32 || __MINGW32__ */
#ifdef HAVE_STRUCT_CMSGHDR
bytes_written = sendmsg(sock->fd, &mhdr, 0);
#else /* ! HAVE_STRUCT_CMSGHDR */
bytes_written = sendto(sock->fd, data, datalen, 0,
bytes_written = sendto(sock->fd, (const void*)data, datalen, 0,
&session->addr_info.remote.addr.sa,
session->addr_info.remote.size);
#endif /* ! HAVE_STRUCT_CMSGHDR */
#endif
#endif /* !_WIN32 || __MINGW32__ */
}
if (bytes_written < 0)
@@ -989,10 +995,10 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) {
packet->length = (size_t)len;
}
} else {
#if defined(_WIN32)
#if defined(_WIN32) && !defined(__MINGW32__)
DWORD dwNumberOfBytesRecvd = 0;
int r;
#endif
#endif /* _WIN32 && !__MINGW32__ */
#ifdef HAVE_STRUCT_CMSGHDR
/* a buffer large enough to hold all packet info types, ipv6 is the largest */
char buf[CMSG_SPACE(sizeof(struct in6_pktinfo))];
@@ -1037,7 +1043,7 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) {
#endif
#else /* ! HAVE_STRUCT_CMSGHDR */
len = recvfrom(sock->fd, packet->payload, COAP_RXBUFFER_SIZE, 0,
len = recvfrom(sock->fd, (void *)packet->payload, COAP_RXBUFFER_SIZE, 0,
&packet->addr_info.remote.addr.sa,
&packet->addr_info.remote.size);
#endif /* ! HAVE_STRUCT_CMSGHDR */
+2 -2
View File
@@ -355,7 +355,7 @@ coap_realloc_type(coap_memory_tag_t type, void *p, size_t size) {
}
#else /* ! RIOT_VERSION */
#ifdef HAVE_MALLOC
#if defined(HAVE_MALLOC) || defined(__MINGW32__)
#include <stdlib.h>
void
@@ -380,7 +380,7 @@ coap_free_type(coap_memory_tag_t type, void *p) {
free(p);
}
#else /* ! HAVE_MALLOC */
#else /* ! HAVE_MALLOC && !__MINGW32__ */
#ifdef WITH_CONTIKI
#include "lib/heapmem.h"
+2 -2
View File
@@ -37,7 +37,7 @@ static coap_tick_t coap_clock_offset = 0;
#define COAP_CLOCK CLOCK_REALTIME
#endif
#ifdef HAVE_WINSOCK2_H
#if defined(HAVE_WINSOCK2_H) && !defined(__MINGW32__)
static int
gettimeofday(struct timeval *tp, TIME_ZONE_INFORMATION *tzp) {
(void)tzp;
@@ -56,7 +56,7 @@ gettimeofday(struct timeval *tp, TIME_ZONE_INFORMATION *tzp) {
tp->tv_usec = (long)(tUsSinceUnicEpoch % 1000000);
return 0;
}
#endif
#endif /* HAVE_WINSOCK2_H && !__MINGW32__ */
void
coap_clock_init(void) {
+4 -4
View File
@@ -234,10 +234,10 @@ coap_ws_write(coap_session_t *session, const uint8_t *data, size_t datalen) {
hdr_len += 2;
} else {
ws_header[1] = 127;
ws_header[2] = (datalen >> 56) & 0xff;
ws_header[3] = (datalen >> 48) & 0xff;
ws_header[4] = (datalen >> 40) & 0xff;
ws_header[5] = (datalen >> 32) & 0xff;
ws_header[2] = ((uint64_t)datalen >> 56) & 0xff;
ws_header[3] = ((uint64_t)datalen >> 48) & 0xff;
ws_header[4] = ((uint64_t)datalen >> 40) & 0xff;
ws_header[5] = ((uint64_t)datalen >> 32) & 0xff;
ws_header[6] = (datalen >> 24) & 0xff;
ws_header[7] = (datalen >> 16) & 0xff;
ws_header[8] = (datalen >> 8) & 0xff;