*** This commit represents a complete reformatting of the LLDB source code
*** to conform to clang-format’s LLVM style. This kind of mass change has
*** two obvious implications:
Firstly, merging this particular commit into a downstream fork may be a huge
effort. Alternatively, it may be worth merging all changes up to this commit,
performing the same reformatting operation locally, and then discarding the
merge for this particular commit. The commands used to accomplish this
reformatting were as follows (with current working directory as the root of
the repository):
find . \( -iname "*.c" -or -iname "*.cpp" -or -iname "*.h" -or -iname "*.mm" \) -exec clang-format -i {} +
find . -iname "*.py" -exec autopep8 --in-place --aggressive --aggressive {} + ;
The version of clang-format used was 3.9.0, and autopep8 was 1.2.4.
Secondly, “blame” style tools will generally point to this commit instead of
a meaningful prior commit. There are alternatives available that will attempt
to look through this change and find the appropriate prior commit. YMMV.
llvm-svn: 280751
This commit is contained in:
@@ -25,10 +25,9 @@ using namespace llvm;
|
||||
|
||||
namespace {
|
||||
|
||||
struct SocketScheme
|
||||
{
|
||||
const char* m_scheme;
|
||||
const Socket::SocketProtocol m_protocol;
|
||||
struct SocketScheme {
|
||||
const char *m_scheme;
|
||||
const Socket::SocketProtocol m_protocol;
|
||||
};
|
||||
|
||||
SocketScheme socket_schemes[] = {
|
||||
@@ -38,134 +37,102 @@ SocketScheme socket_schemes[] = {
|
||||
{"unix-abstract", Socket::ProtocolUnixAbstract},
|
||||
};
|
||||
|
||||
bool
|
||||
FindProtocolByScheme(const char* scheme, Socket::SocketProtocol& protocol)
|
||||
{
|
||||
for (auto s: socket_schemes)
|
||||
{
|
||||
if (!strcmp(s.m_scheme, scheme))
|
||||
{
|
||||
protocol = s.m_protocol;
|
||||
return true;
|
||||
}
|
||||
bool FindProtocolByScheme(const char *scheme,
|
||||
Socket::SocketProtocol &protocol) {
|
||||
for (auto s : socket_schemes) {
|
||||
if (!strcmp(s.m_scheme, scheme)) {
|
||||
protocol = s.m_protocol;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
const char*
|
||||
FindSchemeByProtocol(const Socket::SocketProtocol protocol)
|
||||
{
|
||||
for (auto s: socket_schemes)
|
||||
{
|
||||
if (s.m_protocol == protocol)
|
||||
return s.m_scheme;
|
||||
}
|
||||
return nullptr;
|
||||
const char *FindSchemeByProtocol(const Socket::SocketProtocol protocol) {
|
||||
for (auto s : socket_schemes) {
|
||||
if (s.m_protocol == protocol)
|
||||
return s.m_scheme;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
Error Acceptor::Listen(int backlog) {
|
||||
return m_listener_socket_up->Listen(StringRef(m_name.c_str()), backlog);
|
||||
}
|
||||
|
||||
Error
|
||||
Acceptor::Listen(int backlog)
|
||||
{
|
||||
return m_listener_socket_up->Listen(StringRef(m_name.c_str()),
|
||||
backlog);
|
||||
Error Acceptor::Accept(const bool child_processes_inherit, Connection *&conn) {
|
||||
Socket *conn_socket = nullptr;
|
||||
auto error = m_listener_socket_up->Accept(
|
||||
StringRef(m_name.c_str()), child_processes_inherit, conn_socket);
|
||||
if (error.Success())
|
||||
conn = new ConnectionFileDescriptor(conn_socket);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
Error
|
||||
Acceptor::Accept(const bool child_processes_inherit, Connection *&conn)
|
||||
{
|
||||
Socket* conn_socket = nullptr;
|
||||
auto error = m_listener_socket_up->Accept(StringRef(m_name.c_str()),
|
||||
child_processes_inherit,
|
||||
conn_socket);
|
||||
if (error.Success())
|
||||
conn = new ConnectionFileDescriptor(conn_socket);
|
||||
|
||||
return error;
|
||||
Socket::SocketProtocol Acceptor::GetSocketProtocol() const {
|
||||
return m_listener_socket_up->GetSocketProtocol();
|
||||
}
|
||||
|
||||
Socket::SocketProtocol
|
||||
Acceptor::GetSocketProtocol() const
|
||||
{
|
||||
return m_listener_socket_up->GetSocketProtocol();
|
||||
const char *Acceptor::GetSocketScheme() const {
|
||||
return FindSchemeByProtocol(GetSocketProtocol());
|
||||
}
|
||||
|
||||
const char*
|
||||
Acceptor::GetSocketScheme() const
|
||||
{
|
||||
return FindSchemeByProtocol(GetSocketProtocol());
|
||||
}
|
||||
std::string Acceptor::GetLocalSocketId() const { return m_local_socket_id(); }
|
||||
|
||||
std::string
|
||||
Acceptor::GetLocalSocketId() const
|
||||
{
|
||||
return m_local_socket_id();
|
||||
}
|
||||
std::unique_ptr<Acceptor> Acceptor::Create(StringRef name,
|
||||
const bool child_processes_inherit,
|
||||
Error &error) {
|
||||
error.Clear();
|
||||
|
||||
std::unique_ptr<Acceptor>
|
||||
Acceptor::Create(StringRef name, const bool child_processes_inherit, Error &error)
|
||||
{
|
||||
error.Clear();
|
||||
|
||||
Socket::SocketProtocol socket_protocol = Socket::ProtocolUnixDomain;
|
||||
int port;
|
||||
std::string scheme, host, path;
|
||||
// Try to match socket name as URL - e.g., tcp://localhost:5555
|
||||
if (UriParser::Parse(name.str(), scheme, host, port, path))
|
||||
{
|
||||
if (!FindProtocolByScheme(scheme.c_str(), socket_protocol))
|
||||
error.SetErrorStringWithFormat("Unknown protocol scheme \"%s\"", scheme.c_str());
|
||||
else
|
||||
name = name.drop_front(scheme.size() + strlen("://"));
|
||||
}
|
||||
Socket::SocketProtocol socket_protocol = Socket::ProtocolUnixDomain;
|
||||
int port;
|
||||
std::string scheme, host, path;
|
||||
// Try to match socket name as URL - e.g., tcp://localhost:5555
|
||||
if (UriParser::Parse(name.str(), scheme, host, port, path)) {
|
||||
if (!FindProtocolByScheme(scheme.c_str(), socket_protocol))
|
||||
error.SetErrorStringWithFormat("Unknown protocol scheme \"%s\"",
|
||||
scheme.c_str());
|
||||
else
|
||||
{
|
||||
std::string host_str;
|
||||
std::string port_str;
|
||||
int32_t port = INT32_MIN;
|
||||
// Try to match socket name as $host:port - e.g., localhost:5555
|
||||
if (Socket::DecodeHostAndPort (name, host_str, port_str, port, nullptr))
|
||||
socket_protocol = Socket::ProtocolTcp;
|
||||
}
|
||||
|
||||
if (error.Fail())
|
||||
return std::unique_ptr<Acceptor>();
|
||||
|
||||
std::unique_ptr<Socket> listener_socket_up = Socket::Create(
|
||||
socket_protocol, child_processes_inherit, error);
|
||||
|
||||
LocalSocketIdFunc local_socket_id;
|
||||
if (error.Success())
|
||||
{
|
||||
if (listener_socket_up->GetSocketProtocol() == Socket::ProtocolTcp)
|
||||
{
|
||||
TCPSocket* tcp_socket = static_cast<TCPSocket*>(listener_socket_up.get());
|
||||
local_socket_id = [tcp_socket]() {
|
||||
auto local_port = tcp_socket->GetLocalPortNumber();
|
||||
return (local_port != 0) ? llvm::to_string(local_port) : "";
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::string socket_name = name;
|
||||
local_socket_id = [socket_name](){
|
||||
return socket_name;
|
||||
};
|
||||
}
|
||||
|
||||
return std::unique_ptr<Acceptor>(
|
||||
new Acceptor(std::move(listener_socket_up), name, local_socket_id));
|
||||
}
|
||||
name = name.drop_front(scheme.size() + strlen("://"));
|
||||
} else {
|
||||
std::string host_str;
|
||||
std::string port_str;
|
||||
int32_t port = INT32_MIN;
|
||||
// Try to match socket name as $host:port - e.g., localhost:5555
|
||||
if (Socket::DecodeHostAndPort(name, host_str, port_str, port, nullptr))
|
||||
socket_protocol = Socket::ProtocolTcp;
|
||||
}
|
||||
|
||||
if (error.Fail())
|
||||
return std::unique_ptr<Acceptor>();
|
||||
|
||||
std::unique_ptr<Socket> listener_socket_up =
|
||||
Socket::Create(socket_protocol, child_processes_inherit, error);
|
||||
|
||||
LocalSocketIdFunc local_socket_id;
|
||||
if (error.Success()) {
|
||||
if (listener_socket_up->GetSocketProtocol() == Socket::ProtocolTcp) {
|
||||
TCPSocket *tcp_socket =
|
||||
static_cast<TCPSocket *>(listener_socket_up.get());
|
||||
local_socket_id = [tcp_socket]() {
|
||||
auto local_port = tcp_socket->GetLocalPortNumber();
|
||||
return (local_port != 0) ? llvm::to_string(local_port) : "";
|
||||
};
|
||||
} else {
|
||||
const std::string socket_name = name;
|
||||
local_socket_id = [socket_name]() { return socket_name; };
|
||||
}
|
||||
|
||||
return std::unique_ptr<Acceptor>(
|
||||
new Acceptor(std::move(listener_socket_up), name, local_socket_id));
|
||||
}
|
||||
|
||||
return std::unique_ptr<Acceptor>();
|
||||
}
|
||||
|
||||
Acceptor::Acceptor(std::unique_ptr<Socket> &&listener_socket,
|
||||
StringRef name,
|
||||
Acceptor::Acceptor(std::unique_ptr<Socket> &&listener_socket, StringRef name,
|
||||
const LocalSocketIdFunc &local_socket_id)
|
||||
: m_listener_socket_up(std::move(listener_socket)),
|
||||
m_name(name.str()),
|
||||
m_local_socket_id(local_socket_id)
|
||||
{
|
||||
}
|
||||
: m_listener_socket_up(std::move(listener_socket)), m_name(name.str()),
|
||||
m_local_socket_id(local_socket_id) {}
|
||||
|
||||
Reference in New Issue
Block a user