Browse Source

[1593] suggested style cleanup: use the camel style for function names per guide

JINMEI Tatuya 13 years ago
parent
commit
d3781127f6

+ 27 - 29
src/bin/sockcreator/sockcreator.cc

@@ -31,14 +31,14 @@ namespace {
 
 // Simple wrappers for read_data/write_data that throw an exception on error.
 void
-read_message(const int fd, void* where, const size_t length) {
+readMessage(const int fd, void* where, const size_t length) {
     if (read_data(fd, where, length) < length) {
         isc_throw(ReadError, "Error reading from socket creator client");
     }
 }
 
 void
-write_message(const int fd, const void* what, const size_t length) {
+writeMessage(const int fd, const void* what, const size_t length) {
     if (!write_data(fd, what, length)) {
         isc_throw(WriteError, "Error writing to socket creator client");
     }
@@ -46,13 +46,13 @@ write_message(const int fd, const void* what, const size_t length) {
 
 // Exit on a protocol error after informing the client of the problem.
 void
-protocol_error(const int fd, const char reason = 'I') {
+protocolError(const int fd, const char reason = 'I') {
 
     // Tell client we have a problem
     char message[2];
     message[0] = 'F';
     message[1] = reason;
-    write_message(fd, message, sizeof(message));
+    writeMessage(fd, message, sizeof(message));
 
     // ... and exit
     isc_throw(ProtocolError, "Fatal error, reason: " << reason);
@@ -66,13 +66,13 @@ protocol_error(const int fd, const char reason = 'I') {
 // The arguments passed (and the exceptions thrown) are the same as those for
 // run().
 void
-handle_request(const int input_fd, const int output_fd,
-               const get_sock_t get_sock, const send_fd_t send_fd_fun,
-               const close_t close_fun)
+handleRequest(const int input_fd, const int output_fd,
+              const get_sock_t get_sock, const send_fd_t send_fd_fun,
+              const close_t close_fun)
 {
     // Read the message from the client
     char type[2];
-    read_message(input_fd, type, sizeof(type));
+    readMessage(input_fd, type, sizeof(type));
 
     // Decide what type of socket is being asked for
     int sock_type = 0;
@@ -86,7 +86,7 @@ handle_request(const int input_fd, const int output_fd,
             break;
 
         default:
-            protocol_error(output_fd);
+            protocolError(output_fd);
     }
 
     // Read the address they ask for depending on what address family was
@@ -105,10 +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, &addr_in.sin_port,
-                         sizeof(addr_in.sin_port));
-            read_message(input_fd, &addr_in.sin_addr.s_addr,
-                         sizeof(addr_in.sin_addr.s_addr));
+            readMessage(input_fd, &addr_in.sin_port, sizeof(addr_in.sin_port));
+            readMessage(input_fd, &addr_in.sin_addr.s_addr,
+                        sizeof(addr_in.sin_addr.s_addr));
             break;
 
         case '6':
@@ -116,21 +115,21 @@ 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, &addr_in6.sin6_port,
-                         sizeof(addr_in6.sin6_port));
-            read_message(input_fd, &addr_in6.sin6_addr.s6_addr,
-                         sizeof(addr_in6.sin6_addr.s6_addr));
+            readMessage(input_fd, &addr_in6.sin6_port,
+                        sizeof(addr_in6.sin6_port));
+            readMessage(input_fd, &addr_in6.sin6_addr.s6_addr,
+                        sizeof(addr_in6.sin6_addr.s6_addr));
             break;
 
         default:
-            protocol_error(output_fd);
+            protocolError(output_fd);
     }
 
     // Obtain the socket
     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);
+        writeMessage(output_fd, "S", 1);
         if (send_fd_fun(output_fd, result) != 0) {
             // Error.  Close the socket (ignore any error from that operation)
             // and abort.
@@ -145,14 +144,14 @@ handle_request(const int input_fd, const int output_fd,
         }
     } else {
         // Error.  Tell the client.
-        write_message(output_fd, "E", 1);           // Error occurred...
+        writeMessage(output_fd, "E", 1);           // Error occurred...
         switch (result) {
             case -1:
-                write_message(output_fd, "S", 1);   // ... in the socket() call
+                writeMessage(output_fd, "S", 1);   // ... in the socket() call
                 break;
 
             case -2:
-                write_message(output_fd, "B", 1);   // ... in the bind() call
+                writeMessage(output_fd, "B", 1);   // ... in the bind() call
                 break;
 
             default:
@@ -161,7 +160,7 @@ handle_request(const int input_fd, const int output_fd,
 
         // ...and append the reason code to the error message
         const int error = errno;
-        write_message(output_fd, &error, sizeof(error));
+        writeMessage(output_fd, &error, sizeof(error));
     }
 }
 
@@ -172,8 +171,7 @@ 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)
-{
+getSock(const int type, struct sockaddr* bind_addr, const socklen_t addr_len) {
     const int sock = socket(bind_addr->sa_family, type, 0);
     if (sock == -1) {
         return (-1);
@@ -201,18 +199,18 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock,
 {
     for (;;) {
         char command;
-        read_message(input_fd, &command, sizeof(command));
+        readMessage(input_fd, &command, sizeof(command));
         switch (command) {
             case 'S':   // The "get socket" command
-                handle_request(input_fd, output_fd, get_sock,
-                               send_fd_fun, close_fun);
+                handleRequest(input_fd, output_fd, get_sock,
+                              send_fd_fun, close_fun);
                 break;
 
             case 'T':   // The "terminate" command
                 return;
 
             default:    // Don't recognise anything else
-                protocol_error(output_fd);
+                protocolError(output_fd);
         }
     }
 }

+ 4 - 4
src/bin/sockcreator/sockcreator.h

@@ -88,14 +88,14 @@ public:
 ///         -1 if the socket() call fails or -2 if bind() fails. In case of
 ///         error, errno is set (or left intact from socket() or bind()).
 int
-get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len);
+getSock(const int type, struct sockaddr* bind_addr, const socklen_t addr_len);
 
 // Define some types for functions used to perform socket-related operations.
 // These are typedefed so that alternatives can be passed through to the
 // main functions for testing purposes.
 
-// Type of the get_sock function, to pass it as parameter.  Arguments are
-// those described above for get_sock().
+// Type of the function to get a socket and to pass it as parameter.
+// Arguments are those described above for getSock().
 typedef int (*get_sock_t)(const int, struct sockaddr *, const socklen_t);
 
 // Type of the send_fd() function, so it can be passed as a parameter.
@@ -135,7 +135,7 @@ typedef int (*close_t)(int);
 /// \exception isc::socket_creator::InternalError Other error
 void
 run(const int input_fd, const int output_fd,
-    const get_sock_t get_sock_fun = get_sock,
+    const get_sock_t get_sock_fun = getSock,
     const send_fd_t send_fd_fun = isc::util::io::send_fd,
     const close_t close_fun = close);
 

+ 24 - 24
src/bin/sockcreator/tests/sockcreator_tests.cc

@@ -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<sockaddr*>(&addr);
-    const int socket = get_sock(socket_type, addr_ptr, sizeof(addr));
+    const int socket = getSock(socket_type, addr_ptr, sizeof(addr));
     ASSERT_GE(socket, 0) << "Couldn't create socket: failed with " <<
         "return code " << socket << " and error " << strerror(errno);
 
@@ -176,14 +176,14 @@ TEST(get_sock, tcp6_create) {
 TEST(get_sock, fail_with_nonsense) {
     sockaddr addr;
     memset(&addr, 0, sizeof(addr));
-    ASSERT_LT(get_sock(0, &addr, sizeof addr), 0);
+    ASSERT_LT(getSock(0, &addr, sizeof addr), 0);
 }
 
 // The main run() function in the socket creator takes three functions to
 // get the socket, send information to it, and close it.  These allow for
 // alternatives to the system functions to be used for testing.
 
-// Replacement get_sock() function.
+// Replacement getSock() function.
 // The return value indicates the result of checks and is encoded.  Using LSB
 // bit numbering (least-significant bit is bit 0) then:
 //
@@ -198,7 +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) {
+getSockDummy(const int type, struct sockaddr* addr, const socklen_t) {
     int result = 0;
     int port = 0;
 
@@ -242,9 +242,9 @@ get_sock_dummy(const int type, struct sockaddr* addr, const socklen_t) {
     return (result);
 }
 
-// Dummy send function - return data (the result of get_sock()) to the destination.
+// Dummy send function - return data (the result of getSock()) to the destination.
 int
-send_fd_dummy(const int destination, const int what) {
+send_FdDummy(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.
@@ -263,11 +263,11 @@ closeIgnore(int) {
 // It uses different functions to create the socket and send it and pass
 // data to it and check it returns correct data back, to see if the run()
 // parses the commands correctly.
-void run_test(const char* input_data, const size_t input_size,
-              const char* output_data, const size_t output_size,
-              bool should_succeed = true,
-              const close_t test_close = closeIgnore,
-              const send_fd_t send_fd = send_fd_dummy)
+void runTest(const char* input_data, const size_t input_size,
+             const char* output_data, const size_t output_size,
+             bool should_succeed = true,
+             const close_t test_close = closeIgnore,
+             const send_fd_t send_fd = send_FdDummy)
 {
     // Prepare the input feeder and output checker processes.  The feeder
     // process sends data from the client to run() and the checker process
@@ -282,10 +282,10 @@ void run_test(const char* input_data, const size_t input_size,
 
     // Run the body
     if (should_succeed) {
-        EXPECT_NO_THROW(run(input_fd, output_fd, get_sock_dummy, send_fd,
+        EXPECT_NO_THROW(run(input_fd, output_fd, getSockDummy, send_fd,
                             test_close));
     } else {
-        EXPECT_THROW(run(input_fd, output_fd, get_sock_dummy, send_fd,
+        EXPECT_THROW(run(input_fd, output_fd, getSockDummy, send_fd,
                          test_close), isc::socket_creator::SocketCreatorError);
     }
 
@@ -301,17 +301,17 @@ void run_test(const char* input_data, const size_t input_size,
 
 // Check it terminates successfully when asked to.
 TEST(run, terminate) {
-    run_test("T", 1, NULL, 0);
+    runTest("T", 1, NULL, 0);
 }
 
 // Check it rejects incorrect input.
 TEST(run, bad_input) {
-    run_test("XXX", 3, "FI", 2, false);
+    runTest("XXX", 3, "FI", 2, false);
 }
 
 // Check it correctly parses query stream to create sockets.
 TEST(run, sockets) {
-    run_test(
+    runTest(
         // Commands:
         "SU4\xff\xff\0\0\0\0"   // IPv4 UDP socket, port 0xffffff, address 0.0.0.0
         "ST4\xff\xff\0\0\0\0"   // IPv4 TCP socket, port 0xffffff, address 0.0.0.0
@@ -321,7 +321,7 @@ TEST(run, sockets) {
                                 // IPv6 TCP socket, port 0xffffff, address ::
         "T",                    // ... and terminate
         9 + 9 + 21 + 21 + 1,    // Length of command string
-        "S\x07S\x05S\x0dS\x0f", // Response ("S" + LS byte of get_sock() return)
+        "S\x07S\x05S\x0dS\x0f", // Response ("S" + LS byte of getSock() return)
         8);                     // Length of response
 }
 
@@ -340,7 +340,7 @@ TEST(run, bad_sockets) {
     strcpy(result + 2 + sizeof(int), "ES");
 
     // Run the test
-    run_test(
+    runTest(
         "SU4\xbb\xbb\0\0\0\0"   // Port number will trigger simulated bind() fail
         "SU4\xcc\xcc\0\0\0\0"   // Port number will trigger simulated socket() fail
         "T",                    // Terminate
@@ -355,9 +355,9 @@ closeFail(int) {
 }
 
 TEST(run, cant_close) {
-    run_test("SU4\xff\xff\0\0\0\0", 9,
-             "S\x07", 2,
-             false, closeFail);
+    runTest("SU4\xff\xff\0\0\0\0", 9,
+            "S\x07", 2,
+            false, closeFail);
 }
 
 // A send of the file descriptor that fails.  In this case we expect the client
@@ -369,9 +369,9 @@ sendFDFail(const int, const int) {
 }
 
 TEST(run, cant_send_fd) {
-    run_test("SU4\xff\xff\0\0\0\0", 9,
-             "S", 1,
-             false, closeIgnore, sendFDFail);
+    runTest("SU4\xff\xff\0\0\0\0", 9,
+            "S", 1,
+            false, closeIgnore, sendFDFail);
 }
 
 }   // Anonymous namespace