From 14f03de0026d819300ce43d68312421bdb872476 Mon Sep 17 00:00:00 2001 From: "Enrico Weigelt, metux IT consult" Date: Tue, 10 Feb 2026 11:11:01 +0100 Subject: [PATCH] xwin: move winsock specific errno checks into ossock Signed-off-by: Enrico Weigelt, metux IT consult --- hw/xwin/winclipboard/meson.build | 2 ++ hw/xwin/winclipboard/thread.c | 23 +++-------------------- include/meson.build | 2 -- include/xwin-config.h.meson.in | 3 --- os/ossock.c | 19 +++++++++++++++++++ os/ossock.h | 12 ++++++++++++ 6 files changed, 36 insertions(+), 25 deletions(-) diff --git a/hw/xwin/winclipboard/meson.build b/hw/xwin/winclipboard/meson.build index 8db06a4859..e5bf530797 100644 --- a/hw/xwin/winclipboard/meson.build +++ b/hw/xwin/winclipboard/meson.build @@ -23,12 +23,14 @@ xwin_clipboard = static_library( srcs_xwinclip = [ 'xwinclip.c', 'debug.c', + '../../../os/ossock.c', ] executable( 'xwinclip', srcs_xwinclip, dependencies: dependency('xcb'), + include_directories: inc, link_with: xwin_clipboard, link_args: ['-lgdi32', '-lpthread'], install: true, diff --git a/hw/xwin/winclipboard/thread.c b/hw/xwin/winclipboard/thread.c index 0e60c1b24a..fd3be6724f 100644 --- a/hw/xwin/winclipboard/thread.c +++ b/hw/xwin/winclipboard/thread.c @@ -32,8 +32,6 @@ #ifdef HAVE_XWIN_CONFIG_H #include -#else -#define HAS_WINSOCK 1 #endif #include @@ -42,17 +40,13 @@ #include #include // for MAX() macro -#ifdef HAS_WINSOCK -#include -#else -#include -#endif - #include #include #include #include +#include "os/ossock.h" + #include "winclipboard.h" #include "internal.h" @@ -119,7 +113,6 @@ winClipboardProc(char *szDisplay, xcb_auth_info_t *auth_info) int iMaxDescriptor; xcb_connection_t *conn; xcb_window_t iWindow = XCB_NONE; - int iSelectError; BOOL fShutdown = FALSE; ClipboardConversionData data; int screen; @@ -291,18 +284,8 @@ winClipboardProc(char *szDisplay, xcb_auth_info_t *auth_info) #endif ); -#ifndef HAS_WINSOCK - iSelectError = errno; -#else - iSelectError = WSAGetLastError(); -#endif - if (iReturn < 0) { -#ifndef HAS_WINSOCK - if (iSelectError == EINTR) -#else - if (iSelectError == WSAEINTR) -#endif + if (ossock_eintr(ossock_errno())) continue; ErrorF("winClipboardProc - Call to select () failed: %d. " diff --git a/include/meson.build b/include/meson.build index fa8c8f4029..4bc7a66170 100644 --- a/include/meson.build +++ b/include/meson.build @@ -389,8 +389,6 @@ endif xwin_data = configuration_data() xwin_data.set_quoted('DEFAULT_LOGDIR', log_dir) -xwin_data.set('HAS_WINSOCK', host_machine.system() == 'windows' ? '1' : false, - description: 'Use Windows sockets') xwin_data.set('HAS_DEVWINDOWS', host_machine.system() == 'cygwin' ? '1' : false, description: 'Has /dev/windows for signaling new win32 messages') xwin_data.set('RELOCATE_PROJECTROOT', host_machine.system() == 'windows' ? '1' : false, diff --git a/include/xwin-config.h.meson.in b/include/xwin-config.h.meson.in index 22b97fbefc..00dcd110f6 100644 --- a/include/xwin-config.h.meson.in +++ b/include/xwin-config.h.meson.in @@ -10,9 +10,6 @@ #include -/* Winsock networking */ -#mesondefine HAS_WINSOCK - /* Cygwin has /dev/windows for signaling new win32 messages */ #mesondefine HAS_DEVWINDOWS diff --git a/os/ossock.c b/os/ossock.c index 68e1cdb29e..b9d26eb64f 100644 --- a/os/ossock.c +++ b/os/ossock.c @@ -5,6 +5,7 @@ #include #include +#include #ifdef WIN32 #include @@ -55,3 +56,21 @@ int ossock_wouldblock(int err) return ((err == EAGAIN) || (err == EWOULDBLOCK)); #endif } + +bool ossock_eintr(int err) +{ +#ifdef WIN32 + return (err == WSAEINTR); +#else + return (err == EINTR); +#endif +} + +int ossock_errno(void) +{ +#ifdef WIN32 + return WSAGetLastError(); +#else + return errno; +#endif +} diff --git a/os/ossock.h b/os/ossock.h index b2475285b8..a4c6c8c4d9 100644 --- a/os/ossock.h +++ b/os/ossock.h @@ -6,6 +6,7 @@ #define _XSERVER_OS_OSSOCK_H_ #include +#include /* * os specific initialization of the socket layer @@ -27,4 +28,15 @@ int ossock_close(int fd); */ int ossock_wouldblock(int err); +/* + * os specific check for errno indicating operation interrupted + */ +bool ossock_eintr(int err); + +/* + * os specific retrieval of last socket operation error + * on Unix: errno, on Win32: GetWSALastError() + */ +int ossock_errno(void); + #endif /* _XSERVER_OS_OSSOCK_H_ */