diff options
author | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
---|---|---|
committer | Kate Stone <katherine.stone@apple.com> | 2016-09-06 20:57:50 +0000 |
commit | b9c1b51e45b845debb76d8658edabca70ca56079 (patch) | |
tree | dfcb5a13ef2b014202340f47036da383eaee74aa /lldb/source/Host/common/UDPSocket.cpp | |
parent | d5aa73376966339caad04013510626ec2e42c760 (diff) | |
download | llvm-b9c1b51e45b845debb76d8658edabca70ca56079.zip llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.gz llvm-b9c1b51e45b845debb76d8658edabca70ca56079.tar.bz2 |
*** 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
Diffstat (limited to 'lldb/source/Host/common/UDPSocket.cpp')
-rw-r--r-- | lldb/source/Host/common/UDPSocket.cpp | 193 |
1 files changed, 84 insertions, 109 deletions
diff --git a/lldb/source/Host/common/UDPSocket.cpp b/lldb/source/Host/common/UDPSocket.cpp index 9a2028e..7cb1b37 100644 --- a/lldb/source/Host/common/UDPSocket.cpp +++ b/lldb/source/Host/common/UDPSocket.cpp @@ -25,134 +25,109 @@ using namespace lldb_private; namespace { const int kDomain = AF_INET; -const int kType = SOCK_DGRAM; +const int kType = SOCK_DGRAM; static const char *g_not_supported_error = "Not supported"; - } -UDPSocket::UDPSocket(NativeSocket socket) - : Socket(socket, ProtocolUdp, true) -{ -} +UDPSocket::UDPSocket(NativeSocket socket) : Socket(socket, ProtocolUdp, true) {} UDPSocket::UDPSocket(bool child_processes_inherit, Error &error) - : UDPSocket(CreateSocket(kDomain, kType, 0, child_processes_inherit, error)) -{ -} + : UDPSocket( + CreateSocket(kDomain, kType, 0, child_processes_inherit, error)) {} -size_t -UDPSocket::Send(const void *buf, const size_t num_bytes) -{ - return ::sendto (m_socket, - static_cast<const char*>(buf), - num_bytes, - 0, - m_send_sockaddr, - m_send_sockaddr.GetLength()); +size_t UDPSocket::Send(const void *buf, const size_t num_bytes) { + return ::sendto(m_socket, static_cast<const char *>(buf), num_bytes, 0, + m_send_sockaddr, m_send_sockaddr.GetLength()); } -Error -UDPSocket::Connect(llvm::StringRef name) -{ - return Error("%s", g_not_supported_error); +Error UDPSocket::Connect(llvm::StringRef name) { + return Error("%s", g_not_supported_error); } -Error -UDPSocket::Listen(llvm::StringRef name, int backlog) -{ - return Error("%s", g_not_supported_error); +Error UDPSocket::Listen(llvm::StringRef name, int backlog) { + return Error("%s", g_not_supported_error); } -Error -UDPSocket::Accept(llvm::StringRef name, bool child_processes_inherit, Socket *&socket) -{ - return Error("%s", g_not_supported_error); +Error UDPSocket::Accept(llvm::StringRef name, bool child_processes_inherit, + Socket *&socket) { + return Error("%s", g_not_supported_error); } -Error -UDPSocket::Connect(llvm::StringRef name, bool child_processes_inherit, Socket *&send_socket, Socket *&recv_socket) -{ - std::unique_ptr<UDPSocket> final_send_socket; - std::unique_ptr<UDPSocket> final_recv_socket; - - Log *log(lldb_private::GetLogIfAnyCategoriesSet (LIBLLDB_LOG_CONNECTION)); - if (log) - log->Printf ("UDPSocket::%s (host/port = %s)", __FUNCTION__, name.data()); - - Error error; - std::string host_str; - std::string port_str; - int32_t port = INT32_MIN; - if (!DecodeHostAndPort (name, host_str, port_str, port, &error)) - return error; - - // Setup the receiving end of the UDP connection on this localhost - // on port zero. After we bind to port zero we can read the port. - final_recv_socket.reset(new UDPSocket(child_processes_inherit, error)); - if (error.Success()) - { - // Socket was created, now lets bind to the requested port - SocketAddress addr; - addr.SetToAnyAddress (AF_INET, 0); - - if (::bind (final_recv_socket->GetNativeSocket(), addr, addr.GetLength()) == -1) - { - // Bind failed... - SetLastError (error); - } - } +Error UDPSocket::Connect(llvm::StringRef name, bool child_processes_inherit, + Socket *&send_socket, Socket *&recv_socket) { + std::unique_ptr<UDPSocket> final_send_socket; + std::unique_ptr<UDPSocket> final_recv_socket; - assert(error.Fail() == !(final_recv_socket && final_recv_socket->IsValid())); - if (error.Fail()) - return error; - - // At this point we have setup the receive port, now we need to - // setup the UDP send socket - - struct addrinfo hints; - struct addrinfo *service_info_list = nullptr; - - ::memset (&hints, 0, sizeof(hints)); - hints.ai_family = kDomain; - hints.ai_socktype = kType; - int err = ::getaddrinfo (host_str.c_str(), port_str.c_str(), &hints, &service_info_list); - if (err != 0) - { - error.SetErrorStringWithFormat("getaddrinfo(%s, %s, &hints, &info) returned error %i (%s)", - host_str.c_str(), - port_str.c_str(), - err, - gai_strerror(err)); - return error; - } + Log *log(lldb_private::GetLogIfAnyCategoriesSet(LIBLLDB_LOG_CONNECTION)); + if (log) + log->Printf("UDPSocket::%s (host/port = %s)", __FUNCTION__, name.data()); - for (struct addrinfo *service_info_ptr = service_info_list; - service_info_ptr != nullptr; - service_info_ptr = service_info_ptr->ai_next) - { - auto send_fd = CreateSocket (service_info_ptr->ai_family, - service_info_ptr->ai_socktype, - service_info_ptr->ai_protocol, - child_processes_inherit, - error); - if (error.Success()) - { - final_send_socket.reset(new UDPSocket(send_fd)); - final_send_socket->m_send_sockaddr = service_info_ptr; - break; - } - else - continue; - } + Error error; + std::string host_str; + std::string port_str; + int32_t port = INT32_MIN; + if (!DecodeHostAndPort(name, host_str, port_str, port, &error)) + return error; - :: freeaddrinfo (service_info_list); + // Setup the receiving end of the UDP connection on this localhost + // on port zero. After we bind to port zero we can read the port. + final_recv_socket.reset(new UDPSocket(child_processes_inherit, error)); + if (error.Success()) { + // Socket was created, now lets bind to the requested port + SocketAddress addr; + addr.SetToAnyAddress(AF_INET, 0); + + if (::bind(final_recv_socket->GetNativeSocket(), addr, addr.GetLength()) == + -1) { + // Bind failed... + SetLastError(error); + } + } - if (!final_send_socket) - return error; + assert(error.Fail() == !(final_recv_socket && final_recv_socket->IsValid())); + if (error.Fail()) + return error; - send_socket = final_send_socket.release(); - recv_socket = final_recv_socket.release(); - error.Clear(); + // At this point we have setup the receive port, now we need to + // setup the UDP send socket + + struct addrinfo hints; + struct addrinfo *service_info_list = nullptr; + + ::memset(&hints, 0, sizeof(hints)); + hints.ai_family = kDomain; + hints.ai_socktype = kType; + int err = ::getaddrinfo(host_str.c_str(), port_str.c_str(), &hints, + &service_info_list); + if (err != 0) { + error.SetErrorStringWithFormat( + "getaddrinfo(%s, %s, &hints, &info) returned error %i (%s)", + host_str.c_str(), port_str.c_str(), err, gai_strerror(err)); return error; + } + + for (struct addrinfo *service_info_ptr = service_info_list; + service_info_ptr != nullptr; + service_info_ptr = service_info_ptr->ai_next) { + auto send_fd = CreateSocket( + service_info_ptr->ai_family, service_info_ptr->ai_socktype, + service_info_ptr->ai_protocol, child_processes_inherit, error); + if (error.Success()) { + final_send_socket.reset(new UDPSocket(send_fd)); + final_send_socket->m_send_sockaddr = service_info_ptr; + break; + } else + continue; + } + + ::freeaddrinfo(service_info_list); + + if (!final_send_socket) + return error; + + send_socket = final_send_socket.release(); + recv_socket = final_recv_socket.release(); + error.Clear(); + return error; } |