From 11170b362e9733005bd3badef8669a0c1c28a8c7 Mon Sep 17 00:00:00 2001 From: Edouard DUPIN Date: Mon, 16 May 2016 23:34:27 +0200 Subject: [PATCH] [DEV] send close event --- jus/TcpString.cpp | 24 +++++++++++++----- .../lutin_jus-gateway.cpython-35.pyc | Bin 1433 -> 1433 bytes 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/jus/TcpString.cpp b/jus/TcpString.cpp index c6016ba..44fdbc7 100644 --- a/jus/TcpString.cpp +++ b/jus/TcpString.cpp @@ -65,6 +65,8 @@ void jus::TcpString::connect(){ void jus::TcpString::disconnect(){ JUS_DEBUG("disconnect [START]"); + uint32_t size = 0xFFFFFFFF; + m_connection.write(&size, 4); if (m_thread != nullptr) { m_threadRunning = false; m_connection.unlink(); @@ -86,21 +88,29 @@ int32_t jus::TcpString::write(const std::string& _data) { std::string jus::TcpString::read() { // TODO : Do it better with a correct way to check data size ... + JUS_WARNING("Read [START]"); std::string out; uint32_t size = 0; int32_t len = m_connection.read(&size, 4); if (len != 4) { JUS_ERROR("Protocol error occured ..."); } else { - out.resize(size); - len = m_connection.read(&out[0], size); - if (len == 0) { - JUS_WARNING("Read No data"); - } else if (len != size) { - // TODO do it again ... - JUS_ERROR("Protocol error occured .2."); + if (size == -1) { + JUS_WARNING("Remote close connection"); + m_threadRunning = false; + //m_connection.unlink(); + } else { + out.resize(size); + len = m_connection.read(&out[0], size); + if (len == 0) { + JUS_WARNING("Read No data"); + } else if (len != size) { + // TODO do it again ... + JUS_ERROR("Protocol error occured .2."); + } } } + JUS_WARNING("Read [STOP]"); return out; } diff --git a/tools/gateway/__pycache__/lutin_jus-gateway.cpython-35.pyc b/tools/gateway/__pycache__/lutin_jus-gateway.cpython-35.pyc index cbf4774fe49486c5c00f3d46895c0626e4def6d1..49c394819df54becbb35396e4ab95e4f45a325dd 100644 GIT binary patch delta 16 XcmbQqJ(HVVjF*?olgE4``y^HX9UB8> delta 16 XcmbQqJ(HVVjF*?|Z