1
- // ===--- raw_ostream.cpp - Implement the raw_ostream classes --------------===//
1
+ // ===--- raw_ostream.cpp - Implement the raw_ostream classes --------------===//
2
2
//
3
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
4
// See https://llvm.org/LICENSE.txt for license information.
15
15
#include " llvm/Config/config.h"
16
16
#include " llvm/Support/Compiler.h"
17
17
#include " llvm/Support/Duration.h"
18
+ #include " llvm/Support/Error.h"
18
19
#include " llvm/Support/ErrorHandling.h"
19
20
#include " llvm/Support/FileSystem.h"
20
21
#include " llvm/Support/Format.h"
24
25
#include " llvm/Support/Process.h"
25
26
#include " llvm/Support/Program.h"
26
27
#include " llvm/Support/Threading.h"
27
- #include " llvm/Support/Error.h"
28
28
#include < algorithm>
29
29
#include < cerrno>
30
30
#include < cstdio>
31
31
#include < sys/stat.h>
32
32
33
+ #include < iostream>
33
34
#include < sys/socket.h>
34
35
#include < sys/un.h>
35
- #include < iostream>
36
36
37
37
// <fcntl.h> may provide O_BINARY.
38
38
#if defined(HAVE_FCNTL_H)
61
61
#endif
62
62
63
63
#ifdef _WIN32
64
+ #include " raw_ostream.h"
64
65
#include " llvm/Support/ConvertUTF.h"
65
66
#include " llvm/Support/Signals.h"
66
67
#include " llvm/Support/Windows/WindowsSupport.h"
67
- #include " raw_ostream.h"
68
68
#include < afunix.h>
69
69
#include < io.h>
70
70
#endif
@@ -955,7 +955,9 @@ bool raw_fd_stream::classof(const raw_ostream *OS) {
955
955
// raw_socket_stream
956
956
// ===----------------------------------------------------------------------===//
957
957
958
- int raw_socket_stream::MakeServerSocket (StringRef SocketPath, unsigned int MaxBacklog, std::error_code &EC) {
958
+ int raw_socket_stream::MakeServerSocket (StringRef SocketPath,
959
+ unsigned int MaxBacklog,
960
+ std::error_code &EC) {
959
961
960
962
#ifdef _WIN32
961
963
SOCKET MaybeWinsocket = socket (AF_UNIX, SOCK_STREAM, 0 );
@@ -972,14 +974,14 @@ int raw_socket_stream::MakeServerSocket(StringRef SocketPath, unsigned int MaxBa
972
974
std::perror (Msg.c_str ());
973
975
std::cout << Msg << std::endl;
974
976
EC = std::make_error_code (std::errc::connection_aborted);
975
- return -1 ;
977
+ return -1 ;
976
978
}
977
979
978
980
struct sockaddr_un Addr;
979
981
memset (&Addr, 0 , sizeof (Addr));
980
982
Addr.sun_family = AF_UNIX;
981
983
strncpy (Addr.sun_path , SocketPath.str ().c_str (), sizeof (Addr.sun_path ) - 1 );
982
-
984
+
983
985
if (bind (MaybeWinsocket, (struct sockaddr *)&Addr, sizeof (Addr)) == -1 ) {
984
986
if (errno == EADDRINUSE) {
985
987
::close (MaybeWinsocket);
@@ -995,7 +997,10 @@ int raw_socket_stream::MakeServerSocket(StringRef SocketPath, unsigned int MaxBa
995
997
return -1 ;
996
998
}
997
999
#ifdef _WIN32
998
- return _open_osfhandle (MaybeWinsocket, 0 ); // flags? https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/open-osfhandle?view=msvc-170
1000
+ return _open_osfhandle (
1001
+ MaybeWinsocket,
1002
+ 0 ); // flags?
1003
+ // https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/open-osfhandle?view=msvc-170
999
1004
#else
1000
1005
return MaybeWinsocket;
1001
1006
#endif // _WIN32
@@ -1048,13 +1053,17 @@ static int ServerAccept(int FD) {
1048
1053
1049
1054
// Server
1050
1055
// Call raw_fd_ostream with ShouldClose=false
1051
- raw_socket_stream::raw_socket_stream (int SocketFD, StringRef SockPath, std::error_code &EC) : raw_fd_ostream (ServerAccept (SocketFD), true ) {
1056
+ raw_socket_stream::raw_socket_stream (int SocketFD, StringRef SockPath,
1057
+ std::error_code &EC)
1058
+ : raw_fd_ostream (ServerAccept (SocketFD), true ) {
1052
1059
SocketPath = SockPath;
1053
1060
ShouldUnlink = true ;
1054
1061
}
1055
1062
1056
1063
// Client
1057
- raw_socket_stream::raw_socket_stream (StringRef SockPath, std::error_code &EC) : raw_fd_ostream (GetSocketFD (SockPath, EC), true , true , OStreamKind::OK_OStream ) {
1064
+ raw_socket_stream::raw_socket_stream (StringRef SockPath, std::error_code &EC)
1065
+ : raw_fd_ostream (GetSocketFD (SockPath, EC), true , true ,
1066
+ OStreamKind::OK_OStream) {
1058
1067
SocketPath = SockPath;
1059
1068
ShouldUnlink = false ;
1060
1069
}
@@ -1081,12 +1090,12 @@ Expected<std::string> raw_socket_stream::read_impl() {
1081
1090
n = ::read (MaybeWinsocket, Buffer.data (), Buffer.size ());
1082
1091
1083
1092
if (n < 0 ) {
1084
- std::string Msg = " Buffer read error: " + std::string (strerror (errno));
1085
- return llvm::make_error<StringError>(Msg, inconvertibleErrorCode ());
1093
+ std::string Msg = " Buffer read error: " + std::string (strerror (errno));
1094
+ return llvm::make_error<StringError>(Msg, inconvertibleErrorCode ());
1086
1095
}
1087
1096
1088
1097
if (n == 0 ) {
1089
- return llvm::make_error<StringError>(" EOF" , inconvertibleErrorCode ());
1098
+ return llvm::make_error<StringError>(" EOF" , inconvertibleErrorCode ());
1090
1099
}
1091
1100
return std::string (Buffer.data ());
1092
1101
}
0 commit comments