[llvm] Add raw_socket_stream (PR #73603)

Connor Sughrue via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 6 20:22:59 PST 2023


================
@@ -942,6 +959,270 @@ bool raw_fd_stream::classof(const raw_ostream *OS) {
   return OS->get_kind() == OStreamKind::OK_FDStream;
 }
 
+//===----------------------------------------------------------------------===//
+//  raw_socket_stream
+//===----------------------------------------------------------------------===//
+
+std::error_code getLastSocketErrorCode() {
+#ifdef _WIN32
+  return std::error_code(::WSAGetLastError(), std::system_category());
+#else
+  return std::error_code(errno, std::system_category());
+#endif
+}
+
+ListeningSocket::ListeningSocket(int SocketFD, StringRef SocketPath)
+    : FD(SocketFD), SocketPath(SocketPath) {}
+
+ListeningSocket::ListeningSocket(ListeningSocket &&LS)
+    : FD(LS.FD), SocketPath(LS.SocketPath) {
+  LS.FD = -1;
+}
+
+Expected<ListeningSocket> ListeningSocket::createUnix(StringRef SocketPath) {
+
+  int MaxBacklog = 3;
----------------
cpsughrue wrote:

Is there a reason `MaxBacklog` is 3? If someone builds with a `-j` limit larger than 3, I don't think the module build daemon will be able to fully handle the first round of requests. I can always implement logic so that the frontend retries establishing a connection when it receives an `ECONNREFUSED` (which I should probably do regardless), but `MaxBacklog` could also equal `llvm::hardware_concurrency().compute_thread_count()` or some factor of it.

https://github.com/llvm/llvm-project/pull/73603


More information about the llvm-commits mailing list