diff --git a/src/net/SocketError.hxx b/src/net/SocketError.hxx index 5c7ab6949..cca051c8e 100644 --- a/src/net/SocketError.hxx +++ b/src/net/SocketError.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2015-2021 Max Kellermann + * Copyright 2015-2022 Max Kellermann * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -27,8 +27,7 @@ * OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef SOCKET_ERROR_HXX -#define SOCKET_ERROR_HXX +#pragma once #include "system/Error.hxx" @@ -168,6 +167,20 @@ public: } }; +/** + * Returns the error_category to be used to wrap socket errors. + */ +[[gnu::const]] +static inline const std::error_category & +SocketErrorCategory() noexcept +{ +#ifdef _WIN32 + return LastErrorCategory(); +#else + return ErrnoCategory(); +#endif +} + [[gnu::pure]] static inline auto MakeSocketError(socket_error_t code, const char *msg) noexcept @@ -185,5 +198,3 @@ MakeSocketError(const char *msg) noexcept { return MakeSocketError(GetSocketError(), msg); } - -#endif