[Asterisk-code-review] res http websocket: Debug write lengths. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Wed Aug 5 10:08:45 CDT 2015


Joshua Colp has submitted this change and it was merged.

Change subject: res_http_websocket: Debug write lengths.
......................................................................


res_http_websocket: Debug write lengths.

Commit 39cc28f6ea2140ad6d561fd4c9e9a66f065cecee attempted to fix a
test failure observed on 32 bit test agents by ensuring that a cast from
a 32 bit unsigned integer to a 64 bit unsigned integer was happening in
a predictable place. As it turns out, this did not cause test runs to
succeed.

This commit adds several redundant debug messages that print the payload
lengths of websocket frames. The idea here is that this commit will not
cause tests to succeed for the faulty test agent, but we might deduce
where the fault lies more easily this way by observing at what point the
expected value (537) changes to some ungangly huge number.

If you are wondering why something like this is being committed to the
branch, keep in mind that in commit
39cc28f6ea2140ad6d561fd4c9e9a66f065cecee I noted that the observed test
failures only happen when automated tests are run. Attempts to run the
tests by hand manually on the test agent result in the tests passing.

Change-Id: I14a65c19d8af40dadcdbd52348de3b0016e1ae8d
---
M res/ari/ari_websockets.c
M res/res_http_websocket.c
2 files changed, 24 insertions(+), 1 deletion(-)

Approvals:
  Anonymous Coward #1000019: Verified
  Ashley Sanders: Looks good to me, but someone else must approve
  Joshua Colp: Looks good to me, approved



diff --git a/res/ari/ari_websockets.c b/res/ari/ari_websockets.c
index 1d2eacd..39c6dca 100644
--- a/res/ari/ari_websockets.c
+++ b/res/ari/ari_websockets.c
@@ -174,7 +174,7 @@
 		return -1;
 	}
 
-	ast_debug(3, "Examining ARI event: \n%s\n", str);
+	ast_debug(3, "Examining ARI event (length %zu): \n%s\n", strlen(str), str);
 	if (ast_websocket_write_string(session->ws_session, str)) {
 		ast_log(LOG_NOTICE, "Problem occurred during websocket write, websocket closed\n");
 		return -1;
diff --git a/res/res_http_websocket.c b/res/res_http_websocket.c
index bad8337..db9c50a 100644
--- a/res/res_http_websocket.c
+++ b/res/res_http_websocket.c
@@ -298,6 +298,24 @@
 	return res;
 }
 
+static const char *opcode_map[] = {
+	[AST_WEBSOCKET_OPCODE_CONTINUATION] = "continuation",
+	[AST_WEBSOCKET_OPCODE_TEXT] = "text",
+	[AST_WEBSOCKET_OPCODE_BINARY] = "binary",
+	[AST_WEBSOCKET_OPCODE_CLOSE] = "close",
+	[AST_WEBSOCKET_OPCODE_PING] = "ping",
+	[AST_WEBSOCKET_OPCODE_PONG] = "pong",
+};
+
+static const char *websocket_opcode2str(enum ast_websocket_opcode opcode)
+{
+	if (opcode < AST_WEBSOCKET_OPCODE_CONTINUATION ||
+			opcode > AST_WEBSOCKET_OPCODE_PONG) {
+		return "<unknown>";
+	} else {
+		return opcode_map[opcode];
+	}
+}
 
 /*! \brief Write function for websocket traffic */
 int AST_OPTIONAL_API_NAME(ast_websocket_write)(struct ast_websocket *session, enum ast_websocket_opcode opcode, char *payload, uint64_t actual_length)
@@ -305,6 +323,9 @@
 	size_t header_size = 2; /* The minimum size of a websocket frame is 2 bytes */
 	char *frame;
 	uint64_t length;
+
+	ast_debug(3, "Writing websocket %s frame, length %" PRIu64 "\n",
+			websocket_opcode2str(opcode), actual_length);
 
 	if (actual_length < 126) {
 		length = actual_length;
@@ -1356,6 +1377,8 @@
 {
 	uint64_t len = strlen(buf);
 
+	ast_debug(3, "Writing websocket string of length %" PRIu64 "\n", len);
+
 	/* We do not pass strlen(buf) to ast_websocket_write() directly because the
 	 * size_t returned by strlen() may not require the same storage size
 	 * as the uint64_t that ast_websocket_write() uses. This normally

-- 
To view, visit https://gerrit.asterisk.org/1033
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I14a65c19d8af40dadcdbd52348de3b0016e1ae8d
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: Ashley Sanders <asanders at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list