Skip to content

Commit 67a0ed5

Browse files
author
Christian Riis
committed
clang-format
1 parent abe3119 commit 67a0ed5

File tree

3 files changed

+31
-24
lines changed

3 files changed

+31
-24
lines changed

llvm/include/llvm/Support/raw_ostream.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -641,13 +641,12 @@ class raw_socket_stream : public raw_fd_ostream {
641641
bool ShouldUnlink;
642642

643643
uint64_t current_pos() const override { return 0; }
644-
644+
645645
public:
646-
int get_socket() {
647-
return get_fd();
648-
}
649-
650-
static int MakeServerSocket(StringRef SocketPath, unsigned int MaxBacklog, std::error_code &EC);
646+
int get_socket() { return get_fd(); }
647+
648+
static int MakeServerSocket(StringRef SocketPath, unsigned int MaxBacklog,
649+
std::error_code &EC);
651650

652651
raw_socket_stream(int SocketFD, StringRef SockPath, std::error_code &EC);
653652
raw_socket_stream(StringRef SockPath, std::error_code &EC);

llvm/lib/Support/raw_ostream.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- raw_ostream.cpp - Implement the raw_ostream classes --------------===//
1+
//===--- raw_ostream.cpp - Implement the raw_ostream classes --------------===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
@@ -15,6 +15,7 @@
1515
#include "llvm/Config/config.h"
1616
#include "llvm/Support/Compiler.h"
1717
#include "llvm/Support/Duration.h"
18+
#include "llvm/Support/Error.h"
1819
#include "llvm/Support/ErrorHandling.h"
1920
#include "llvm/Support/FileSystem.h"
2021
#include "llvm/Support/Format.h"
@@ -24,15 +25,14 @@
2425
#include "llvm/Support/Process.h"
2526
#include "llvm/Support/Program.h"
2627
#include "llvm/Support/Threading.h"
27-
#include "llvm/Support/Error.h"
2828
#include <algorithm>
2929
#include <cerrno>
3030
#include <cstdio>
3131
#include <sys/stat.h>
3232

33+
#include <iostream>
3334
#include <sys/socket.h>
3435
#include <sys/un.h>
35-
#include <iostream>
3636

3737
// <fcntl.h> may provide O_BINARY.
3838
#if defined(HAVE_FCNTL_H)
@@ -61,10 +61,10 @@
6161
#endif
6262

6363
#ifdef _WIN32
64+
#include "raw_ostream.h"
6465
#include "llvm/Support/ConvertUTF.h"
6566
#include "llvm/Support/Signals.h"
6667
#include "llvm/Support/Windows/WindowsSupport.h"
67-
#include "raw_ostream.h"
6868
#include <afunix.h>
6969
#include <io.h>
7070
#endif
@@ -955,7 +955,9 @@ bool raw_fd_stream::classof(const raw_ostream *OS) {
955955
// raw_socket_stream
956956
//===----------------------------------------------------------------------===//
957957

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) {
959961

960962
#ifdef _WIN32
961963
SOCKET MaybeWinsocket = socket(AF_UNIX, SOCK_STREAM, 0);
@@ -972,14 +974,14 @@ int raw_socket_stream::MakeServerSocket(StringRef SocketPath, unsigned int MaxBa
972974
std::perror(Msg.c_str());
973975
std::cout << Msg << std::endl;
974976
EC = std::make_error_code(std::errc::connection_aborted);
975-
return -1;
977+
return -1;
976978
}
977979

978980
struct sockaddr_un Addr;
979981
memset(&Addr, 0, sizeof(Addr));
980982
Addr.sun_family = AF_UNIX;
981983
strncpy(Addr.sun_path, SocketPath.str().c_str(), sizeof(Addr.sun_path) - 1);
982-
984+
983985
if (bind(MaybeWinsocket, (struct sockaddr *)&Addr, sizeof(Addr)) == -1) {
984986
if (errno == EADDRINUSE) {
985987
::close(MaybeWinsocket);
@@ -995,7 +997,10 @@ int raw_socket_stream::MakeServerSocket(StringRef SocketPath, unsigned int MaxBa
995997
return -1;
996998
}
997999
#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
9991004
#else
10001005
return MaybeWinsocket;
10011006
#endif // _WIN32
@@ -1048,13 +1053,17 @@ static int ServerAccept(int FD) {
10481053

10491054
// Server
10501055
// 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) {
10521059
SocketPath = SockPath;
10531060
ShouldUnlink = true;
10541061
}
10551062

10561063
// 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) {
10581067
SocketPath = SockPath;
10591068
ShouldUnlink = false;
10601069
}
@@ -1081,12 +1090,12 @@ Expected<std::string> raw_socket_stream::read_impl() {
10811090
n = ::read(MaybeWinsocket, Buffer.data(), Buffer.size());
10821091

10831092
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());
10861095
}
10871096

10881097
if (n == 0) {
1089-
return llvm::make_error<StringError>("EOF", inconvertibleErrorCode());
1098+
return llvm::make_error<StringError>("EOF", inconvertibleErrorCode());
10901099
}
10911100
return std::string(Buffer.data());
10921101
}

llvm/unittests/Support/raw_socket_stream_test.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#include <stdlib.h>
2-
#include <iostream>
3-
#include <future>
41
#include "llvm/ADT/SmallString.h"
52
#include "llvm/Config/llvm-config.h"
63
#include "llvm/Support/Casting.h"
74
#include "llvm/Support/FileSystem.h"
85
#include "llvm/Support/FileUtilities.h"
96
#include "llvm/Support/raw_ostream.h"
107
#include "gtest/gtest.h"
8+
#include <future>
9+
#include <iostream>
10+
#include <stdlib.h>
1111

1212
using namespace llvm;
1313

@@ -45,11 +45,10 @@ TEST(raw_socket_streamTest, CLIENT_TO_SERVER_AND_SERVER_TO_CLIENT) {
4545
Server.flush();
4646

4747
Expected<std::string> from_server = Client.read_impl();
48-
if (auto E = from_server.takeError()) {
48+
if (auto E = from_server.takeError()) {
4949
return;
5050
// YIKES! 😩
5151
}
5252
EXPECT_EQ("76543210", (*from_server));
53-
5453
}
5554
} // namespace

0 commit comments

Comments
 (0)