From 5f7549edaaa33bf7fa0c1dd4e164d188ae4e5cd4 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 7 Aug 2019 15:44:19 +0200 Subject: [PATCH v3 1/7] Enable Unix-domain sockets support on Windows As of Windows 10 version 1803, Unix-domain sockets are supported on Windows. But it's not automatically detected by configure because it looks for struct sockaddr_un and Windows doesn't define that. So we just make our own definition on Windows and override the configure result. --- config/c-library.m4 | 5 +++-- configure | 5 ++++- src/include/c.h | 11 +++++++++++ src/include/pg_config.h.in | 6 +++--- src/include/pg_config.h.win32 | 6 +++--- src/include/pg_config_manual.h | 7 ------- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/config/c-library.m4 b/config/c-library.m4 index 6f2b0fbb4e..1469b07d2f 100644 --- a/config/c-library.m4 +++ b/config/c-library.m4 @@ -121,10 +121,11 @@ AC_DEFUN([PGAC_UNION_SEMUN], # PGAC_STRUCT_SOCKADDR_UN # ----------------------- -# If `struct sockaddr_un' exists, define HAVE_UNIX_SOCKETS. +# If `struct sockaddr_un' exists, define HAVE_STRUCT_SOCKADDR_UN. +# If it is missing then one could define it. # (Requires test for !) AC_DEFUN([PGAC_STRUCT_SOCKADDR_UN], -[AC_CHECK_TYPE([struct sockaddr_un], [AC_DEFINE(HAVE_UNIX_SOCKETS, 1, [Define to 1 if you have unix sockets.])], [], +[AC_CHECK_TYPES([struct sockaddr_un], [], [], [#include #ifdef HAVE_SYS_UN_H #include diff --git a/configure b/configure index f14709ed1e..da1ef11991 100755 --- a/configure +++ b/configure @@ -14079,7 +14079,10 @@ ac_fn_c_check_type "$LINENO" "struct sockaddr_un" "ac_cv_type_struct_sockaddr_un " if test "x$ac_cv_type_struct_sockaddr_un" = xyes; then : -$as_echo "#define HAVE_UNIX_SOCKETS 1" >>confdefs.h +cat >>confdefs.h <<_ACEOF +#define HAVE_STRUCT_SOCKADDR_UN 1 +_ACEOF + fi diff --git a/src/include/c.h b/src/include/c.h index f461628a24..af690f0f5e 100644 --- a/src/include/c.h +++ b/src/include/c.h @@ -1277,6 +1277,17 @@ extern unsigned long long strtoull(const char *str, char **endptr, int base); #define NON_EXEC_STATIC static #endif +#ifdef HAVE_STRUCT_SOCKADDR_UN +#define HAVE_UNIX_SOCKETS 1 +#elif defined(WIN32) +struct sockaddr_un +{ + unsigned short sun_family; + char sun_path[108]; +}; +#define HAVE_UNIX_SOCKETS 1 +#endif + /* /port compatibility functions */ #include "port.h" diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in index d876926c21..dfcd7da569 100644 --- a/src/include/pg_config.h.in +++ b/src/include/pg_config.h.in @@ -588,6 +588,9 @@ /* Define to 1 if `__ss_len' is a member of `struct sockaddr_storage'. */ #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN +/* Define to 1 if the system has the type `struct sockaddr_un'. */ +#undef HAVE_STRUCT_SOCKADDR_UN + /* Define to 1 if `tm_zone' is a member of `struct tm'. */ #undef HAVE_STRUCT_TM_TM_ZONE @@ -676,9 +679,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_UNISTD_H -/* Define to 1 if you have unix sockets. */ -#undef HAVE_UNIX_SOCKETS - /* Define to 1 if you have the `unsetenv' function. */ #undef HAVE_UNSETENV diff --git a/src/include/pg_config.h.win32 b/src/include/pg_config.h.win32 index fc50528590..08a3c0d916 100644 --- a/src/include/pg_config.h.win32 +++ b/src/include/pg_config.h.win32 @@ -457,6 +457,9 @@ /* Define to 1 if `__ss_len' is member of `struct sockaddr_storage'. */ /* #undef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN */ +/* Define to 1 if the system has the type `struct sockaddr_un'. */ +/* #undef HAVE_STRUCT_SOCKADDR_UN */ + /* Define to 1 if `tm_zone' is member of `struct tm'. */ /* #undef HAVE_STRUCT_TM_TM_ZONE */ @@ -524,9 +527,6 @@ /* Define to 1 if you have the header file. */ #define HAVE_UNISTD_H 1 -/* Define to 1 if you have unix sockets. */ -/* #undef HAVE_UNIX_SOCKETS */ - /* Define to 1 if you have the `unsetenv' function. */ /* #undef HAVE_UNSETENV */ diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h index 743401cb96..65d20d44b3 100644 --- a/src/include/pg_config_manual.h +++ b/src/include/pg_config_manual.h @@ -109,13 +109,6 @@ */ #define ALIGNOF_BUFFER 32 -/* - * Disable UNIX sockets for certain operating systems. - */ -#if defined(WIN32) -#undef HAVE_UNIX_SOCKETS -#endif - /* * Define this if your operating system supports link() */ base-commit: 1d7a6e3eb45946db86d6d1776c55323740d955b0 -- 2.22.0