diff options
author | Brian Cully <bjc@kublai.com> | 2008-03-02 17:44:34 -0500 |
---|---|---|
committer | Brian Cully <github.20.shmit@spamgourmet.com> | 2008-03-02 17:44:34 -0500 |
commit | 52a4f21f1aa608b327af5d2e83cf0c0a29ff7c7e (patch) | |
tree | 0e3c3e48c3d192d736e07718b88032f5e5a5cf82 /src/mysqlerl.c | |
parent | 2891b40b3a7799f67ba83c4914500cba7ca8aa1c (diff) | |
download | mysqlerl-52a4f21f1aa608b327af5d2e83cf0c0a29ff7c7e.tar.gz mysqlerl-52a4f21f1aa608b327af5d2e83cf0c0a29ff7c7e.zip |
Handle timeouts.
Pass timeout down to port level, and if the communication times out,
kill the port and let the supervisor restart it.
Also stub in select_count and param_query, conveniently used to test
timing out.
Diffstat (limited to 'src/mysqlerl.c')
-rw-r--r-- | src/mysqlerl.c | 41 |
1 files changed, 36 insertions, 5 deletions
diff --git a/src/mysqlerl.c b/src/mysqlerl.c index 5cec054..79731b7 100644 --- a/src/mysqlerl.c +++ b/src/mysqlerl.c @@ -13,7 +13,8 @@ #include <string.h> const char *QUERY_MSG = "sql_query"; -const char *PARAM_QUERY_MSG = "param_query_msg"; +const char *PARAM_QUERY_MSG = "sql_param_query"; +const char *SELECT_COUNT_MSG = "sql_select_count"; void usage() @@ -138,7 +139,7 @@ handle_mysql_result(MYSQL_RES *result) } void -handle_sql_query(MYSQL *dbh, ETERM *cmd) +handle_query(MYSQL *dbh, ETERM *cmd) { ETERM *query, *resp; char *q; @@ -174,8 +175,35 @@ handle_sql_query(MYSQL *dbh, ETERM *cmd) } void -handle_sql_param_query(MYSQL *dbh, ETERM *cmd) +handle_param_query(MYSQL *dbh, ETERM *msg) { + ETERM *query, *params; + char *q; + + query = erl_element(2, msg); + params = erl_element(3, msg); + q = erl_iolist_to_string(query); + erl_free_term(query); + erl_free_term(params); + + logmsg("DEBUG: got param query msg: %s.", q); + + erl_free(q); +} + +void +handle_select_count(MYSQL *dbh, ETERM *msg) +{ + ETERM *query; + char *q; + + query = erl_element(2, msg); + q = erl_iolist_to_string(query); + erl_free_term(query); + + logmsg("DEBUG: got select count msg: %s.", q); + + erl_free(q); } void @@ -186,10 +214,13 @@ dispatch_db_cmd(MYSQL *dbh, ETERM *msg) tag = erl_element(1, msg); if (strncmp((char *)ERL_ATOM_PTR(tag), QUERY_MSG, strlen(QUERY_MSG)) == 0) { - handle_sql_query(dbh, msg); + handle_query(dbh, msg); } else if (strncmp((char *)ERL_ATOM_PTR(tag), PARAM_QUERY_MSG, strlen(PARAM_QUERY_MSG)) == 0) { - handle_sql_param_query(dbh, msg); + handle_param_query(dbh, msg); + } else if (strncmp((char *)ERL_ATOM_PTR(tag), + SELECT_COUNT_MSG, strlen(SELECT_COUNT_MSG)) == 0) { + handle_select_count(dbh, msg); } else { logmsg("WARNING: message type %s unknown.", (char *)ERL_ATOM_PTR(tag)); erl_free_term(tag); |