[svn] commit: r3160 - in /branches/vorner-sockcreator/src/bin/sockcreator: sockcreator.cc sockcreator.h tests/sockcreator_tests.cc
BIND 10 source code commits
bind10-changes at lists.isc.org
Sun Oct 10 08:02:13 UTC 2010
Author: vorner
Date: Sun Oct 10 08:02:12 2010
New Revision: 3160
Log:
Code style correction
The rest of code seems to have space between if/while and the
parenthesis.
Modified:
branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.cc
branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.h
branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc
Modified: branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.cc
==============================================================================
--- branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.cc (original)
+++ branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.cc Sun Oct 10 08:02:12 2010
@@ -24,10 +24,10 @@
get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len)
{
int sock(socket(bind_addr->sa_family, type, 0));
- if(sock == -1) {
+ if (sock == -1) {
return -1;
}
- if(bind(sock, bind_addr, addr_len) == -1) {
+ if (bind(sock, bind_addr, addr_len) == -1) {
return -2;
}
return sock;
@@ -49,10 +49,10 @@
write_data(const int fd, const char *buffer, const size_t length) {
size_t rest(length);
// Just keep writing until all is written
- while(rest) {
+ while (rest) {
ssize_t written(write(fd, buffer, rest));
- if(rest == -1) {
- if(errno == EINTR) { // Just keep going
+ if (rest == -1) {
+ if (errno == EINTR) { // Just keep going
continue;
} else {
return false;
@@ -68,15 +68,15 @@
ssize_t
read_data(const int fd, char *buffer, const size_t length) {
size_t rest(length), already(0);
- while(rest) { // Stil something to read
+ while (rest) { // Stil something to read
ssize_t amount(read(fd, buffer, rest));
- if(rest == -1) {
- if(errno == EINTR) { // Continue on interrupted call
+ if (rest == -1) {
+ if (errno == EINTR) { // Continue on interrupted call
continue;
} else {
return -1;
}
- } else if(amount) {
+ } else if (amount) {
already += amount;
rest -= amount;
buffer += amount;
Modified: branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.h
==============================================================================
--- branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.h (original)
+++ branches/vorner-sockcreator/src/bin/sockcreator/sockcreator.h Sun Oct 10 08:02:12 2010
@@ -77,6 +77,11 @@
* file descriptor, creates sockets and writes the results (socket or
* error) to output_fd.
*
+ * Current errors are:
+ * - 1: Read error
+ * - 2: Write error
+ * - 3: Protocol error (unknown command, etc)
+ *
* It terminates either if a command asks it to or when unrecoverable
* error happens.
*
Modified: branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc
==============================================================================
--- branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc (original)
+++ branches/vorner-sockcreator/src/bin/sockcreator/tests/sockcreator_tests.cc Sun Oct 10 08:02:12 2010
@@ -58,15 +58,15 @@
<< socket << " and errno " << errno; \
CHECK_SOCK(ADDR_TYPE, socket); \
EXPECT_EQ(0, close(socket)); \
- } while(0)
+ } while (0)
// Just helper macros
-#define INADDR_SET(WHAT) do { WHAT.sin_addr.s_addr = INADDR_ANY; } while(0)
-#define IN6ADDR_SET(WHAT) do { WHAT.sin6_addr = in6addr_any; } while(0)
+#define INADDR_SET(WHAT) do { WHAT.sin_addr.s_addr = INADDR_ANY; } while (0)
+#define IN6ADDR_SET(WHAT) do { WHAT.sin6_addr = in6addr_any; } while (0)
// If the get_sock returned something useful, listen must work
#define TCP_CHECK(UNUSED, SOCKET) do { \
EXPECT_EQ(0, listen(SOCKET, 1)); \
- } while(0)
+ } while (0)
// More complicated with UDP, so we send a packet to ourselfs and se if it
// arrives
#define UDP_CHECK(ADDR_TYPE, SOCKET) do { \
@@ -81,7 +81,7 @@
char buffer[5]; \
ASSERT_EQ(5, recv(SOCKET, buffer, 5, 0)); \
EXPECT_STREQ("test", buffer); \
- } while(0)
+ } while (0)
/*
* Several tests to ensure we can create the sockets.
@@ -121,16 +121,16 @@
pid_t
provide_input(int *read_pipe, const char *input, const size_t length) {
int pipes[2];
- if(pipe(pipes)) {
+ if (pipe(pipes)) {
return -1;
}
*read_pipe = pipes[0];
pid_t pid(fork());
- if(pid) { // We are in the parent
+ if (pid) { // We are in the parent
return pid;
} else { // This is in the child, just puth the data there
close(pipes[0]);
- if(!write_data(pipes[1], input, length)) {
+ if (!write_data(pipes[1], input, length)) {
exit(1);
} else {
close(pipes[1]);
@@ -146,18 +146,18 @@
pid_t
check_output(int *write_pipe, const char *output, const size_t length) {
int pipes[2];
- if(pipe(pipes)) {
+ if (pipe(pipes)) {
return -1;
}
*write_pipe = pipes[1];
pid_t pid(fork());
- if(pid) { // We are in parent
+ if (pid) { // We are in parent
return pid;
} else {
close(pipes[1]);
char buffer[length + 1];
// Try to read one byte more to see if the output ends here
- if(read_data(pipes[0], buffer, length + 1) != length)
+ if (read_data(pipes[0], buffer, length + 1) != length)
exit(1);
// Normalize the return value - return 0 on equality, 1 on nonequality
exit(!!memcmp(buffer, output, length));
@@ -177,8 +177,8 @@
* but we might have another tests to run.
*/
alarm(3);
- if(waitpid(process, &status, 0) == -1) {
- if(errno == EINTR)
+ if (waitpid(process, &status, 0) == -1) {
+ if (errno == EINTR)
kill(process, SIGTERM);
return false;
}
@@ -200,7 +200,7 @@
* The familly is similar - third bit is known address family,
* the fourth is the family.
*/
- switch(type) {
+ switch (type) {
case SOCK_STREAM:
result += 1;
break;
@@ -208,7 +208,7 @@
result += 3;
break;
}
- switch(addr->sa_family) {
+ switch (addr->sa_family) {
case AF_INET:
result += 4;
port = static_cast<struct sockaddr_in *>(
@@ -225,11 +225,11 @@
* The port of 0xbbbb means bind should fail and 0xcccc means
* socket should fail.
*/
- if(port != 0xffff) {
+ if (port != 0xffff) {
errno = 0;
- if(port == 0xbbbb) {
+ if (port == 0xbbbb) {
return -2;
- } else if(port == 0xcccc) {
+ } else if (port == 0xcccc) {
return -1;
} else {
result += 16;
@@ -246,7 +246,7 @@
* the test anyway.
*/
char fd_data(what);
- if(!write_data(destination, &fd_data, 1))
+ if (!write_data(destination, &fd_data, 1))
return -1;
}
@@ -268,7 +268,7 @@
ASSERT_NE(-1, output) << "Couldn't start output checker";
// Run the body
int result(run(input_fd, output_fd, get_sock_dummy, send_fd_dummy));
- if(should_succeed) {
+ if (should_succeed) {
EXPECT_EQ(0, result);
} else {
EXPECT_NE(0, result);
More information about the bind10-changes
mailing list