BIND 10 trac1593, updated. d3781127f6d22976c761003fba52df8c9c30436d [1593] suggested style cleanup: use the camel style for function names per guide
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 16 05:18:04 UTC 2012
The branch, trac1593 has been updated
via d3781127f6d22976c761003fba52df8c9c30436d (commit)
via b0d21f92b8fa563a1cba116a16109dc4c7164dc1 (commit)
from e40cec7b4d5a0fc473bb5d4abfb6a93a712e0cb4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d3781127f6d22976c761003fba52df8c9c30436d
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Wed Feb 15 20:37:36 2012 -0800
[1593] suggested style cleanup: use the camel style for function names per guide
commit b0d21f92b8fa563a1cba116a16109dc4c7164dc1
Author: JINMEI Tatuya <jinmei at isc.org>
Date: Wed Feb 15 20:25:56 2012 -0800
[1593] some trivial style fixes. mostly to be aligned with the guideline.
also constify some variables, and remove unnecessary cast.
-----------------------------------------------------------------------
Summary of changes:
src/bin/sockcreator/sockcreator.cc | 74 ++++++++++++------------
src/bin/sockcreator/sockcreator.h | 8 +-
src/bin/sockcreator/tests/sockcreator_tests.cc | 62 ++++++++++----------
3 files changed, 71 insertions(+), 73 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc
index 639ae75..be35978 100644
--- a/src/bin/sockcreator/sockcreator.cc
+++ b/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, static_cast<void*>(&addr_in.sin_port),
- sizeof(addr_in.sin_port));
- read_message(input_fd, static_cast<void*>(&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, static_cast<void*>(&addr_in6.sin6_port),
- sizeof(addr_in6.sin6_port));
- read_message(input_fd, static_cast<void*>(&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
- 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);
+ 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:
@@ -160,8 +159,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<void*>(&error), sizeof error);
+ const int error = errno;
+ writeMessage(output_fd, &error, sizeof(error));
}
}
@@ -172,24 +171,25 @@ 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)
-{
- int sock = socket(bind_addr->sa_family, type, 0);
+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;
+ 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.
@@ -199,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);
}
}
}
diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h
index 3aad2d2..fd6975d 100644
--- a/src/bin/sockcreator/sockcreator.h
+++ b/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);
diff --git a/src/bin/sockcreator/tests/sockcreator_tests.cc b/src/bin/sockcreator/tests/sockcreator_tests.cc
index 5bafbb8..eccc3ed 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 <iostream>
-
#include "../sockcreator.h"
#include <util/unittests/fork.h>
@@ -25,6 +23,8 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
+
+#include <iostream>
#include <cstring>
#include <cerrno>
@@ -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<sockaddr*>(&addr);
- 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,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)
-{
+getSockDummy(const int type, struct sockaddr* addr, const socklen_t) {
int result = 0;
int port = 0;
@@ -243,10 +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.
@@ -265,29 +263,29 @@ 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
// 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
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);
}
@@ -303,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
@@ -323,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
}
@@ -342,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
@@ -357,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
@@ -371,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
More information about the bind10-changes
mailing list