From ecc29aa2e63c4a616ae0bbee35319777664d6823 Mon Sep 17 00:00:00 2001 From: Kirk Rodrigues <2454684+kirkrodrigues@users.noreply.github.com> Date: Mon, 13 Nov 2023 08:45:06 -0500 Subject: [PATCH] Apply clang-format to networking namespace. --- components/core/CMakeLists.txt | 1 - .../src/networking/SocketOperationFailed.cpp | 1 - .../src/networking/SocketOperationFailed.hpp | 23 +++--- .../core/src/networking/socket_utils.cpp | 70 +++++++++--------- .../core/src/networking/socket_utils.hpp | 74 +++++++++---------- 5 files changed, 79 insertions(+), 90 deletions(-) delete mode 100644 components/core/src/networking/SocketOperationFailed.cpp diff --git a/components/core/CMakeLists.txt b/components/core/CMakeLists.txt index 1cc7a43c3..00dd1207e 100644 --- a/components/core/CMakeLists.txt +++ b/components/core/CMakeLists.txt @@ -600,7 +600,6 @@ set(SOURCE_FILES_clo src/LogTypeDictionaryReader.hpp src/networking/socket_utils.cpp src/networking/socket_utils.hpp - src/networking/SocketOperationFailed.cpp src/networking/SocketOperationFailed.hpp src/PageAllocatedVector.cpp src/PageAllocatedVector.hpp diff --git a/components/core/src/networking/SocketOperationFailed.cpp b/components/core/src/networking/SocketOperationFailed.cpp deleted file mode 100644 index c899023c4..000000000 --- a/components/core/src/networking/SocketOperationFailed.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "SocketOperationFailed.hpp" diff --git a/components/core/src/networking/SocketOperationFailed.hpp b/components/core/src/networking/SocketOperationFailed.hpp index ceb0cd638..1bd2b0941 100644 --- a/components/core/src/networking/SocketOperationFailed.hpp +++ b/components/core/src/networking/SocketOperationFailed.hpp @@ -1,22 +1,19 @@ #ifndef NETWORKING_SOCKETOPERATIONFAILED_HPP #define NETWORKING_SOCKETOPERATIONFAILED_HPP -// Project headers #include "../ErrorCode.hpp" #include "../TraceableException.hpp" namespace networking { - class SocketOperationFailed : public TraceableException { - public: - // Constructors - SocketOperationFailed (ErrorCode error_code, const char* const filename, int line_number) : - TraceableException(error_code, filename, line_number) {} +class SocketOperationFailed : public TraceableException { +public: + // Constructors + SocketOperationFailed(ErrorCode error_code, char const* const filename, int line_number) + : TraceableException(error_code, filename, line_number) {} - // Methods - const char* what () const noexcept override { - return "Socket operation failed"; - } - }; -} + // Methods + [[nodiscard]] char const* what() const noexcept override { return "Socket operation failed"; } +}; +} // namespace networking -#endif //NETWORKING_SOCKETOPERATIONFAILED_HPP +#endif // NETWORKING_SOCKETOPERATIONFAILED_HPP diff --git a/components/core/src/networking/socket_utils.cpp b/components/core/src/networking/socket_utils.cpp index c965206a8..b1c06a59c 100644 --- a/components/core/src/networking/socket_utils.cpp +++ b/components/core/src/networking/socket_utils.cpp @@ -1,58 +1,54 @@ #include "socket_utils.hpp" -// C standard libraries #include -// C++ standard libraries #include -// Project headers #include "../Defs.h" #include "SocketOperationFailed.hpp" namespace networking { - ErrorCode try_send (int fd, const char* buf, size_t buf_len) { - if (fd < 0 || nullptr == buf) { - return ErrorCode_BadParam; - } - - ssize_t num_bytes_sent = ::send(fd, buf, buf_len, 0); - if (-1 == num_bytes_sent) { - return ErrorCode_errno; - } - - return ErrorCode_Success; +ErrorCode try_send(int fd, char const* buf, size_t buf_len) { + if (fd < 0 || nullptr == buf) { + return ErrorCode_BadParam; } - void send (int fd, const char* buf, size_t buf_len) { - auto error_code = try_send(fd, buf, buf_len); - if (ErrorCode_Success != error_code) { - throw SocketOperationFailed(error_code, __FILENAME__, __LINE__); - } + ssize_t num_bytes_sent = ::send(fd, buf, buf_len, 0); + if (-1 == num_bytes_sent) { + return ErrorCode_errno; } + return ErrorCode_Success; +} - ErrorCode try_receive (int fd, char* buf, size_t buf_len, size_t& num_bytes_received) { - if (fd < 0 || nullptr == buf) { - return ErrorCode_BadParam; - } +void send(int fd, char const* buf, size_t buf_len) { + auto error_code = try_send(fd, buf, buf_len); + if (ErrorCode_Success != error_code) { + throw SocketOperationFailed(error_code, __FILENAME__, __LINE__); + } +} - ssize_t result = recv(fd, buf, buf_len, 0); - if (result < 0) { - return ErrorCode_errno; - } - if (0 == result) { - return ErrorCode_EndOfFile; - } - num_bytes_received = result; +ErrorCode try_receive(int fd, char* buf, size_t buf_len, size_t& num_bytes_received) { + if (fd < 0 || nullptr == buf) { + return ErrorCode_BadParam; + } - return ErrorCode_Success; + ssize_t result = recv(fd, buf, buf_len, 0); + if (result < 0) { + return ErrorCode_errno; + } + if (0 == result) { + return ErrorCode_EndOfFile; } + num_bytes_received = result; + + return ErrorCode_Success; +} - void receive (int fd, char* buf, size_t buf_len, size_t& num_bytes_received) { - auto error_code = try_receive(fd, buf, buf_len, num_bytes_received); - if (ErrorCode_Success != error_code) { - throw SocketOperationFailed(error_code, __FILENAME__, __LINE__); - } +void receive(int fd, char* buf, size_t buf_len, size_t& num_bytes_received) { + auto error_code = try_receive(fd, buf, buf_len, num_bytes_received); + if (ErrorCode_Success != error_code) { + throw SocketOperationFailed(error_code, __FILENAME__, __LINE__); } } +} // namespace networking diff --git a/components/core/src/networking/socket_utils.hpp b/components/core/src/networking/socket_utils.hpp index 95a24a59f..90e16403d 100644 --- a/components/core/src/networking/socket_utils.hpp +++ b/components/core/src/networking/socket_utils.hpp @@ -1,48 +1,46 @@ #ifndef NETWORKING_SOCKET_UTILS_HPP #define NETWORKING_SOCKET_UTILS_HPP -// C++ standard libraries #include -// Project headers #include "../ErrorCode.hpp" namespace networking { - // Methods - /** - * Tries to send a buffer of data over the socket - * @param fd - * @param buf - * @param buf_len - * @return ErrorCode_BadParam if the file descriptor or buffer pointer is invalid - * @return ErrorCode_errno if sending failed - * @return ErrorCode_Success otherwise - */ - ErrorCode try_send (int fd, const char* buf, size_t buf_len); - /** - * Sends a buffer of data over the socket - * @param fd - * @param buf - * @param buf_len - */ - void send (int fd, const char* buf, size_t buf_len); +// Methods +/** + * Tries to send a buffer of data over the socket + * @param fd + * @param buf + * @param buf_len + * @return ErrorCode_BadParam if the file descriptor or buffer pointer is invalid + * @return ErrorCode_errno if sending failed + * @return ErrorCode_Success otherwise + */ +ErrorCode try_send(int fd, char const* buf, size_t buf_len); +/** + * Sends a buffer of data over the socket + * @param fd + * @param buf + * @param buf_len + */ +void send(int fd, char const* buf, size_t buf_len); - /** - * Tries to receive up to a given number of bytes over a socket - * @param buf Buffer to store received bytes - * @param buf_len Number of bytes to receive - * @return ErrorCode_BadParam if file descriptor or buffer pointer are invalid - * @return ErrorCode_EndOfFile on EOF - * @return ErrorCode_errno if receiving failed - * @return ErrorCode_Success otherwise - */ - ErrorCode try_receive (int fd, char* buf, size_t buf_len, size_t& num_bytes_received); - /** - * Receives up to the give number of bytes over a socket - * @param buf Buffer to store received bytes - * @param buf_len Number of bytes to receive - */ - void receive (int fd, char* buf, size_t buf_len, size_t& num_bytes_received); -} +/** + * Tries to receive up to a given number of bytes over a socket + * @param buf Buffer to store received bytes + * @param buf_len Number of bytes to receive + * @return ErrorCode_BadParam if file descriptor or buffer pointer are invalid + * @return ErrorCode_EndOfFile on EOF + * @return ErrorCode_errno if receiving failed + * @return ErrorCode_Success otherwise + */ +ErrorCode try_receive(int fd, char* buf, size_t buf_len, size_t& num_bytes_received); +/** + * Receives up to the give number of bytes over a socket + * @param buf Buffer to store received bytes + * @param buf_len Number of bytes to receive + */ +void receive(int fd, char* buf, size_t buf_len, size_t& num_bytes_received); +} // namespace networking -#endif //NETWORKING_SOCKET_UTILS_HPP +#endif // NETWORKING_SOCKET_UTILS_HPP