From: JINMEI Tatuya Date: Thu, 16 Feb 2012 04:25:56 +0000 (-0800) Subject: [1593] some trivial style fixes. mostly to be aligned with the guideline. X-Git-Tag: trac2351_base~252 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b0d21f92b8fa563a1cba116a16109dc4c7164dc1;p=thirdparty%2Fkea.git [1593] some trivial style fixes. mostly to be aligned with the guideline. also constify some variables, and remove unnecessary cast. --- diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc index 639ae75979..b12f465dae 100644 --- a/src/bin/sockcreator/sockcreator.cc +++ b/src/bin/sockcreator/sockcreator.cc @@ -105,9 +105,9 @@ handle_request(const int input_fd, const int output_fd, addr_len = sizeof(addr_in); memset(&addr_in, 0, sizeof(addr_in)); addr_in.sin_family = AF_INET; - read_message(input_fd, static_cast(&addr_in.sin_port), + read_message(input_fd, &addr_in.sin_port, sizeof(addr_in.sin_port)); - read_message(input_fd, static_cast(&addr_in.sin_addr.s_addr), + read_message(input_fd, &addr_in.sin_addr.s_addr, sizeof(addr_in.sin_addr.s_addr)); break; @@ -116,9 +116,9 @@ handle_request(const int input_fd, const int output_fd, addr_len = sizeof addr_in6; memset(&addr_in6, 0, sizeof(addr_in6)); addr_in6.sin6_family = AF_INET6; - read_message(input_fd, static_cast(&addr_in6.sin6_port), + read_message(input_fd, &addr_in6.sin6_port, sizeof(addr_in6.sin6_port)); - read_message(input_fd, static_cast(&addr_in6.sin6_addr.s6_addr), + read_message(input_fd, &addr_in6.sin6_addr.s6_addr, sizeof(addr_in6.sin6_addr.s6_addr)); break; @@ -127,7 +127,7 @@ handle_request(const int input_fd, const int output_fd, } // Obtain the socket - int result = get_sock(sock_type, addr, addr_len); + const int result = get_sock(sock_type, addr, addr_len); if (result >= 0) { // Got the socket, send it to the client. write_message(output_fd, "S", 1); @@ -160,8 +160,8 @@ handle_request(const int input_fd, const int output_fd, } // ...and append the reason code to the error message - int error = errno; - write_message(output_fd, static_cast(&error), sizeof error); + const int error = errno; + write_message(output_fd, &error, sizeof(error)); } } @@ -172,24 +172,26 @@ namespace socket_creator { // Get the socket and bind to it. int -get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len) +get_sock(const int type, struct sockaddr* bind_addr, const socklen_t addr_len) { - int sock = socket(bind_addr->sa_family, type, 0); + const int sock = socket(bind_addr->sa_family, type, 0); if (sock == -1) { - return -1; + return (-1); } const int on = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) { - return -2; // This is part of the binding process, so it's a bind error + // This is part of the binding process, so it's a bind error + return (-2); } if (bind_addr->sa_family == AF_INET6 && setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &on, sizeof(on)) == -1) { - return -2; // This is part of the binding process, so it's a bind error + // This is part of the binding process, so it's a bind error + return (-2); } if (bind(sock, bind_addr, addr_len) == -1) { - return -2; + return (-2); } - return sock; + return (sock); } // Main run loop. diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc index 5bafbb8510..b351c120d2 100644 --- a/src/bin/sockcreator/tests/sockcreator_tests.cc +++ b/src/bin/sockcreator/tests/sockcreator_tests.cc @@ -12,8 +12,6 @@ // OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR // PERFORMANCE OF THIS SOFTWARE. -#include - #include "../sockcreator.h" #include @@ -25,6 +23,8 @@ #include #include #include + +#include #include #include @@ -106,7 +106,7 @@ typedef void (*socket_check_t)(const int); // IPv4 check void addressFamilySpecificCheck(const sockaddr_in*, const int) { -}; +} // IPv6 check void addressFamilySpecificCheck(const sockaddr_in6*, const int socknum) { @@ -114,7 +114,7 @@ void addressFamilySpecificCheck(const sockaddr_in6*, const int socknum) { socklen_t len = sizeof(options); EXPECT_EQ(0, getsockopt(socknum, IPPROTO_IPV6, IPV6_V6ONLY, &options, &len)); EXPECT_NE(0, options); -}; +} // Generic version of the socket test. It creates the socket and checks that @@ -133,7 +133,7 @@ void testAnyCreate(int socket_type, socket_check_t socket_check) { memset(&addr, 0, sizeof(addr)); setAddressFamilyFields(&addr); sockaddr* addr_ptr = reinterpret_cast(&addr); - int socket = get_sock(socket_type, addr_ptr, sizeof(addr)); + const int socket = get_sock(socket_type, addr_ptr, sizeof(addr)); ASSERT_GE(socket, 0) << "Couldn't create socket: failed with " << "return code " << socket << " and error " << strerror(errno); @@ -198,8 +198,7 @@ TEST(get_sock, fail_with_nonsense) { // -1: The simulated bind() call has failed // -2: The simulated socket() call has failed int -get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t) -{ +get_sock_dummy(const int type, struct sockaddr* addr, const socklen_t) { int result = 0; int port = 0; @@ -245,8 +244,7 @@ get_sock_dummy(const int type, struct sockaddr *addr, const socklen_t) // Dummy send function - return data (the result of get_sock()) to the destination. int -send_fd_dummy(const int destination, const int what) -{ +send_fd_dummy(const int destination, const int what) { // Make sure it is 1 byte so we know the length. We do not use more during // the test anyway. And even with the LS bute, we can distinguish between // the different results. @@ -275,11 +273,11 @@ void run_test(const char* input_data, const size_t input_size, // process sends data from the client to run() and the checker process // reads the response and checks it against the expected response. int input_fd = 0; - pid_t input = provide_input(&input_fd, input_data, input_size); + const pid_t input = provide_input(&input_fd, input_data, input_size); ASSERT_NE(-1, input) << "Couldn't start input feeder"; int output_fd = 0; - pid_t output = check_output(&output_fd, output_data, output_size); + const pid_t output = check_output(&output_fd, output_data, output_size); ASSERT_NE(-1, output) << "Couldn't start output checker"; // Run the body