aboutsummaryrefslogtreecommitdiffstats
path: root/src/mysqlerl_port.erl
diff options
context:
space:
mode:
authorBrian Cully <bjc@kublai.com>2008-03-02 17:44:34 -0500
committerBrian Cully <github.20.shmit@spamgourmet.com>2008-03-02 17:44:34 -0500
commit52a4f21f1aa608b327af5d2e83cf0c0a29ff7c7e (patch)
tree0e3c3e48c3d192d736e07718b88032f5e5a5cf82 /src/mysqlerl_port.erl
parent2891b40b3a7799f67ba83c4914500cba7ca8aa1c (diff)
downloadmysqlerl-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_port.erl')
-rw-r--r--src/mysqlerl_port.erl6
1 files changed, 5 insertions, 1 deletions
diff --git a/src/mysqlerl_port.erl b/src/mysqlerl_port.erl
index 572bc11..3593119 100644
--- a/src/mysqlerl_port.erl
+++ b/src/mysqlerl_port.erl
@@ -32,7 +32,8 @@ terminate(Reason, State) ->
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
-handle_call(#req{request = Request}, From, #state{ref = Ref} = State) ->
+handle_call(#req{request = {Request, Timeout}}, From,
+ #state{ref = Ref} = State) ->
io:format("DEBUG: Sending request: ~p~n", [Request]),
port_command(Ref, term_to_binary(Request)),
receive
@@ -46,6 +47,9 @@ handle_call(#req{request = Request}, From, #state{ref = Ref} = State) ->
[Other]),
gen_server:reply(From, {error, connection_closed}),
{stop, {unknownreply, Other}, State}
+ after Timeout ->
+ gen_server:reply(From, timeout),
+ {stop, timeout, State}
end.
handle_cast(_Request, State) ->