BIND 10 trac1593, updated. 955d8f31227b9429548de4da6fbe40350509cf04 [1593] Addressed comments from review
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Feb 16 13:56:44 UTC 2012
The branch, trac1593 has been updated
via 955d8f31227b9429548de4da6fbe40350509cf04 (commit)
from d3781127f6d22976c761003fba52df8c9c30436d (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 955d8f31227b9429548de4da6fbe40350509cf04
Author: Stephen Morris <stephen at isc.org>
Date: Thu Feb 16 13:55:35 2012 +0000
[1593] Addressed comments from review
-----------------------------------------------------------------------
Summary of changes:
src/bin/sockcreator/main.cc | 8 ++--
src/bin/sockcreator/sockcreator.cc | 74 ++++++++++++++++++++++-------------
src/bin/sockcreator/sockcreator.h | 7 ++-
3 files changed, 54 insertions(+), 35 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/sockcreator/main.cc b/src/bin/sockcreator/main.cc
index c97e0ff..3e06882 100644
--- a/src/bin/sockcreator/main.cc
+++ b/src/bin/sockcreator/main.cc
@@ -13,6 +13,7 @@
// PERFORMANCE OF THIS SOFTWARE.
#include "sockcreator.h"
+#include <unistd.h>
using namespace isc::socket_creator;
@@ -22,11 +23,10 @@ main() {
* TODO Maybe use some OS-specific caps interface and drop everything
* but ability to bind ports? It would be nice.
*/
- int status = 0;
try {
- run(0, 1); // Read commands from stdin, output to stdout
+ run(STDIN_FILENO, STDOUT_FILENO);
} catch (const SocketCreatorError& ec) {
- status = ec.getExitCode();
+ return (ec.getExitCode());
}
- return (status);
+ return (0);
}
diff --git a/src/bin/sockcreator/sockcreator.cc b/src/bin/sockcreator/sockcreator.cc
index be35978..68d77fb 100644
--- a/src/bin/sockcreator/sockcreator.cc
+++ b/src/bin/sockcreator/sockcreator.cc
@@ -58,6 +58,45 @@ protocolError(const int fd, const char reason = 'I') {
isc_throw(ProtocolError, "Fatal error, reason: " << reason);
}
+// Return appropriate socket type constant for the socket type requested.
+// The output_fd argument is required to report a protocol error.
+int getSocketType(const char type_code, const int output_fd) {
+ int socket_type = 0;
+ switch (type_code) {
+ case 'T':
+ socket_type = SOCK_STREAM;
+ break;
+
+ case 'U':
+ socket_type = SOCK_DGRAM;
+ break;
+
+ default:
+ protocolError(output_fd); // Does not return
+ }
+ return (socket_type);
+}
+
+// Convert return status from getSock() to a character to be sent back to
+// the caller.
+char getErrorCode(const int status) {
+ char error_code = ' ';
+ switch (status) {
+ case -1:
+ error_code = 'S';
+ break;
+
+ case -2:
+ error_code = 'B';
+ break;
+
+ default:
+ isc_throw(InternalError, "Error creating socket");
+ }
+ return (error_code);
+}
+
+
// Handle the request from the client.
//
// Reads the type and family of socket required, creates the socket and returns
@@ -75,19 +114,7 @@ handleRequest(const int input_fd, const int output_fd,
readMessage(input_fd, type, sizeof(type));
// Decide what type of socket is being asked for
- int sock_type = 0;
- switch (type[0]) {
- case 'T':
- sock_type = SOCK_STREAM;
- break;
-
- case 'U':
- sock_type = SOCK_DGRAM;
- break;
-
- default:
- protocolError(output_fd);
- }
+ const int sock_type = getSocketType(type[0], output_fd);
// Read the address they ask for depending on what address family was
// specified.
@@ -144,23 +171,14 @@ handleRequest(const int input_fd, const int output_fd,
}
} else {
// Error. Tell the client.
- writeMessage(output_fd, "E", 1); // Error occurred...
- switch (result) {
- case -1:
- writeMessage(output_fd, "S", 1); // ... in the socket() call
- break;
-
- case -2:
- writeMessage(output_fd, "B", 1); // ... in the bind() call
- break;
-
- default:
- isc_throw(InternalError, "Error creating socket");
- }
+ char error_message[2];
+ error_message[0] = 'E';
+ error_message[1] = getErrorCode(result);
+ writeMessage(output_fd, error_message, sizeof(error_message));
// ...and append the reason code to the error message
- const int error = errno;
- writeMessage(output_fd, &error, sizeof(error));
+ const int error_number = errno;
+ writeMessage(output_fd, &error_number, sizeof(error_number));
}
}
diff --git a/src/bin/sockcreator/sockcreator.h b/src/bin/sockcreator/sockcreator.h
index fd6975d..df2bf8f 100644
--- a/src/bin/sockcreator/sockcreator.h
+++ b/src/bin/sockcreator/sockcreator.h
@@ -116,10 +116,11 @@ typedef int (*close_t)(int);
/// It terminates either if a command asks it to or when unrecoverable error
/// happens.
///
-/// \param input_fd File descriptor of the stream from which the input commands
+/// \param input_fd File number of the stream from which the input commands
/// are read.
-/// \param output_fd File descriptor of the stream to which the output
-/// (message/socket or error message) is written.
+/// \param output_fd File number of the stream to which the response is
+/// written. The socket is sent as part of a control message associated
+/// with that stream.
/// \param get_sock_fun The function that is used to create the sockets.
/// This should be left on the default value, the parameter is here
/// for testing purposes.
More information about the bind10-changes
mailing list