diff options
author | Kevin Harwell <kharwell@digium.com> | 2015-02-11 16:51:29 +0000 |
---|---|---|
committer | Kevin Harwell <kharwell@digium.com> | 2015-02-11 16:51:29 +0000 |
commit | 72e5ba2ce8ffe6076430add012f56eabaaa2381b (patch) | |
tree | 36b81f6fcb216ddbb16a312b799598c80e77a581 /res/ari | |
parent | 2531f750576542037e93f4c4e087f9dbced1897d (diff) |
res_http_websocket: websocket write timeout fails to fully disconnect
When writing to a websocket if a timeout occurred the underlying socket did not
get closed/disconnected. This patch makes sure the websocket gets disconnected
on a write timeout. Also a notice is logged stating that the websocket was
disconnected.
ASTERISK-24701 #close
Reported by: Matt Jordan
Review: https://reviewboard.asterisk.org/r/4412/
........
Merged revisions 431669 from http://svn.asterisk.org/svn/asterisk/branches/11
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@431670 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/ari')
-rw-r--r-- | res/ari/ari_websockets.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/res/ari/ari_websockets.c b/res/ari/ari_websockets.c index ff0a53c4f..683f00e19 100644 --- a/res/ari/ari_websockets.c +++ b/res/ari/ari_websockets.c @@ -100,6 +100,16 @@ struct ast_json *ast_ari_websocket_session_read( { RAII_VAR(struct ast_json *, message, NULL, ast_json_unref); + if (ast_websocket_fd(session->ws_session) < 0) { + return NULL; + } + + + if (ast_websocket_fd(session->ws_session) <= 0) { + return NULL; + } + + while (!message) { int res; char *payload; @@ -127,7 +137,7 @@ struct ast_json *ast_ari_websocket_session_read( switch (opcode) { case AST_WEBSOCKET_OPCODE_CLOSE: - ast_debug(1, "WebSocket closed by peer\n"); + ast_debug(1, "WebSocket closed\n"); return NULL; case AST_WEBSOCKET_OPCODE_TEXT: message = ast_json_load_buf(payload, payload_len, NULL); @@ -173,8 +183,12 @@ int ast_ari_websocket_session_write(struct ast_ari_websocket_session *session, } ast_debug(3, "Examining ARI event: \n%s\n", str); - return ast_websocket_write(session->ws_session, - AST_WEBSOCKET_OPCODE_TEXT, str, strlen(str)); + if (ast_websocket_write(session->ws_session, + AST_WEBSOCKET_OPCODE_TEXT, str, strlen(str))) { + ast_log(LOG_NOTICE, "Problem occurred during websocket write, websocket closed\n"); + return -1; + } + return 0; } void ari_handle_websocket(struct ast_websocket_server *ws_server, |