mirror of
https://github.com/curl/curl.git
synced 2024-11-21 01:16:58 +08:00
cmake: fix support for UnixSockets feature on Win32
Move the definition of sockaddr_un struct from config-win32.h to curl_setup.h, so that it could be shared by all build systems. Add ADDRESS_FAMILY typedef for old mingw, now old mingw can also use unix sockets. Also fix the build of tests/server/sws.c on Win32 when USE_UNIX_SOCKETS is defined. Closes #7034
This commit is contained in:
parent
62be096085
commit
30e491e5c9
@ -807,7 +807,11 @@ endif()
|
|||||||
option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
|
option(ENABLE_UNIX_SOCKETS "Define if you want Unix domain sockets support" ON)
|
||||||
if(ENABLE_UNIX_SOCKETS)
|
if(ENABLE_UNIX_SOCKETS)
|
||||||
include(CheckStructHasMember)
|
include(CheckStructHasMember)
|
||||||
check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
|
if(WIN32)
|
||||||
|
set(USE_UNIX_SOCKETS ON)
|
||||||
|
else()
|
||||||
|
check_struct_has_member("struct sockaddr_un" sun_path "sys/un.h" USE_UNIX_SOCKETS)
|
||||||
|
endif()
|
||||||
else()
|
else()
|
||||||
unset(USE_UNIX_SOCKETS CACHE)
|
unset(USE_UNIX_SOCKETS CACHE)
|
||||||
endif()
|
endif()
|
||||||
|
@ -678,22 +678,8 @@ Vista
|
|||||||
#define USE_WIN32_CRYPTO
|
#define USE_WIN32_CRYPTO
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* On MinGW the ADDRESS_FAMILY typedef was committed alongside LUP_SECURE,
|
|
||||||
so we use it to check for the presence of the typedef. */
|
|
||||||
#include <ws2tcpip.h>
|
|
||||||
#if !defined(__MINGW32__) || defined(LUP_SECURE)
|
|
||||||
/* Define to use Unix sockets. */
|
/* Define to use Unix sockets. */
|
||||||
#define USE_UNIX_SOCKETS
|
#define USE_UNIX_SOCKETS
|
||||||
#if !defined(UNIX_PATH_MAX)
|
|
||||||
/* Replicating logic present in afunix.h of newer Windows 10 SDK versions */
|
|
||||||
# define UNIX_PATH_MAX 108
|
|
||||||
/* !checksrc! disable TYPEDEFSTRUCT 1 */
|
|
||||||
typedef struct sockaddr_un {
|
|
||||||
ADDRESS_FAMILY sun_family;
|
|
||||||
char sun_path[UNIX_PATH_MAX];
|
|
||||||
} SOCKADDR_UN, *PSOCKADDR_UN;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- */
|
/* ---------------------------------------------------------------- */
|
||||||
/* ADDITIONAL DEFINITIONS */
|
/* ADDITIONAL DEFINITIONS */
|
||||||
|
@ -50,12 +50,6 @@
|
|||||||
# define in_addr_t unsigned long
|
# define in_addr_t unsigned long
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(USE_UNIX_SOCKETS) && defined(WINAPI_FAMILY) && \
|
|
||||||
(WINAPI_FAMILY == WINAPI_FAMILY_APP)
|
|
||||||
/* Required for sockaddr_un type */
|
|
||||||
# include <afunix.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "curl_addrinfo.h"
|
#include "curl_addrinfo.h"
|
||||||
|
@ -824,4 +824,20 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf,
|
|||||||
#define ENABLE_QUIC
|
#define ENABLE_QUIC
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(USE_UNIX_SOCKETS) && defined(WIN32)
|
||||||
|
# if defined(__MINGW32__) && !defined(LUP_SECURE)
|
||||||
|
typedef u_short ADDRESS_FAMILY; /* Classic mingw, 11y+ old mingw-w64 */
|
||||||
|
# endif
|
||||||
|
# if !defined(UNIX_PATH_MAX)
|
||||||
|
/* Replicating logic present in afunix.h
|
||||||
|
(distributed with newer Windows 10 SDK versions only) */
|
||||||
|
# define UNIX_PATH_MAX 108
|
||||||
|
/* !checksrc! disable TYPEDEFSTRUCT 1 */
|
||||||
|
typedef struct sockaddr_un {
|
||||||
|
ADDRESS_FAMILY sun_family;
|
||||||
|
char sun_path[UNIX_PATH_MAX];
|
||||||
|
} SOCKADDR_UN, *PSOCKADDR_UN;
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* HEADER_CURL_SETUP_H */
|
#endif /* HEADER_CURL_SETUP_H */
|
||||||
|
@ -2072,9 +2072,9 @@ int main(int argc, char *argv[])
|
|||||||
strncpy(me.sau.sun_path, unix_socket, sizeof(me.sau.sun_path) - 1);
|
strncpy(me.sau.sun_path, unix_socket, sizeof(me.sau.sun_path) - 1);
|
||||||
rc = bind(sock, &me.sa, sizeof(me.sau));
|
rc = bind(sock, &me.sa, sizeof(me.sau));
|
||||||
if(0 != rc && errno == EADDRINUSE) {
|
if(0 != rc && errno == EADDRINUSE) {
|
||||||
struct stat statbuf;
|
struct_stat statbuf;
|
||||||
/* socket already exists. Perhaps it is stale? */
|
/* socket already exists. Perhaps it is stale? */
|
||||||
int unixfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
curl_socket_t unixfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if(CURL_SOCKET_BAD == unixfd) {
|
if(CURL_SOCKET_BAD == unixfd) {
|
||||||
error = SOCKERRNO;
|
error = SOCKERRNO;
|
||||||
logmsg("Error binding socket, failed to create socket at %s: (%d) %s",
|
logmsg("Error binding socket, failed to create socket at %s: (%d) %s",
|
||||||
@ -2084,15 +2084,19 @@ int main(int argc, char *argv[])
|
|||||||
/* check whether the server is alive */
|
/* check whether the server is alive */
|
||||||
rc = connect(unixfd, &me.sa, sizeof(me.sau));
|
rc = connect(unixfd, &me.sa, sizeof(me.sau));
|
||||||
error = errno;
|
error = errno;
|
||||||
close(unixfd);
|
sclose(unixfd);
|
||||||
if(ECONNREFUSED != error) {
|
if(ECONNREFUSED != error) {
|
||||||
logmsg("Error binding socket, failed to connect to %s: (%d) %s",
|
logmsg("Error binding socket, failed to connect to %s: (%d) %s",
|
||||||
unix_socket, error, strerror(error));
|
unix_socket, error, strerror(error));
|
||||||
goto sws_cleanup;
|
goto sws_cleanup;
|
||||||
}
|
}
|
||||||
/* socket server is not alive, now check if it was actually a socket.
|
/* socket server is not alive, now check if it was actually a socket. */
|
||||||
* Systems which have Unix sockets will also have lstat */
|
#ifdef WIN32
|
||||||
|
/* Windows does not have lstat function. */
|
||||||
|
rc = curlx_win32_stat(unix_socket, &statbuf);
|
||||||
|
#else
|
||||||
rc = lstat(unix_socket, &statbuf);
|
rc = lstat(unix_socket, &statbuf);
|
||||||
|
#endif
|
||||||
if(0 != rc) {
|
if(0 != rc) {
|
||||||
logmsg("Error binding socket, failed to stat %s: (%d) %s",
|
logmsg("Error binding socket, failed to stat %s: (%d) %s",
|
||||||
unix_socket, errno, strerror(errno));
|
unix_socket, errno, strerror(errno));
|
||||||
|
Loading…
Reference in New Issue
Block a user