@@ -32,9 +32,9 @@ callback_mode() ->
3232 state_functions .
3333
3434
35- common (info ,{tcp ,S ,<<" POINT" , _ : 1 / binary ,P /binary >>},[S ,T ]) ->
35+ common (info ,{tcp ,S ,<<" POINT: " ,P /binary >>},[S ,T ]) ->
3636 T :setopts (S ,[{active ,once }]),
37- K = break_binary_string (P ),
37+ K = break_binary_string (byte_size ( P ), P ),
3838 case lfu :point (K ) of
3939 ok ->
4040 T :send (S ,<<" OK" >>);
@@ -46,7 +46,7 @@ common(info,{tcp,S,<<"POINT",_:1/binary,P/binary>>},[S,T]) ->
4646 T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
4747 end ,
4848 keep_state_and_data ;
49- common (info ,{tcp ,S ,<<" CHEAT" , _ : 1 / binary ,P /binary >>},[S ,T ]) ->
49+ common (info ,{tcp ,S ,<<" CHEAT: " ,P /binary >>},[S ,T ]) ->
5050 T :setopts (S ,[{active ,once }]),
5151 KVL = lists :filtermap (
5252 fun (KV ) ->
@@ -57,7 +57,7 @@ common(info,{tcp,S,<<"CHEAT",_:1/binary,P/binary>>},[S,T]) ->
5757 false
5858 end
5959 end ,
60- binary :split (break_binary_string (P ),<<" ;" >>,[global ])),
60+ binary :split (break_binary_string (byte_size ( P ), P ),<<" ;" >>,[global ])),
6161 case lfu :cheat (KVL ) of
6262 ok ->
6363 T :send (S ,<<" OK" >>);
@@ -69,9 +69,9 @@ common(info,{tcp,S,<<"CHEAT",_:1/binary,P/binary>>},[S,T]) ->
6969 T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
7070 end ,
7171 keep_state_and_data ;
72- common (info ,{tcp ,S ,<<" COUNT" , _ : 1 / binary ,P /binary >>},[S ,T ]) ->
72+ common (info ,{tcp ,S ,<<" COUNT: " ,P /binary >>},[S ,T ]) ->
7373 T :setopts (S ,[{active ,once }]),
74- K = break_binary_string (P ),
74+ K = break_binary_string (byte_size ( P ), P ),
7575 case lfu :count (K ) of
7676 " type_error" ->
7777 T :send (S ,<<" {" ," ERROR" ," :" ," TYPE_ERROR" ," }" >>);
@@ -86,7 +86,7 @@ common(info,{tcp,S,<<"COUNT",_:1/binary,P/binary>>},[S,T]) ->
8686 T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
8787 end ,
8888 keep_state_and_data ;
89- common (info ,{tcp ,S ,<<" STATE" ,_ /binary >>},[S ,T ]) ->
89+ common (info ,{tcp ,S ,<<" STATE" ,E /binary >>},[S ,T ]) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
9090 T :setopts (S ,[{active ,once }]),
9191 case lfu :state () of
9292 [O ,Q ] ->
@@ -97,7 +97,7 @@ common(info,{tcp,S,<<"STATE",_/binary>>},[S,T]) ->
9797 T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
9898 end ,
9999 keep_state_and_data ;
100- common (info ,{tcp ,S ,<<" STORE" ,_ /binary >>},[S ,T ]) ->
100+ common (info ,{tcp ,S ,<<" STORE" ,E /binary >>},[S ,T ]) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
101101 T :setopts (S ,[{active ,once }]),
102102 case lfu :store () of
103103 ok ->
@@ -106,7 +106,7 @@ common(info,{tcp,S,<<"STORE",_/binary>>},[S,T]) ->
106106 T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
107107 end ,
108108 keep_state_and_data ;
109- common (info ,{tcp ,S ,<<" SCORE" ,_ /binary >>},[S ,T ]) ->
109+ common (info ,{tcp ,S ,<<" SCORE" ,E /binary >>},[S ,T ]) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
110110 T :setopts (S ,[{active ,once }]),
111111 case lfu :score () of
112112 ready ->
@@ -115,7 +115,7 @@ common(info,{tcp,S,<<"SCORE",_/binary>>},[S,T]) ->
115115 T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
116116 end ,
117117 keep_state_and_data ;
118- common (info ,{tcp ,S ,<<" FETCH" ,_ /binary >>},[S ,T ]) ->
118+ common (info ,{tcp ,S ,<<" FETCH" ,E /binary >>},[S ,T ]) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
119119 T :setopts (S ,[{active ,once }]),
120120 case catch ets :info (lfu :fetch ()) of
121121 I when is_list (I ) ->
@@ -136,7 +136,7 @@ common(info,{tcp,S,<<"FETCH",_/binary>>},[S,T]) ->
136136 T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
137137 end ,
138138 keep_state_and_data ;
139- common (info ,{tcp ,S ,<<" CLEAN" ," :" ," SYNC" ,_ /binary >>},[S ,T ]) ->
139+ common (info ,{tcp ,S ,<<" CLEAN" ," :" ," SYNC" ,E /binary >>},[S ,T ]) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
140140 T :setopts (S ,[{active ,once }]),
141141 case lfu :clean (sync ) of
142142 {TID ,R } when is_reference (TID ) andalso is_reference (R ) ->
@@ -159,7 +159,7 @@ common(info,{tcp,S,<<"CLEAN",":","SYNC",_/binary>>},[S,T]) ->
159159 T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>),
160160 keep_state_and_data
161161 end ;
162- common (info ,{tcp ,S ,<<" CLEAN" ," :" ," ASYNC" ,_ /binary >>},[S ,T ]) ->
162+ common (info ,{tcp ,S ,<<" CLEAN" ," :" ," ASYNC" ,E /binary >>},[S ,T ]) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
163163 T :setopts (S ,[{active ,once }]),
164164 case lfu :clean (async ) of
165165 TID when is_reference (TID ) ->
@@ -185,7 +185,7 @@ common(info,{tcp,S,<<"CLEAN",":",_P/binary>>},[S,T]) ->
185185 T :setopts (S ,[{active ,once }]),
186186 T :send (S ,<<" {" ," ERROR" ," :" ," EXPIRED_REF" ," }" >>),
187187 keep_state_and_data ;
188- common (info ,{tcp ,S ,<<" CLEAN" ,_ /binary >>},[S ,T ]) ->
188+ common (info ,{tcp ,S ,<<" CLEAN" ,E /binary >>},[S ,T ]) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
189189 T :setopts (S ,[{active ,once }]),
190190 case lfu :clean (async ) of
191191 TID when is_reference (TID ) ->
@@ -214,9 +214,13 @@ common(info,{tcp,S,_B},[S,T]) ->
214214
215215delete (state_timeout ,BR ,[S ,T ,#{ref := BR , tid := _T }]) ->
216216 {next_state ,common ,[S ,T ]};
217+ delete (info ,{tcp ,_S ,<<" CLEAN:ASYNC" ,E /binary >>},_StateData ) when E =:= <<>> orelse E =:= <<" \r\n " >> orelse E =:= <<" \n " >> orelse E =:= <<" \r " >> ->
218+ {keep_state_and_data ,[postpone ]};
219+ delete (info ,{tcp ,_S ,<<" CLEAN:SYNC" ,E /binary >>},_StateData ) when E =:= <<>> orelse E =:= <<" \r\n " >> orelse E =:= <<" \n " >> orelse E =:= <<" \r " >> ->
220+ {keep_state_and_data ,[postpone ]};
217221delete (info ,{tcp ,S ,<<" CLEAN" ," :" ,P /binary >>},[S ,T ,#{ref := BR , tid := TID }]) ->
218222 T :setopts (S ,[{active ,once }]),
219- case break_binary_string (P ) =:= BR of
223+ case break_binary_string (byte_size ( P ), P ) =:= BR of
220224 true ->
221225 case lfu :clean (list_to_ref (binary_to_list (BR )),TID ) of
222226 ok ->
@@ -230,21 +234,21 @@ delete(info,{tcp,S,<<"CLEAN",":",P/binary>>},[S,T,#{ref := BR, tid := TID}]) ->
230234 T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_REF" ," }" >>),
231235 keep_state_and_data
232236 end ;
233- delete (info ,{tcp ,_S ,<<" POINT" , _ : 1 / binary ,_P /binary >>},_StateData ) ->
237+ delete (info ,{tcp ,_S ,<<" POINT: " ,_P /binary >>},_StateData ) ->
234238 {keep_state_and_data ,[postpone ]};
235- delete (info ,{tcp ,_S ,<<" CHEAT" , _ : 1 / binary ,_P /binary >>},_StateData ) ->
239+ delete (info ,{tcp ,_S ,<<" CHEAT: " ,_P /binary >>},_StateData ) ->
236240 {keep_state_and_data ,[postpone ]};
237- delete (info ,{tcp ,_S ,<<" COUNT" , _ : 1 / binary ,_P /binary >>},_StateData ) ->
241+ delete (info ,{tcp ,_S ,<<" COUNT: " ,_P /binary >>},_StateData ) ->
238242 {keep_state_and_data ,[postpone ]};
239- delete (info ,{tcp ,_S ,<<" STATE" ,_ /binary >>},_StateData ) ->
243+ delete (info ,{tcp ,_S ,<<" STATE" ,E /binary >>},_StateData ) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
240244 {keep_state_and_data ,[postpone ]};
241- delete (info ,{tcp ,_S ,<<" STORE" ,_ /binary >>},_StateData ) ->
245+ delete (info ,{tcp ,_S ,<<" STORE" ,E /binary >>},_StateData ) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
242246 {keep_state_and_data ,[postpone ]};
243- delete (info ,{tcp ,_S ,<<" SCORE" ,_ /binary >>},_StateData ) ->
247+ delete (info ,{tcp ,_S ,<<" SCORE" ,E /binary >>},_StateData ) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
244248 {keep_state_and_data ,[postpone ]};
245- delete (info ,{tcp ,_S ,<<" FETCH" ,_ /binary >>},_StateData ) ->
249+ delete (info ,{tcp ,_S ,<<" FETCH" ,E /binary >>},_StateData ) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
246250 {keep_state_and_data ,[postpone ]};
247- delete (info ,{tcp ,_S ,<<" CLEAN" ,_ /binary >>},_StateData ) ->
251+ delete (info ,{tcp ,_S ,<<" CLEAN" ,E /binary >>},_StateData ) when E =:= <<>> orelse E =:= << " \r\n " >> orelse E =:= << " \n " >> orelse E =:= << " \r " >> ->
248252 {keep_state_and_data ,[postpone ]};
249253delete (info ,{tcp ,S ,_B },[S ,T ,_MD ]) ->
250254 T :setopts (S ,[{active ,once }]),
@@ -272,5 +276,14 @@ pack_list_to_binary([H|T],B) ->
272276 pack_list_to_binary (T ,<<B /binary ," ," ,H /binary >>)
273277 end .
274278
275- break_binary_string (B ) ->
276- hd (binary :split (B ,<<" \r\n " >>,[global ])).
279+ break_binary_string (S ,B ) ->
280+ case B of
281+ <<B1 :(S - 2 )/binary ," \r\n " >> ->
282+ B1 ;
283+ <<B2 :(S - 1 )/binary ," \n " >> ->
284+ B2 ;
285+ <<B3 :(S - 1 )/binary ," \r " >> ->
286+ B3 ;
287+ _ ->
288+ B
289+ end .
0 commit comments