diff --git a/src/transport/tcp/tcp_channel.erl b/src/transport/tcp/tcp_channel.erl index 8de4115..5b1b7e1 100644 --- a/src/transport/tcp/tcp_channel.erl +++ b/src/transport/tcp/tcp_channel.erl @@ -93,20 +93,17 @@ handle_call(_Request, _From, State) -> %% 发送消息, 基于pub/sub机制 handle_cast({pub, Topic, Qos, Content}, State = #state{transport = Transport, socket = Socket}) -> Encoded = message_pb:encode_msg(#'Pub'{topic = Topic, qos = Qos, content = Content}), - EncPub = <>, - Transport:send(Socket, <>), + Transport:send(Socket, <>), {noreply, State}; %% 发送Command消息 handle_cast({command, CommandType, Command}, State = #state{transport = Transport, socket = Socket}) -> Encoded = message_pb:encode_msg(#'Command'{command_type = CommandType, command = Command}), - EncCommand = <>, - Transport:send(Socket, <>), + Transport:send(Socket, <>), {noreply, State}; %% 推送消息 -handle_cast({jsonrpc_call, ReceiverPid, Ref, {Method, Params}}, State = #state{transport = Transport, socket = Socket, packet_id = PacketId, inflight = Inflight}) - when is_binary(Method) -> +handle_cast({jsonrpc_call, ReceiverPid, Ref, {Method, Params}}, State = #state{transport = Transport, socket = Socket, packet_id = PacketId, inflight = Inflight}) -> case next_packet_id(PacketId, Inflight) of {ok, NPacketId, NextPacketId} -> Encoded = message_pb:encode_msg(#'JsonRpcRequest'{ @@ -117,10 +114,8 @@ handle_cast({jsonrpc_call, ReceiverPid, Ref, {Method, Params}}, State = #state{t EncRequest = <>, TimerRef = erlang:start_timer(?INFLIGHT_TIMEOUT, self(), {jsonrpc_timeout, NPacketId}), Transport:send(Socket, <>), - {noreply, State#state{ - packet_id = NextPacketId, - inflight = maps:put(NPacketId, {ReceiverPid, Ref, TimerRef}, Inflight) - }}; + + {noreply, State#state{packet_id = NextPacketId, inflight = maps:put(NPacketId, {ReceiverPid, Ref, TimerRef}, Inflight)}}; {error, inflight_full} -> logger:warning("[ws_channel] uuid: ~p, inflight requests exhausted", [State#state.uuid]), {noreply, State} @@ -176,22 +171,18 @@ handle_info({tcp, Socket, <> {stop, State}; handle_info({tcp, Socket, <>}, State = #state{socket = Socket, host_pid = HostPid}) when is_pid(HostPid) -> - CastMessage = message_pb:decode_msg(CastBin, 'Data'), - case CastMessage of - #'Data'{} = Data -> - iot_host:handle(HostPid, {data, Data}) - end, + Data = message_pb:decode_msg(CastBin, 'Data'), + iot_host:handle(HostPid, {data, Data}), {noreply, State}; + handle_info({tcp, Socket, <>}, State = #state{socket = Socket, host_pid = HostPid}) when is_pid(HostPid) -> CastMessage = message_pb:decode_msg(CastBin, 'TaskEventStream'), case CastMessage of - #'TaskEventStream'{task_id = TaskId, type = Type0, stream = Reason0} when Type0 =:= <<"close">>; Type0 =:= [<<"close">>] -> + #'TaskEventStream'{task_id = TaskId, type = Type0, stream = Reason0} when Type0 =:= <<"close">> -> iot_event_stream_observer:stream_close(TaskId, iolist_to_binary(Reason0)); #'TaskEventStream'{task_id = TaskId, type = Type, stream = Stream} -> - TypeBin = iolist_to_binary(Type), - StreamBin = iolist_to_binary(Stream), - logger:debug("[tcp_channel] get task_id: ~p, type: ~ts, stream: ~ts", [TaskId, TypeBin, StreamBin]), - iot_event_stream_observer:stream_data(TaskId, TypeBin, StreamBin) + logger:debug("[tcp_channel] get task_id: ~p, type: ~ts, stream: ~ts", [TaskId, Type, Stream]), + iot_event_stream_observer:stream_data(TaskId, Type, Stream) end, {noreply, State}; handle_info({tcp, Socket, <>}, State = #state{socket = Socket}) ->