Skip to content

Commit

Permalink
fix(core): disable polling for Windows CE (#5536)
Browse files Browse the repository at this point in the history
Windows CE does not support socket status determination via
WSAPoll, so that CPU-saving measure needs to be disabled.

Fixes #5388
  • Loading branch information
beffe committed May 2, 2023
1 parent 9e86eed commit 0663874
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
13 changes: 10 additions & 3 deletions arch/network_tcp.c
Expand Up @@ -445,10 +445,10 @@ ServerNetworkLayerTCP_start(UA_ServerNetworkLayer *nl, const UA_Logger *logger,
addServerSocket(layer, ai);
}
UA_freeaddrinfo(res);

if(layer->serverSocketsSize == 0) {
return UA_STATUSCODE_BADCOMMUNICATIONERROR;
}
}

/* Get the discovery url from the hostname */
UA_String du = UA_STRING_NULL;
Expand Down Expand Up @@ -846,9 +846,16 @@ UA_ClientConnectionTCP_poll(UA_Connection *connection, UA_UInt32 timeout,
socklen_t len = sizeof(so_error);
ret = UA_getsockopt(connection->sockfd, SOL_SOCKET, SO_ERROR, &so_error, &len);
if(ret != 0 || so_error != 0) {
// UA_LOG_SOCKET_ERRNO_GAI_WRAP because of so_error
// no UA_LOG_SOCKET_ERRNO_GAI_WRAP because of so_error
#ifndef _WIN32
char *errno_str = strerror(ret == 0 ? so_error : UA_ERRNO);
#elif defined(UNDER_CE)
LPVOID errno_str = NULL;
FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, ret == 0 ? so_error : WSAGetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPWSTR)&errno_str, 0,
NULL);
#else
char *errno_str = NULL;
FormatMessageA(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
Expand Down
10 changes: 10 additions & 0 deletions arch/wec7/ua_architecture.h
Expand Up @@ -76,6 +76,15 @@ void UA_sleep_ms(unsigned long ms);
#define UA_WOULDBLOCK WSAEWOULDBLOCK
#define UA_ERR_CONNECTION_PROGRESS WSAEWOULDBLOCK

typedef struct pollfd {
SOCKET fd;
SHORT events;
SHORT revents;
} WSAPOLLFD, *PWSAPOLLFD, *LPWSAPOLLFD;

#define UA_POLLIN 0
#define UA_POLLOUT 0

#define UA_fd_set(fd, fds) FD_SET((UA_SOCKET)fd, fds)
#define UA_fd_isset(fd, fds) FD_ISSET((UA_SOCKET)fd, fds)

Expand All @@ -84,6 +93,7 @@ void UA_sleep_ms(unsigned long ms);
#endif

#define UA_getnameinfo getnameinfo
#define UA_poll(fds,nfds,timeout) 1
#define UA_send(sockfd, buf, len, flags) send(sockfd, buf, (int)(len), flags)
#define UA_recv recv
#define UA_sendto(sockfd, buf, len, flags, dest_addr, addrlen) sendto(sockfd, (const char*)(buf), (int)(len), flags, dest_addr, (int) (addrlen))
Expand Down
6 changes: 4 additions & 2 deletions deps/aa_tree.c
@@ -1,14 +1,16 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2020 (c) Fraunhofer IOSB (Author: Julius Pfrommer)
*/

#include "aa_tree.h"
#include <stddef.h>

#if !defined(_MSC_VER) || _MSC_VER >= 1800
#ifdef UNDER_CE
/* Windows CE: uintptr_t has already been defined by windows.h */
#elif !defined(_MSC_VER) || _MSC_VER >= 1800
# include <inttypes.h>
#elif !defined(uintptr_t)
/* Workaround missing standard includes in older Visual Studio */
Expand Down

0 comments on commit 0663874

Please sign in to comment.