summaryrefslogtreecommitdiff
path: root/p11p-daemon/src/p11p_server.erl
diff options
context:
space:
mode:
Diffstat (limited to 'p11p-daemon/src/p11p_server.erl')
-rw-r--r--p11p-daemon/src/p11p_server.erl20
1 files changed, 10 insertions, 10 deletions
diff --git a/p11p-daemon/src/p11p_server.erl b/p11p-daemon/src/p11p_server.erl
index ab71c6d..880a8c0 100644
--- a/p11p-daemon/src/p11p_server.erl
+++ b/p11p-daemon/src/p11p_server.erl
@@ -28,13 +28,13 @@
start_link(Args) ->
gen_server:start_link(?MODULE, Args, []).
--spec add_to_clientbuf(pid(), binary()) -> binary().
+-spec add_to_clientbuf(pid(), binary()) -> {ok, non_neg_integer()}.
add_to_clientbuf(Pid, Data) ->
gen_server:call(Pid, {add_to_clientbuf, Data}).
--spec reply(pid(), p11rpc_msg()) -> ok.
+-spec reply(pid(), p11rpc_msg()) -> {ok, non_neg_integer()}.
reply(Pid, Response) ->
- gen_server:cast(Pid, {response, Response}).
+ gen_server:call(Pid, {response, Response}).
%% Genserver callbacks.
init([Token, SocketPath, Socket]) ->
@@ -45,7 +45,13 @@ init([Token, SocketPath, Socket]) ->
handle_call({add_to_clientbuf, Data}, _From, #state{clientbuf = Buf} = State) ->
NewBuf = <<Buf/binary, Data/binary>>,
- {reply, NewBuf, State#state{clientbuf = NewBuf}};
+ {reply, {ok, size(NewBuf)}, State#state{clientbuf = NewBuf}};
+handle_call({response, Response}, _From, #state{socket = ClientPort, clientbuf = Buf} = State) ->
+ Data = p11p_rpc:serialise(Response),
+ NewBuf = <<Buf/binary, Data/binary>>,
+ lager:debug("~p: sending ~B octets back to client as reply", [self(), size(NewBuf)]),
+ ok = gen_tcp:send(ClientPort, NewBuf), % TODO: what about short writes?
+ {reply, {ok, size(NewBuf)}, State#state{clientbuf = <<>>}};
handle_call(Call, _From, State) ->
lager:debug("~p: Unhandled call: ~p~n", [self(), Call]),
{reply, unhandled, State}.
@@ -65,12 +71,6 @@ handle_cast(accept, State = #state{tokname = TokName, sockpath = SocketPath, soc
lager:debug("~p: listening socket closed", [self()]),
{stop, normal, State}
end;
-handle_cast({response, Response}, #state{socket = ClientPort, clientbuf = Buf} = State) ->
- %%lager:debug("~p: received ~B octets from remote", [self(), length(Data)]),
- Data = p11p_rpc:serialise(Response),
- NewBuf = <<Buf/binary, Data/binary>>,
- ok = gen_tcp:send(ClientPort, NewBuf), % TODO: what about short writes?
- {noreply, State#state{clientbuf = <<>>}};
handle_cast(Cast, State) ->
lager:debug("~p: Unhandled cast: ~p~n", [self(), Cast]),
{noreply, State}.