Move result start handling into separate function

The largest part of the code deals with the start of a response. Moving
this into a subfunction makes the function clearer as the switch statement
inside a switch statement is removed.
This commit is contained in:
Markus Mäkelä
2019-04-10 16:25:03 +03:00
parent 746bd53668
commit d2ecaa83a6
2 changed files with 54 additions and 45 deletions

View File

@ -142,6 +142,7 @@ public:
}
void process_packets(GWBUF* buffer);
void process_reply_start(mxs::Buffer::iterator it);
// Controlled by the session
ResponseStat& response_stat();

View File

@ -229,25 +229,9 @@ uint64_t is_last_eof(Iter it)
return (status & SERVER_MORE_RESULTS_EXIST) == 0;
}
void RWBackend::process_packets(GWBUF* result)
void RWBackend::process_reply_start(mxs::Buffer::iterator it)
{
mxs::Buffer buffer(result);
auto it = buffer.begin();
while (it != buffer.end())
{
// Extract packet length and command byte
uint32_t len = *it++;
len |= (*it++) << 8;
len |= (*it++) << 16;
++it; // Skip the sequence
mxb_assert(it != buffer.end());
auto end = std::next(it, len);
uint8_t cmd = *it;
switch (m_reply_state)
{
case REPLY_STATE_START:
m_local_infile_requested = false;
switch (cmd)
@ -276,7 +260,6 @@ void RWBackend::process_packets(GWBUF* result)
break;
default:
if (current_command() == MXS_COM_FIELD_LIST)
{
// COM_FIELD_LIST sends a strange kind of a result set
@ -291,6 +274,28 @@ void RWBackend::process_packets(GWBUF* result)
break;
}
}
void RWBackend::process_packets(GWBUF* result)
{
mxs::Buffer buffer(result);
auto it = buffer.begin();
while (it != buffer.end())
{
// Extract packet length and command byte
uint32_t len = *it++;
len |= (*it++) << 8;
len |= (*it++) << 16;
++it; // Skip the sequence
mxb_assert(it != buffer.end());
auto end = std::next(it, len);
uint8_t cmd = *it;
switch (m_reply_state)
{
case REPLY_STATE_START:
process_reply_start(it);
break;
case REPLY_STATE_DONE:
@ -323,11 +328,14 @@ void RWBackend::process_packets(GWBUF* result)
break;
case REPLY_STATE_RSET_ROWS:
if ((cmd == MYSQL_REPLY_EOF && len == MYSQL_EOF_PACKET_LEN - MYSQL_HEADER_LEN)
|| cmd == MYSQL_REPLY_ERR)
if (cmd == MYSQL_REPLY_EOF && len == MYSQL_EOF_PACKET_LEN - MYSQL_HEADER_LEN)
{
set_reply_state(is_last_eof(it) ? REPLY_STATE_DONE : REPLY_STATE_START);
}
else if (cmd == MYSQL_REPLY_ERR)
{
set_reply_state(REPLY_STATE_DONE);
}
break;
}