You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by dl...@apache.org on 2019/08/29 08:33:06 UTC

[dubbo-erlang] branch 0.4.0 updated: fixed client heartbeat response

This is an automated email from the ASF dual-hosted git repository.

dlive pushed a commit to branch 0.4.0
in repository https://gitbox.apache.org/repos/asf/dubbo-erlang.git


The following commit(s) were added to refs/heads/0.4.0 by this push:
     new a62b956  fixed client heartbeat response
a62b956 is described below

commit a62b956848a0369161f794dbae3e9c88d318a67d
Author: DLive <xs...@163.com>
AuthorDate: Thu Aug 29 16:32:23 2019 +0800

    fixed client heartbeat response
---
 src/dubbo_provider_protocol.erl | 30 ++++++++++++++++++++++++++----
 1 file changed, 26 insertions(+), 4 deletions(-)

diff --git a/src/dubbo_provider_protocol.erl b/src/dubbo_provider_protocol.erl
index 5615916..67e61ae 100644
--- a/src/dubbo_provider_protocol.erl
+++ b/src/dubbo_provider_protocol.erl
@@ -163,7 +163,7 @@ process_data(Data, State) ->
     case dubbo_codec:decode_header(Header) of
         {ok, request, RequestInfo} ->
             {ok, Req} = dubbo_codec:decode_request(RequestInfo, RestData),
-            logger:info("get one request mid ~p, is_event ~p", [Req#dubbo_request.mid, Req#dubbo_request.is_event]),
+            logger:info("dubbo process one request mid ~p, is_event ~p", [Req#dubbo_request.mid, Req#dubbo_request.is_event]),
             {ok, State2} = process_request(Req#dubbo_request.is_event, Req, State),
             {ok, State2};
         {ok, response, ResponseInfo} ->
@@ -196,10 +196,32 @@ process_response(false, Response, State) ->
     {ok, State}.
 
 process_request(true, Request, State) ->
-%%    {ok,NewState} = send_heartbeat_msg(Request#dubbo_request.mid,State),
+    {ok,NewState} = send_heartbeat_msg(Request#dubbo_request.mid,false,State),
     logger:debug("process request event ~p", [Request]),
-    {ok, State};
+    {ok, NewState};
 process_request(false, Request, State) ->
     logger:info("process request ~p", [Request]),
     dubbo_provider_worker:process_request(Request, self()),
-    {ok, State}.
\ No newline at end of file
+    {ok, State}.
+
+send_heartbeat_msg(Mid, NeedResponse, State) ->
+    {ok, Bin} = dubbo_heartbeat:generate_request(Mid, NeedResponse),
+    case send_msg(Bin, State#state.socket) of
+        ok ->
+            State;
+        {error, Reason} ->
+            logger:warning("dubbo connection send heartbeat error ~p", [Reason]),
+            State
+    end,
+    {ok, State}.
+
+send_msg(_Msg, undefined) ->
+    {error, closed};
+send_msg(Msg, Socket) ->
+    case gen_tcp:send(Socket, Msg) of
+        ok ->
+            ok;
+        {error, Reason} ->
+            logger:error("protocol socket send error,reason:~p", [Reason]),
+            {error, Reason}
+    end.
\ No newline at end of file