fix tcp
This commit is contained in:
parent
1fb4cbfe61
commit
9d91c0ef1e
@ -9,13 +9,14 @@
|
|||||||
-module(tcp_channel).
|
-module(tcp_channel).
|
||||||
-author("licheng5").
|
-author("licheng5").
|
||||||
-include("message.hrl").
|
-include("message.hrl").
|
||||||
|
-behaviour(ranch_protocol).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([pub/3, rpc_call/3, command/3]).
|
-export([pub/3, rpc_call/3, command/3]).
|
||||||
|
|
||||||
-export([start_link/2, stop/2]).
|
-export([start_link/3, stop/2]).
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).
|
-export([init/3, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).
|
||||||
|
|
||||||
-record(state, {
|
-record(state, {
|
||||||
transport,
|
transport,
|
||||||
@ -59,19 +60,15 @@ stop(Pid, Reason) when is_pid(Pid) ->
|
|||||||
%% 逻辑处理方法
|
%% 逻辑处理方法
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
start_link(Transport, Sock) ->
|
start_link(Ref, Transport, Opts) ->
|
||||||
{ok, proc_lib:spawn_link(?MODULE, init, [[Transport, Sock]])}.
|
{ok, proc_lib:spawn_link(?MODULE, init, [Ref, Transport, Opts])}.
|
||||||
|
|
||||||
init([Transport, Sock]) ->
|
init(Ref, Transport, _Opts = []) ->
|
||||||
lager:debug("[sdlan_channel] get a new connection: ~p", [Sock]),
|
{ok, Socket} = ranch:handshake(Ref),
|
||||||
case Transport:wait(Sock) of
|
lager:debug("[sdlan_channel] get a new connection: ~p", [Socket]),
|
||||||
{ok, NewSock} ->
|
Transport:setopts(Socket, [{active, true}]),
|
||||||
Transport:setopts(Sock, [{active, true}]),
|
|
||||||
% erlang:start_timer(?PING_TICKER, self(), ping_ticker),
|
% erlang:start_timer(?PING_TICKER, self(), ping_ticker),
|
||||||
gen_server:enter_loop(?MODULE, [], #state{transport = Transport, socket = NewSock});
|
gen_server:enter_loop(?MODULE, [], #state{transport = Transport, socket = Socket}).
|
||||||
{error, Reason} ->
|
|
||||||
{stop, Reason}
|
|
||||||
end.
|
|
||||||
|
|
||||||
handle_call(_Request, _From, State) ->
|
handle_call(_Request, _From, State) ->
|
||||||
{reply, ok, State}.
|
{reply, ok, State}.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user