From 5011966115e45efc47aaa8a0a257d570502868d0 Mon Sep 17 00:00:00 2001 From: Lefteris Chatzimparmpas Date: Thu, 23 Feb 2012 00:04:10 +0100 Subject: [PATCH] Ignore network errors during logout In case of a network failure during a logout request, there's no point in restoring the connection, but it is better to just close it. --- src/core.c | 3 +-- src/request.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/core.c b/src/core.c index d3f05bd..0e9b459 100644 --- a/src/core.c +++ b/src/core.c @@ -151,8 +151,7 @@ ifcore_logout(lua_State *lua) luaL_error(lua, "wrong number of arguments"); luaL_checktype(lua, 1, LUA_TLIGHTUSERDATA); - while ((r = request_logout((session *)(lua_topointer(lua, 1)))) == - STATUS_NONE); + r = request_logout((session *)(lua_topointer(lua, 1))); lua_pop(lua, 1); diff --git a/src/request.c b/src/request.c index 65b7de8..9fcc719 100644 --- a/src/request.c +++ b/src/request.c @@ -267,13 +267,21 @@ request_logout(session *ssn) { int t, r; - t = send_request(ssn, "LOGOUT"); - r = response_generic(ssn, t); + if ((t = send_request(ssn, "LOGOUT")) == -1) + goto fail; + if ((r = response_generic(ssn, t)) == -1) + goto fail; - close_connection(ssn); - session_destroy(ssn); + if (r == STATUS_OK) { + close_connection(ssn); + session_destroy(ssn); + } return r; +fail: + session_destroy(ssn); + + return STATUS_OK; }