From caed92f525de546a897a9ef0d6921b4f04497c8d Mon Sep 17 00:00:00 2001 From: Pierre Kancir Date: Thu, 8 Aug 2024 10:05:45 +0200 Subject: [PATCH] SocketUDP: reformat to pass cpplint check --- include/SocketUDP.hh | 28 +++++++++++++++++----------- src/SocketUDP.cc | 17 +++++++++++------ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/include/SocketUDP.hh b/include/SocketUDP.hh index 7024313a..bd23a9b9 100644 --- a/include/SocketUDP.hh +++ b/include/SocketUDP.hh @@ -20,16 +20,19 @@ #include #include + #ifdef _WIN32 - #include - #include +#include +#include #else - #include - #include - #include - #include - #include - #include + +#include +#include +#include +#include +#include +#include + #endif /// \brief Simple UDP socket handling class. @@ -51,7 +54,8 @@ public: bool set_blocking(bool blocking); /// \brief Send data to address and port. - ssize_t sendto(const void *buf, size_t size, const char *address, uint16_t port); + ssize_t + sendto(const void *buf, size_t size, const char *address, uint16_t port); /// \brief Receive data. ssize_t recv(void *pkt, size_t size, uint32_t timeout_ms); @@ -61,7 +65,7 @@ public: private: /// \brief File descriptor. - struct sockaddr_in in_addr {}; + struct sockaddr_in in_addr{}; /// \brief File descriptor. int fd = -1; @@ -70,6 +74,8 @@ private: bool pollin(uint32_t timeout_ms); /// \brief Make a sockaddr_in struct from address and port. - void make_sockaddr(const char *address, uint16_t port, struct sockaddr_in &sockaddr); + void make_sockaddr(const char *address, uint16_t port, + struct sockaddr_in &sockaddr); }; + #endif // SOCKETUDP_HH_ diff --git a/src/SocketUDP.cc b/src/SocketUDP.cc index f9aaa274..5618c109 100644 --- a/src/SocketUDP.cc +++ b/src/SocketUDP.cc @@ -55,7 +55,8 @@ bool SocketUDP::bind(const char *address, uint16_t port) { struct sockaddr_in server_addr{}; make_sockaddr(address, port, server_addr); - if (::bind(fd, reinterpret_cast(&server_addr), sizeof(server_addr)) != 0) { + if (::bind(fd, reinterpret_cast(&server_addr), + sizeof(server_addr)) != 0) { perror("SocketUDP Bind failed"); #ifdef _WIN32 closesocket(fd); @@ -90,11 +91,14 @@ bool SocketUDP::set_blocking(bool blocking) { } -ssize_t SocketUDP::sendto(const void *buf, size_t size, const char *address, uint16_t port) { +ssize_t SocketUDP::sendto(const void *buf, size_t size, const char *address, + uint16_t port) { struct sockaddr_in sockaddr_out{}; make_sockaddr(address, port, sockaddr_out); - return ::sendto(fd, buf, size, 0, reinterpret_cast(&sockaddr_out), sizeof(sockaddr_out)); + return ::sendto(fd, buf, size, 0, + reinterpret_cast(&sockaddr_out), + sizeof(sockaddr_out)); } /* @@ -105,7 +109,8 @@ ssize_t SocketUDP::recv(void *buf, size_t size, uint32_t timeout_ms) { return -1; } socklen_t len = sizeof(in_addr); - return ::recvfrom(fd, buf, size, MSG_DONTWAIT, reinterpret_cast(&in_addr), &len); + return ::recvfrom(fd, buf, size, MSG_DONTWAIT, + reinterpret_cast(&in_addr), &len); } @@ -131,8 +136,8 @@ bool SocketUDP::pollin(uint32_t timeout_ms) { return true; } -void SocketUDP::make_sockaddr(const char *address, uint16_t port, struct sockaddr_in &sockaddr) -{ +void SocketUDP::make_sockaddr(const char *address, uint16_t port, + struct sockaddr_in &sockaddr) { sockaddr = {}; sockaddr.sin_family = AF_INET;