summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-10-30 16:09:55 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-10-30 16:09:55 +0100
commitd837c94dcd08cacee427e59ff11a7e07d6d9e530 (patch)
tree6d7de9355e235bcaa3919b6cb5db096b81bb1901
parent3f56462ef476c70b74efb587f93d94104f7dd8ce (diff)
Go parallel
-rw-r--r--include/config.hrl3
-rw-r--r--src/rose.erl2
-rw-r--r--src/tda.erl25
3 files changed, 13 insertions, 17 deletions
diff --git a/include/config.hrl b/include/config.hrl
index 3cc12a0..3a23cd6 100644
--- a/include/config.hrl
+++ b/include/config.hrl
@@ -1,4 +1,3 @@
--define(TIMEOUT, 300000).
--define(CONNTIMEOUT, 3000).
-define(HOST, "192.168.240.20").
-define(PORT, 33333).
+-define(TIMEOUT, 300000).
diff --git a/src/rose.erl b/src/rose.erl
index 441fa05..ba6d566 100644
--- a/src/rose.erl
+++ b/src/rose.erl
@@ -33,7 +33,7 @@ dispatch({invoke, #'Invoke'{invokeId = Id, opcode = Op, argument = Data}}) ->
ok;
?STATUS ->
io:format("Status: ~p~n", [status:value(Data)]),
- return(Id, Op, status:encode());
+ tda:send(return(Id, Op, status:encode()));
_ ->
error
end;
diff --git a/src/tda.erl b/src/tda.erl
index 3305f0c..7f3eba7 100644
--- a/src/tda.erl
+++ b/src/tda.erl
@@ -1,7 +1,7 @@
-module(tda).
--export([start/0, client/1, stop/0]).
--export([ext/0, co/0, snapshot/1]).
+-export([start/0, client/1, stop/0, decode/1]).
+-export([send/1, ext/0, co/0, snapshot/1]).
-include("config.hrl").
-include("opcodes.hrl").
@@ -19,14 +19,15 @@ ext() ->
co() ->
tdaPid ! rose:invoke(?ESCAPE, escape:lines(co)).
+send(Reply) ->
+ tdaPid ! Reply.
+
snapshot(Device) ->
tdaPid ! rose:invoke(?SNAPSHOT, snapshot:encode(Device)).
client({dial, Host, Port}) ->
io:format("Dial ~p:~p~n", [Host, Port]),
- Conn = gen_tcp:connect(Host, Port,
- [binary, {active, once}, {packet, 2}],
- ?CONNTIMEOUT),
+ Conn = gen_tcp:connect(Host, Port, [binary, {packet, 2}], ?TIMEOUT),
counter:start(),
client(Conn);
@@ -40,18 +41,14 @@ client({error, Reason}) ->
{error, Reason}.
loop(Sock) ->
- inet:setopts(Sock, [{active, once}]),
+ %inet:setopts(Sock, [{active, once}]),
receive
{ok, Reply} ->
- %io:format("Send ~p~n", [Reply]),
- gen_tcp:send(Sock, Reply);
+ io:format("Send ~p~n", [Reply]),
+ spawn(gen_tcp, send, [Sock, Reply]);
{tcp, Sock, Data} ->
- %io:format("Got ~p~n", [Data]),
- case decode(Data) of
- {ok, Reply} -> tdaPid ! {ok, Reply};
- ok -> ok;
- error -> exit(error)
- end;
+ io:format("Recv ~p~n", [Data]),
+ spawn(?MODULE, decode, [Data]);
{tcp_closed, _} ->
io:format("Connection closed~n", []),
exit(closed)