diff --git a/CMakeLists.txt b/CMakeLists.txt index 889bc69169..da4b90dcf8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -549,15 +549,6 @@ target_include_directories(openPMD PUBLIC $ ) -# Winsock library for gethostname() function on Windows -if(WIN32) - # need to link this publically as WSAStartup() and WSACleanup() need to be - # called surrounding the gethostname() function on Windows - # and it needs to be done at client site since the winsocks API is - # initialized statically per process.... - target_link_libraries(openPMD PUBLIC ws2_32) -endif() - # Catch2 for unit tests if(openPMD_BUILD_TESTING) add_library(openPMD::thirdparty::Catch2 INTERFACE IMPORTED) diff --git a/include/openPMD/ChunkInfo.hpp b/include/openPMD/ChunkInfo.hpp index 0902137a05..3ddaefaff8 100644 --- a/include/openPMD/ChunkInfo.hpp +++ b/include/openPMD/ChunkInfo.hpp @@ -97,7 +97,6 @@ namespace host_info enum class Method { POSIX_HOSTNAME, - WINSOCKS_HOSTNAME, MPI_PROCESSOR_NAME }; @@ -108,7 +107,6 @@ namespace host_info * Currently recognized are: * * * posix_hostname - * * winsocks_hostname * * mpi_processor_name * * For backwards compatibility reasons, "hostname" is also recognized as a @@ -152,24 +150,27 @@ namespace host_info chunk_assignment::RankMeta byMethodCollective(MPI_Comm, Method); #endif -/* - * The following block contains one wrapper for each native hostname retrieval - * method. The purpose is to have the same function pointer type for all - * of them. - */ + /* + * The following block contains one wrapper for each native hostname + * retrieval method. The purpose is to have the same function pointer type + * for all of them. + */ -/* - * @todo Replace _WIN32 with proper Winsocks macro, - * add POSIX availability macro. - */ #ifdef _WIN32 - std::string winsocks_hostname(); +#define openPMD_POSIX_AVAILABLE false #else +#define openPMD_POSIX_AVAILABLE true +#endif + +#if openPMD_POSIX_AVAILABLE std::string posix_hostname(); #endif + #if openPMD_HAVE_MPI std::string mpi_processor_name(); #endif } // namespace host_info } // namespace openPMD + +#undef openPMD_POSIX_AVAILABLE diff --git a/src/ChunkInfo.cpp b/src/ChunkInfo.cpp index fcae8a55bf..f25cc96a3b 100644 --- a/src/ChunkInfo.cpp +++ b/src/ChunkInfo.cpp @@ -24,14 +24,13 @@ #include -/* - * @todo Replace _WIN32 with proper Winsocks macro, - * add POSIX availability macro. - */ - #ifdef _WIN32 -#include +#define openPMD_POSIX_AVAILABLE false #else +#define openPMD_POSIX_AVAILABLE true +#endif + +#if openPMD_POSIX_AVAILABLE #include #endif @@ -71,7 +70,6 @@ namespace host_info static std::map const map{ {"posix_hostname", Method::POSIX_HOSTNAME}, {"hostname", Method::POSIX_HOSTNAME}, - {"winsocks_hostname", Method::WINSOCKS_HOSTNAME}, {"mpi_processor_name", Method::MPI_PROCESSOR_NAME}}; if (descr == "hostname") { @@ -84,12 +82,6 @@ namespace host_info return map.at(descr); } -// @todo do this properly -#ifdef _WIN32 -#define openPMD_POSIX_AVAILABLE false -#else -#define openPMD_POSIX_AVAILABLE true -#endif bool methodAvailable(Method method) { switch (method) @@ -97,8 +89,6 @@ namespace host_info case Method::POSIX_HOSTNAME: return openPMD_POSIX_AVAILABLE; - case Method::WINSOCKS_HOSTNAME: - return !openPMD_POSIX_AVAILABLE; case Method::MPI_PROCESSOR_NAME: return openPMD_HAVE_MPI == 1; } @@ -107,15 +97,13 @@ namespace host_info std::string byMethod(Method method) { - static std::map const map{ -#ifdef _WIN32 - {Method::WINSOCKS_HOSTNAME, &winsocks_hostname} -#else - {Method::POSIX_HOSTNAME, &posix_hostname} + static std::map const map + { +#if openPMD_POSIX_AVAILABLE + {Method::POSIX_HOSTNAME, &posix_hostname}, #endif #if openPMD_HAVE_MPI - , - {Method::MPI_PROCESSOR_NAME, &mpi_processor_name} + {Method::MPI_PROCESSOR_NAME, &mpi_processor_name}, #endif }; try @@ -162,19 +150,7 @@ namespace host_info } #endif -#ifdef _WIN32 - std::string winsocks_hostname() - { - char hostname[MAX_HOSTNAME_LENGTH]; - if (gethostname(hostname, MAX_HOSTNAME_LENGTH)) - { - throw std::runtime_error( - "[winsocks_hostname] Could not inquire hostname."); - } - std::string res(hostname); - return res; - } -#else +#if openPMD_POSIX_AVAILABLE std::string posix_hostname() { char hostname[MAX_HOSTNAME_LENGTH]; @@ -189,3 +165,5 @@ namespace host_info #endif } // namespace host_info } // namespace openPMD + +#undef openPMD_POSIX_AVAILABLE diff --git a/src/binding/python/ChunkInfo.cpp b/src/binding/python/ChunkInfo.cpp index 43fa465126..e18d00face 100644 --- a/src/binding/python/ChunkInfo.cpp +++ b/src/binding/python/ChunkInfo.cpp @@ -77,7 +77,6 @@ void init_Chunk(py::module &m) py::enum_(m, "HostInfo") .value("POSIX_HOSTNAME", host_info::Method::POSIX_HOSTNAME) - .value("WINSOCKS_HOSTNAME", host_info::Method::WINSOCKS_HOSTNAME) .value("MPI_PROCESSOR_NAME", host_info::Method::MPI_PROCESSOR_NAME) #if openPMD_HAVE_MPI .def( diff --git a/test/SerialIOTest.cpp b/test/SerialIOTest.cpp index c6c0dd2b8f..99d8e9b8b9 100644 --- a/test/SerialIOTest.cpp +++ b/test/SerialIOTest.cpp @@ -1562,13 +1562,7 @@ struct ReadFromAnyType inline void write_test(const std::string &backend) { #ifdef _WIN32 - WSADATA wsaData; - WSAStartup(MAKEWORD(2, 0), &wsaData); - std::string jsonCfg = R"({"rank_table": "winsocks_hostname"})"; - chunk_assignment::RankMeta compare{ - {0, - host_info::byMethod( - host_info::methodFromStringDescription("winsocks_hostname"))}}; + std::string jsonCfg = "{}"; #else std::string jsonCfg = R"({"rank_table": "posix_hostname"})"; chunk_assignment::RankMeta compare{ @@ -1689,11 +1683,8 @@ inline void write_test(const std::string &backend) }, variantTypeDataset); - // need double parens here to avoid link errors to unprintableString - // on Windows - REQUIRE((read.mpiRanksMetaInfo(/* collective = */ false) == compare)); -#ifdef _WIN32 - WSACleanup(); +#ifndef _WIN32 + REQUIRE(read.mpiRanksMetaInfo(/* collective = */ false) == compare); #endif } @@ -1846,9 +1837,7 @@ fileBased_add_EDpic(ParticleSpecies &e, uint64_t const num_particles) inline void fileBased_write_test(const std::string &backend) { #ifdef _WIN32 - WSADATA wsaData; - WSAStartup(MAKEWORD(2, 0), &wsaData); - std::string jsonCfg = R"({"rank_table": "winsocks_hostname"})"; + std::string jsonCfg = "{}"; #else std::string jsonCfg = R"({"rank_table": "posix_hostname"})"; #endif @@ -2232,9 +2221,6 @@ inline void fileBased_write_test(const std::string &backend) close(dirfd); } #endif // defined(__unix__) -#ifdef _WIN32 - WSACleanup(); -#endif } TEST_CASE("fileBased_write_test", "[serial]")