Skip to content

Commit

Permalink
enable HAVE_STRUCT_CMSGHDR when building with mingw
Browse files Browse the repository at this point in the history
  • Loading branch information
anyc committed Jul 11, 2024
1 parent 7d5e5f3 commit deb2768
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ check_function_exists(random HAVE_RANDOM)
check_function_exists(if_nametoindex HAVE_IF_NAMETOINDEX)

# check for symbols
if(WIN32 AND NOT MINGW)
if(WIN32)
set(HAVE_STRUCT_CMSGHDR 1)
message(STATUS "setting HAVE_STRUCT_CMSGHDR")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL QNX)
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ check_function_exists(random HAVE_RANDOM)
check_function_exists(if_nametoindex HAVE_IF_NAMETOINDEX)

# check for symbols
if(WIN32 AND NOT MINGW)
if(WIN32)
set(HAVE_STRUCT_CMSGHDR 1)
message(STATUS "setting HAVE_STRUCT_CMSGHDR")
elseif(${CMAKE_SYSTEM_NAME} STREQUAL QNX)
Expand Down
26 changes: 21 additions & 5 deletions src/coap_io.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ coap_mfree_endpoint(coap_endpoint_t *ep) {
}
#endif /* COAP_SERVER_SUPPORT */

#if defined(__MINGW32__)
#if(_WIN32_WINNT >= 0x0600)
#define CMSG_FIRSTHDR WSA_CMSG_FIRSTHDR
#define CMSG_NXTHDR WSA_CMSG_NXTHDR
#define CMSG_LEN WSA_CMSG_LEN
#define CMSG_SPACE WSA_CMSG_SPACE
#define cmsghdr _WSACMSGHDR
#endif /* (_WIN32_WINNT>=0x0600) */
#endif /* defined(__MINGW32__) */

#if !defined(WITH_CONTIKI) && !defined(WITH_LWIP) && !defined(RIOT_VERSION)

#if COAP_SERVER_SUPPORT
Expand Down Expand Up @@ -734,9 +744,11 @@ struct in_pktinfo {

#if defined(_WIN32)
#include <mswsock.h>
#if !defined(__MINGW32__)
#if defined(__MINGW32__)
static __thread LPFN_WSARECVMSG lpWSARecvMsg = NULL;
#else
static __declspec(thread) LPFN_WSARECVMSG lpWSARecvMsg = NULL;
#endif /* ! __MINGW32__ */
#endif /* defined(__MINGW32__) */
/* Map struct WSABUF fields to their posix counterpart */
#define msghdr _WSAMSG
#define msg_name name
Expand Down Expand Up @@ -783,7 +795,7 @@ coap_socket_send(coap_socket_t *sock, const coap_session_t *session,
bytes_written = send(sock->fd, data, datalen, 0);
#endif
} else {
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(_WIN32)
DWORD dwNumberOfBytesSent = 0;
int r;
#endif /* _WIN32 && !__MINGW32__ */
Expand Down Expand Up @@ -920,7 +932,7 @@ coap_socket_send(coap_socket_t *sock, const coap_session_t *session,
}
#endif /* HAVE_STRUCT_CMSGHDR */

#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(_WIN32)
r = WSASendMsg(sock->fd, &mhdr, 0 /*dwFlags*/, &dwNumberOfBytesSent, NULL /*lpOverlapped*/,
NULL /*lpCompletionRoutine*/);
if (r == 0)
Expand Down Expand Up @@ -1005,7 +1017,7 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) {
packet->length = (size_t)len;
}
} else {
#if defined(_WIN32) && !defined(__MINGW32__)
#if defined(_WIN32)
DWORD dwNumberOfBytesRecvd = 0;
int r;
#endif /* _WIN32 && !__MINGW32__ */
Expand All @@ -1016,7 +1028,11 @@ coap_socket_recv(coap_socket_t *sock, coap_packet_t *packet) {
struct msghdr mhdr;
struct iovec iov[1];

#if defined(__MINGW32__)
iov[0].iov_base = (char*) packet->payload;
#else
iov[0].iov_base = packet->payload;
#endif /* defined(__MINGW32__) */
iov[0].iov_len = (iov_len_t)COAP_RXBUFFER_SIZE;

memset(&mhdr, 0, sizeof(struct msghdr));
Expand Down

0 comments on commit deb2768

Please sign in to comment.