From ab825123f297341ca3dbfdcfea8fd22d79bb5319 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Fri, 24 Apr 2020 14:26:58 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/myx/redis/client.hpp | 7 +++++-- src/myx/redis/lexer.hpp | 1 - src/myx/redis/parser-inl.hpp | 33 +++++++++++++++++++++++---------- src/myx/redis/parser.hpp | 3 ++- src/myx/redis/request.hpp | 2 +- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/myx/redis/client.hpp b/src/myx/redis/client.hpp index daeb845..187b6a7 100644 --- a/src/myx/redis/client.hpp +++ b/src/myx/redis/client.hpp @@ -136,9 +136,12 @@ class ClientPrivate : public QObject Lexer m_lexer; Parser m_parser; - Q_SLOT void sendReply( myx::redis::Reply& reply ) + Q_SLOT void sendReply( const myx::redis::Reply& reply ) { - Q_EMIT m_queue.dequeue()->reply( reply ); + if ( !m_queue.isEmpty() ) + { + Q_EMIT m_queue.dequeue()->reply( reply ); + } } }; // class ClientPrivate diff --git a/src/myx/redis/lexer.hpp b/src/myx/redis/lexer.hpp index 35cd881..c53b981 100644 --- a/src/myx/redis/lexer.hpp +++ b/src/myx/redis/lexer.hpp @@ -24,7 +24,6 @@ public: Lexer( Lexer&& ) = delete; Lexer& operator=( Lexer&& ) = delete; - ~Lexer() override = default; Q_SIGNAL void character( char ); diff --git a/src/myx/redis/parser-inl.hpp b/src/myx/redis/parser-inl.hpp index bea4888..df34a70 100644 --- a/src/myx/redis/parser-inl.hpp +++ b/src/myx/redis/parser-inl.hpp @@ -7,16 +7,19 @@ #include #endif +#include + namespace myx { namespace redis { MYXLIB_INLINE Parser::Parser( Lexer* lexer, QObject* parent ) : - QObject( parent ) + QObject( parent ), + m_lexer( lexer ) { - connect( lexer, &Lexer::character, this, &Parser::readCharacter ); - connect( lexer, &Lexer::unsafeString, this, &Parser::readUnsafeString ); - connect( lexer, &Lexer::safeString, this, &Parser::readSafeString ); + connect( m_lexer, &Lexer::character, this, &Parser::readCharacter ); + connect( m_lexer, &Lexer::unsafeString, this, &Parser::readUnsafeString ); + connect( m_lexer, &Lexer::safeString, this, &Parser::readSafeString ); } @@ -66,23 +69,33 @@ MYXLIB_INLINE void Parser::descend() { while ( true ) { - if ( ( tos().m_reply.type() == Reply::kMultiBulk ) && - ( tos().m_reply.value().toList().count() < tos().m_count ) ) + auto& task = tos(); + if ( task.m_reply.value().isNull() ) + { + task.m_reply.value().setValue( QList< QVariant >() ); + } + + if ( ( task.m_reply.type() == Reply::kMultiBulk ) && + ( task.m_reply.value().toList().count() < task.m_count ) ) { return; } if ( m_stack.count() == 1 ) { - auto r = m_stack.takeLast().m_reply; - Q_EMIT reply( r ); + Q_EMIT reply( m_stack.takeLast().m_reply ); return; } auto r = m_stack.takeLast().m_reply; - tos().m_reply.value().toList().append( QVariant::fromValue( r ) ); + + Task t = m_stack.takeLast(); + auto l = t.m_reply.value().toList(); + l.append( QVariant::fromValue( r ) ); + t.m_reply.value().setValue( l ); + m_stack.append( t ); } -} +} // Parser::descend } // namespace redis diff --git a/src/myx/redis/parser.hpp b/src/myx/redis/parser.hpp index 47133cd..239cff3 100644 --- a/src/myx/redis/parser.hpp +++ b/src/myx/redis/parser.hpp @@ -29,7 +29,7 @@ public: ~Parser() override = default; - Q_SIGNAL void reply( myx::redis::Reply& ); + Q_SIGNAL void reply( const myx::redis::Reply& ); private: Q_SLOT void readCharacter( char ); @@ -52,6 +52,7 @@ private: int m_count; }; + Lexer* m_lexer; QList< Task > m_stack; Task& tos() { return( m_stack.last() ); } diff --git a/src/myx/redis/request.hpp b/src/myx/redis/request.hpp index 6e01878..ad1dd1b 100644 --- a/src/myx/redis/request.hpp +++ b/src/myx/redis/request.hpp @@ -62,7 +62,7 @@ public: * @brief Emitted when a reply is received * @param reply the reply received */ - Q_SIGNAL void reply( myx::redis::Reply& reply ); + Q_SIGNAL void reply( const myx::redis::Reply& reply ); private: