Дополнительные проверки

This commit is contained in:
Andrei Astafev 2020-04-24 14:26:58 +03:00
parent 0b6132d692
commit ab825123f2
5 changed files with 31 additions and 15 deletions

View File

@ -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

View File

@ -24,7 +24,6 @@ public:
Lexer( Lexer&& ) = delete;
Lexer& operator=( Lexer&& ) = delete;
~Lexer() override = default;
Q_SIGNAL void character( char );

View File

@ -7,16 +7,19 @@
#include <myx/redis/parser.hpp>
#endif
#include <QDebug>
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

View File

@ -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() ); }

View File

@ -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: