From 04830e8c23061e06f62a94714c1d0c415382cfaa Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Tue, 1 Nov 2022 09:39:50 -0500 Subject: [PATCH] build: Port use of shutdown() on mingw Even though mingw's has a definition for SHUT_WR, it is guarded by _POSIX_SOURCE, and does not get enabled in our build setup. We can instead utilize winsock2.h's non-standard names for shutdown(how). We also need to allow for a missing definition of ESHUTDOWN. Fixes: bf8653b3 ("server: Give client EOF when we are done writing") Fixes: 6a7def7e ("blocksize-policy: Add blocksize-write-disconnect=N parameter") --- common/utils/windows-compat.h | 8 +++++++- filters/blocksize-policy/policy.c | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/common/utils/windows-compat.h b/common/utils/windows-compat.h index 658c1d8bc..6d84a39a3 100644 --- a/common/utils/windows-compat.h +++ b/common/utils/windows-compat.h @@ -1,5 +1,5 @@ /* nbdkit - * Copyright (C) 2020 Red Hat Inc. + * Copyright (C) 2020-2022 Red Hat Inc. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -85,6 +85,12 @@ struct sockaddr_un #define ESHUTDOWN ECONNABORTED #endif +/* Windows uses non-standard names for shutdown(how). */ +#ifndef SHUT_WR +#define SHUT_WR SD_SEND +#define SHUT_RDWR SD_BOTH +#endif + /* This generated function translates Winsock errors into errno codes. */ extern int translate_winsock_error (const char *fn, int err); diff --git a/filters/blocksize-policy/policy.c b/filters/blocksize-policy/policy.c index f7cff2f11..7e6f2a968 100644 --- a/filters/blocksize-policy/policy.c +++ b/filters/blocksize-policy/policy.c @@ -43,6 +43,7 @@ #include "ispowerof2.h" #include "rounding.h" +#include "windows-compat.h" /* Block size constraints configured on the command line (0 = unset). */ static uint32_t config_minimum;