================ @@ -0,0 +1,128 @@ +//===------------------------- SocketSupport.cpp --------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#include "clang/Tooling/ModuleBuildDaemon/SocketSupport.h" +#include "clang/Basic/Version.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Tooling/ModuleBuildDaemon/Client.h" +#include "llvm/ADT/ArrayRef.h" +#include "llvm/ADT/ScopeExit.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/Config/llvm-config.h" +#include "llvm/Support/BLAKE3.h" + +// TODO: Make portable +#if LLVM_ON_UNIX + +#include <cerrno> +#include <filesystem> +#include <fstream> +#include <signal.h> +#include <spawn.h> +#include <string> +#include <sys/socket.h> +#include <sys/stat.h> +#include <sys/un.h> +#include <unistd.h> + +Expected<int> cc1modbuildd::createSocket() { + int FD; + if ((FD = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) { + std::string Msg = "socket create error: " + std::string(strerror(errno)); + return createStringError(inconvertibleErrorCode(), Msg); ---------------- cpsughrue wrote:
I've been trying to write error message that contain the errno description and some developer-provided context. For example, `std::perror("Socket bind error: ");` might print something like `"Socket bind error: No such file or directory"` which follows the format `"developer-provided context: errno description"`. I think that format does a good job of providing a helpful error message. Is there a way to return developer-provided context alongside the llvm::Error formed from errno? When returning a `llvm::Error` with something like `return llvm::errorCodeToError(std::error_code(EIO, std::generic_category()));` I have not been able to figure out how to return anything other then the error code. https://github.com/llvm/llvm-project/pull/67562 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits