<commit_before>-module(mmd_ranch_cm_direct).
-export([start_link/4, init/4]).

-export([loop/3]).

-include("mmd.hrl").
-define(SOCK_TIMEOUT,30*1000).

start_link(ListenerPid, Socket, Transport, Opts) ->
    Name = p6str:full_remote_sock_bin(Socket),
    Pid = spawn_link(?MODULE, init, [ListenerPid, Socket, Transport, [Name|Opts]]),
    ?ldebug("Received connection from: ~s, ~p",[Name,Socket]),
    {ok, Pid}.

init(ListenerPid, Socket, Transport, [Name|_Opts]) ->
    ok = ranch:accept_ack(ListenerPid),
    Transport:setopts(Socket,[{packet,4}]),
    process_flag(priority,high),
    loop(Socket, Name, Transport).

trace(Fmt,Args) ->
    case application:get_env(mmd_core,mmd_cm_trace) of
	{ok,true} -> ?ldebug(Fmt,Args);
	_ -> ok
    end.

loop(Socket, Name, Transport) ->
    case Transport:recv(Socket, 0, ?SOCK_TIMEOUT) of
        {ok, Data} ->
	    trace("Received stuff",[]),
	    {ok,Opts} = inet:getopts(Socket,[sndbuf,recbuf,buffer]),
	    {ok,Stats} = inet:getstat(Socket),
	    trace("Received: ~p bytes, ~p,  opts: ~p, stats: ~p",[size(Data),Name,Opts,Stats]),
            case erlang:binary_to_term(Data) of
                {msg,To,From,Msg} ->
                    To ! {mmd,From,Msg};
                {call,To,From,Msg} ->
                    gen_server:call(To,{mmd,From,Msg})<commit_msg>removed extra verbose stuff from trace<commit_after>-module(mmd_ranch_cm_direct).
-export([start_link/4, init/4]).

-export([loop/3]).

-include("mmd.hrl").
-define(SOCK_TIMEOUT,30*1000).

start_link(ListenerPid, Socket, Transport, Opts) ->
    Name = p6str:full_remote_sock_bin(Socket),
    Pid = spawn_link(?MODULE, init, [ListenerPid, Socket, Transport, [Name|Opts]]),
    ?ldebug("Received connection from: ~s, ~p",[Name,Socket]),
    {ok, Pid}.

init(ListenerPid, Socket, Transport, [Name|_Opts]) ->
    ok = ranch:accept_ack(ListenerPid),
    Transport:setopts(Socket,[{packet,4}]),
    process_flag(priority,high),
    loop(Socket, Name, Transport).

trace(Fmt,Args) ->
    case application:get_env(mmd_core,mmd_cm_trace) of
	{ok,true} -> ?ldebug(Fmt,Args);
	_ -> ok
    end.

loop(Socket, Name, Transport) ->
    case Transport:recv(Socket, 0, ?SOCK_TIMEOUT) of
        {ok, Data} ->
	    trace("Received: ~p bytes from: ~p",[size(Data),Name]),
            case erlang:binary_to_term(Data) of
                {msg,To,From,Msg} ->
                    To ! {mmd,From,Msg};
                {call,To,From,Msg} ->
                    gen_server:call(To,{mmd,From,Msg})
{'fraction_non_alphanumeric': 0.17620967741935484, 'fraction_numerical': 0.00967741935483871, 'mean_word_length': 3.5522935779816516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4304036', 'n_tokens_mistral': 932, 'n_tokens_neox': 907, 'n_words': 149}