From 834e7cda28e6f15fb39e0f58ce51268ef8b36ac4 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 13 Oct 2005 22:37:39 +0000 Subject: [PATCH] Close session properly in FilterFrontendNet --- src/filter_frontend_net.cpp | 23 +++++++++++------- src/package.hpp | 5 ++++ src/test_filter_frontend_net.cpp | 49 ++++++++++++++++++++++++++++---------- 3 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/filter_frontend_net.cpp b/src/filter_frontend_net.cpp index ed9a475..6b2a46e 100644 --- a/src/filter_frontend_net.cpp +++ b/src/filter_frontend_net.cpp @@ -70,6 +70,9 @@ void ThreadPoolPackage::result() int len; m_session->send_GDU(gdu->get(), &len); } + if (m_session->m_no_requests == 0 && m_package->session().is_closed()) + delete m_session; + delete this; } IThreadPoolMsg *ThreadPoolPackage::handle() @@ -116,18 +119,22 @@ void P2_Session::recv_GDU(Z_GDU *z_pdu, int len) void P2_Session::failNotify() { // TODO: send Package to signal "close" - m_delete_flag = true; - if (m_no_requests == 0) - delete this; - + if (m_session.is_closed()) + return; + m_no_requests++; + + m_session.close(); + + Package *p = new Package(m_session, m_origin); + + ThreadPoolPackage *m = new ThreadPoolPackage(p, this); + p->copy_filter(*m_package); + m_my_thread->put(m); } void P2_Session::timeoutNotify() { - // TODO: send Package to signal "close" - m_delete_flag = true; - if (m_no_requests == 0) - delete this; + failNotify(); } void P2_Session::connectNotify() diff --git a/src/package.hpp b/src/package.hpp index d49301c..014bfeb 100644 --- a/src/package.hpp +++ b/src/package.hpp @@ -98,6 +98,11 @@ namespace yp2 { return m_response_gdu; } + /// get function - right val in assignment + Session session() const { + return m_session; + } + private: Session m_session; Origin m_origin; diff --git a/src/test_filter_frontend_net.cpp b/src/test_filter_frontend_net.cpp index f5ea15a..a8e5116 100644 --- a/src/test_filter_frontend_net.cpp +++ b/src/test_filter_frontend_net.cpp @@ -3,10 +3,11 @@ #include #include +#include "filter_frontend_net.hpp" + #include "router.hpp" #include "session.hpp" #include "package.hpp" -#include "filter_frontend_net.hpp" #define BOOST_AUTO_TEST_MAIN #include @@ -16,14 +17,25 @@ using namespace boost::unit_test; class FilterInit: public yp2::Filter { public: yp2::Package & process(yp2::Package & package) const { - ODR odr = odr_createmem(ODR_ENCODE); - Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse); - apdu->u.initResponse->implementationName = "YP2/YAZ"; - - package.response() = apdu; - odr_destroy(odr); - return package.move(); + Z_GDU *gdu = package.request().get(); + if (package.session().is_closed()) + { + // std::cout << "Got Close. Sending nothing\n"; + } + + if (gdu) + { + // std::cout << "Got PDU. Sending init response\n"; + ODR odr = odr_createmem(ODR_ENCODE); + Z_APDU *apdu = zget_APDU(odr, Z_APDU_initResponse); + + apdu->u.initResponse->implementationName = "YP2/YAZ"; + + package.response() = apdu; + odr_destroy(odr); + } + return package.move(); }; }; @@ -53,16 +65,30 @@ BOOST_AUTO_TEST_CASE( test_filter_frontend_net_2 ) router.rule(tf); + // Create package with Z39.50 init request in it yp2::Session session; yp2::Origin origin; yp2::Package pack_in(session, origin); - + + ODR odr = odr_createmem(ODR_ENCODE); + Z_APDU *apdu = zget_APDU(odr, Z_APDU_initRequest); + + pack_in.request() = apdu; + odr_destroy(odr); + // Done creating query. + + // Put it in router pack_in.router(router).move(); + // Inspect that we got Z39.50 init response yazpp_1::GDU *gdu = &pack_in.response(); - BOOST_CHECK_EQUAL(gdu->get()->which, Z_GDU_Z3950); - BOOST_CHECK_EQUAL(gdu->get()->u.z3950->which, Z_APDU_initResponse); + Z_GDU *z_gdu = gdu->get(); + BOOST_CHECK(z_gdu); + if (z_gdu) { + BOOST_CHECK_EQUAL(z_gdu->which, Z_GDU_Z3950); + BOOST_CHECK_EQUAL(z_gdu->u.z3950->which, Z_APDU_initResponse); + } } BOOST_CHECK(true); } @@ -77,7 +103,6 @@ BOOST_AUTO_TEST_CASE( test_filter_frontend_net_3 ) { { yp2::RouterChain router; - yp2::FilterFrontendNet filter_front; filter_front.listen_address() = "unix:socket"; filter_front.listen_duration() = 2; // listen a short time only -- 1.7.10.4