[Quickfix-developers] Logout and DoNotSend
Brought to you by:
orenmnero
From: Olivier T. <oli...@ev...> - 2003-10-17 10:24:30
|
Hi, I'm using the C++ library of Quickfix 1.6.0 I've added a logout message to tradeclient. When I tested it with the executor_cpp.exe, I have noticed that tradeclient was sending a duplicate logout: - Tradeclient send logout message - Executor replies with a logout message - Tradeclient re-sends a logout message! This seemed to be due to the fact that the executor answer is so quick, being on the same machine, that mState.sentLogout is not set. In order to work-around this problem, I changed my Application::toAdmin() so that it throws a DoNotSend exception when receiving a logout from the counterparty (hoping that it will be handled like the DoNotSend exception coming from Application::toApp() to manage possible duplicates). I had to had a try/catch around the call to m_application.toAdmin() in sendRaw() (in session.cpp) The exception was caught fine, and the duplicate logout not sent. However, the sequence number was incremented, even though the second logout was never sent, so tradeclient and executor became out of sync. To remedy this, I had to make a simple change (see source below) so that when the DoNotSend exception is caught, the sequence number is not incremented. It seems to me that it never should be when there is a DoNotSend exception. Has any one else come across this? Any comments on these changes? No big deal I suppose, but I'd be interested in your views. Cheers, Olivier. Modified sendRaw() in session.cpp: bool Session::sendRaw( Message& message, int num ) { QF_STACK_PUSH(Session::sendRaw) Locker l( m_mutex ); try { bool result = false; bool notSent = false; Header& header = message.getHeader(); MsgType msgType; header.getField( msgType ); fill( header ); std::string messageString; if ( num ) header.setField( MsgSeqNum( num ) ); if ( Message::isAdminMsgType( msgType ) ) { try{ // new try-catch m_application.toAdmin( message, m_sessionID ); if ( msgType == "A" || msgType == "5" || msgType == "2" || msgType == "4" || isLoggedOn() ) result = send( message.toString(messageString) ); } catch ( DoNotSend&) { notSent = true; } } else { try { m_application.toApp( message, m_sessionID ); message.toString( messageString ); if ( isLoggedOn() ) result = send( messageString ); } catch ( DoNotSend& ) { notSent = true; // new Boolean to avoid sequence number increment } } if ( !num && !notSent) // new condition before incrementing sequence number { MsgSeqNum msgSeqNum; header.getField( msgSeqNum ); m_state.set( msgSeqNum, messageString ); m_state.incrNextSenderMsgSeqNum(); } return result; } catch ( IOException& ) { return false; } QF_STACK_POP } |