[llvm] Add raw_socket_stream (PR #73603)

Michael Spencer via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 30 03:12:31 PST 2023


================
@@ -942,6 +955,154 @@ bool raw_fd_stream::classof(const raw_ostream *OS) {
   return OS->get_kind() == OStreamKind::OK_FDStream;
 }
 
+//===----------------------------------------------------------------------===//
+//  raw_socket_stream
+//===----------------------------------------------------------------------===//
+
+int raw_socket_stream::MakeServerSocket(StringRef SocketPath,
+                                        unsigned int MaxBacklog,
+                                        std::error_code &EC) {
+
+#ifdef _WIN32
+  SOCKET MaybeWinsocket = socket(AF_UNIX, SOCK_STREAM, 0);
+#else
+  int MaybeWinsocket = socket(AF_UNIX, SOCK_STREAM, 0);
+#endif // defined(_WIN32)
+
+#ifdef _WIN32
+  if (MaybeWinsocket == INVALID_SOCKET) {
+#else
+  if (MaybeWinsocket == -1) {
+#endif // _WIN32
+    std::string Msg = "socket create error" + std::string(strerror(errno));
+    std::perror(Msg.c_str());
+    std::cout << Msg << std::endl;
----------------
Bigcheese wrote:

You shouldn't be emitting an error message here, instead the error should be propagated out.

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


More information about the llvm-commits mailing list