From ada23e9e17bad882d06aa40f80c11355e8a140f9 Mon Sep 17 00:00:00 2001 From: tgic Date: Fri, 7 Mar 2014 15:56:39 +0800 Subject: [PATCH 1/2] fix issue 47 Connection obj cant search the right result --- lib/Connection.cpp | 14 ++++++++++++++ lib/Connection.h | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/Connection.cpp b/lib/Connection.cpp index fcacef6..a5aeb84 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -83,6 +83,7 @@ Connection::Connection (UMConnectionCAPI *_capi) m_errno = -1; memcpy (&m_capi, _capi, sizeof (UMConnectionCAPI)); m_dbgMethodProgress = 0; + m_dbgFailedRecv = 0; m_errorType = UME_OTHER; } @@ -736,6 +737,18 @@ void *Connection::query(const char *_query, size_t _cbQuery) return NULL; } + if (m_dbgFailedRecv > 0) + { + if (!recvPacket()) + { + m_dbgMethodProgress --; + return NULL; + } + + m_reader.skip(); // pop dirty packages sent succ but recv failed + m_dbgFailedRecv --; + } + size_t len = _cbQuery; if (len > m_writer.getSize () - (MYSQL_PACKET_HEADER_SIZE + 1)) @@ -762,6 +775,7 @@ void *Connection::query(const char *_query, size_t _cbQuery) { PRINTMARK(); m_dbgMethodProgress --; + m_dbgFailedRecv ++; return NULL; } diff --git a/lib/Connection.h b/lib/Connection.h index 2d410fe..7aec623 100644 --- a/lib/Connection.h +++ b/lib/Connection.h @@ -108,6 +108,7 @@ class Connection UMConnectionCAPI m_capi; int m_dbgMethodProgress; + int m_dbgFailedRecv; public: @@ -145,4 +146,4 @@ class Connection protected: }; -#endif \ No newline at end of file +#endif From 10008123d06b0240b65d8f3aadcd677680930de4 Mon Sep 17 00:00:00 2001 From: tgic Date: Fri, 7 Mar 2014 19:00:09 +0800 Subject: [PATCH 2/2] fix dirty select package --- lib/Connection.cpp | 81 +++++++++++++++++++++++++++------------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/lib/Connection.cpp b/lib/Connection.cpp index a5aeb84..53b1445 100644 --- a/lib/Connection.cpp +++ b/lib/Connection.cpp @@ -737,17 +737,6 @@ void *Connection::query(const char *_query, size_t _cbQuery) return NULL; } - if (m_dbgFailedRecv > 0) - { - if (!recvPacket()) - { - m_dbgMethodProgress --; - return NULL; - } - - m_reader.skip(); // pop dirty packages sent succ but recv failed - m_dbgFailedRecv --; - } size_t len = _cbQuery; @@ -779,33 +768,59 @@ void *Connection::query(const char *_query, size_t _cbQuery) return NULL; } - UINT8 result = m_reader.readByte(); - - switch (result) + void * topResult = NULL; + bool again; + do { - case 0x00: - PRINTMARK(); - m_dbgMethodProgress --; - return handleOKPacket(); + again = false; - case 0xff: - PRINTMARK(); - handleErrorPacket(); - m_dbgMethodProgress --; - return NULL; + UINT8 result = m_reader.readByte(); - case 0xfe: - PRINTMARK(); - setError ("Unexpected EOF when decoding result", 0, UME_OTHER); - m_dbgMethodProgress --; - return NULL; + switch (result) + { + case 0x00: + PRINTMARK(); + m_dbgMethodProgress --; + topResult = handleOKPacket(); + break; + case 0xff: + PRINTMARK(); + handleErrorPacket(); + m_dbgMethodProgress --; + topResult = NULL; + break; - default: - PRINTMARK(); - m_dbgMethodProgress --; - return handleResultPacket((int)result); - } + case 0xfe: + PRINTMARK(); + setError ("Unexpected EOF when decoding result", 0, UME_OTHER); + m_dbgMethodProgress --; + topResult = NULL; + break; + + default: + PRINTMARK(); + m_dbgMethodProgress --; + topResult = handleResultPacket((int)result); + break; + } + + + if (m_dbgFailedRecv > 0) + { + again = true; + if (!recvPacket()) + { + m_dbgMethodProgress --; + return NULL; + } + + m_dbgFailedRecv --; + } + + }while(again); + + return topResult; PRINTMARK(); m_dbgMethodProgress --;