Skip to content

Commit 674649c

Browse files
committed
Separate mysql response handler.
1 parent 86e08e8 commit 674649c

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

swoole_mysql.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ typedef struct _mysql_client
391391
off_t check_offset;
392392
mysql_response_t response; /* single response */
393393

394+
// for stored procedure
395+
zval* tmp_result;
396+
394397
} mysql_client;
395398

396399
#define mysql_request_buffer (SwooleTG.buffer_stack)

swoole_mysql_coro.cc

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,19 +1894,33 @@ static int swoole_mysql_coro_onRead(swReactor *reactor, swEvent *event)
18941894

18951895
_parse_response:
18961896

1897-
// always check that is packet complete
1898-
// and maybe more responses has already received in buffer, we check it now.
1899-
if ((client->cmd == SW_MYSQL_COM_QUERY || client->cmd == SW_MYSQL_COM_STMT_EXECUTE) && mysql_is_over(client) != SW_OK)
1897+
if (client->tmp_result)
19001898
{
1901-
// the **last** sever status flag shows that more results exist but we hasn't received.
1902-
swTraceLog(SW_TRACE_MYSQL_CLIENT, "need more");
1903-
return SW_OK;
1899+
_check_over:
1900+
// maybe more responses has already received in buffer, we check it now.
1901+
if (mysql_is_over(client) != SW_OK)
1902+
{
1903+
// the **last** sever status flag shows that more results exist but we hasn't received.
1904+
return SW_OK;
1905+
}
1906+
else
1907+
{
1908+
result = client->tmp_result;
1909+
client->tmp_result = NULL;
1910+
}
19041911
}
1905-
1906-
ret = swoole_mysql_coro_parse_response(client, &result, 0);
1907-
if (ret == SW_AGAIN)
1912+
else
19081913
{
1909-
return SW_OK; // parse error or need again
1914+
ret = swoole_mysql_coro_parse_response(client, &result, 0);
1915+
if (ret == SW_AGAIN)
1916+
{
1917+
return SW_OK; // parse error or need again
1918+
}
1919+
if (client->response.status_code & SW_MYSQL_SERVER_MORE_RESULTS_EXISTS)
1920+
{
1921+
client->tmp_result = result;
1922+
goto _check_over;
1923+
}
19101924
}
19111925
swoole_mysql_coro_parse_end(client, buffer); // ending tidy up
19121926

0 commit comments

Comments
 (0)