From ab33ebd0838607305cae5f25f4dedddcc0742e17 Mon Sep 17 00:00:00 2001 From: Michael Santos Date: Fri, 25 Apr 2014 12:18:59 +0000 Subject: [PATCH] Change the message to include the gen_server PID Modify the message format from: {pid(), {atom(), [non_neg_integer()], any()}} To: {atom(), pid(), [non_neg_integer()], any()} Using a deeply nested tuple is similar to how port drivers are handled and is more efficient, since it doesn't require destructuring the tuple returned from decode/1. But flat tuples are consistent with the gen_tcp/gen_udp interfaces and mirror the calling conventions for the rest of alcove, e.g.: alcove:chdir(pid(), [non_neg_integer()], iodata()]) --- src/alcove_drv.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/alcove_drv.erl b/src/alcove_drv.erl index 19192f0..4c45d25 100644 --- a/src/alcove_drv.erl +++ b/src/alcove_drv.erl @@ -207,7 +207,8 @@ code_change(_OldVsn, State, _Extra) -> % Several writes from the child process may be coalesced into 1 read by % the parent. handle_info({Port, {data, Data}}, #state{port = Port, pid = Pid} = State) -> - [ Pid ! {self(), Msg} || Msg <- decode(Data) ], + [ Pid ! {Tag, self(), Pids, Term} || + {Tag, Pids, Term} <- decode(Data) ], {noreply, State}; handle_info({'EXIT', Port, Reason}, #state{port = Port} = State) -> @@ -224,7 +225,7 @@ handle_info(Info, State) -> reply(Drv, Pids, Type, Timeout) -> Tag = type_to_atom(Type), receive - {Drv, {Tag, Pids, Event}} -> + {Tag, Drv, Pids, Event} -> Event after Timeout ->