@@ -32,9 +32,9 @@ callback_mode() ->
32
32
state_functions .
33
33
34
34
35
- common (info ,{tcp ,S ,<<" POINT" , _ : 1 / binary ,P /binary >>},[S ,T ]) ->
35
+ common (info ,{tcp ,S ,<<" POINT: " ,P /binary >>},[S ,T ]) ->
36
36
T :setopts (S ,[{active ,once }]),
37
- K = break_binary_string (P ),
37
+ K = break_binary_string (byte_size ( P ), P ),
38
38
case lfu :point (K ) of
39
39
ok ->
40
40
T :send (S ,<<" OK" >>);
@@ -46,7 +46,7 @@ common(info,{tcp,S,<<"POINT",_:1/binary,P/binary>>},[S,T]) ->
46
46
T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
47
47
end ,
48
48
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 ]) ->
50
50
T :setopts (S ,[{active ,once }]),
51
51
KVL = lists :filtermap (
52
52
fun (KV ) ->
@@ -57,7 +57,7 @@ common(info,{tcp,S,<<"CHEAT",_:1/binary,P/binary>>},[S,T]) ->
57
57
false
58
58
end
59
59
end ,
60
- binary :split (break_binary_string (P ),<<" ;" >>,[global ])),
60
+ binary :split (break_binary_string (byte_size ( P ), P ),<<" ;" >>,[global ])),
61
61
case lfu :cheat (KVL ) of
62
62
ok ->
63
63
T :send (S ,<<" OK" >>);
@@ -69,9 +69,9 @@ common(info,{tcp,S,<<"CHEAT",_:1/binary,P/binary>>},[S,T]) ->
69
69
T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
70
70
end ,
71
71
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 ]) ->
73
73
T :setopts (S ,[{active ,once }]),
74
- K = break_binary_string (P ),
74
+ K = break_binary_string (byte_size ( P ), P ),
75
75
case lfu :count (K ) of
76
76
" type_error" ->
77
77
T :send (S ,<<" {" ," ERROR" ," :" ," TYPE_ERROR" ," }" >>);
@@ -86,7 +86,7 @@ common(info,{tcp,S,<<"COUNT",_:1/binary,P/binary>>},[S,T]) ->
86
86
T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
87
87
end ,
88
88
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 " >> ->
90
90
T :setopts (S ,[{active ,once }]),
91
91
case lfu :state () of
92
92
[O ,Q ] ->
@@ -97,7 +97,7 @@ common(info,{tcp,S,<<"STATE",_/binary>>},[S,T]) ->
97
97
T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
98
98
end ,
99
99
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 " >> ->
101
101
T :setopts (S ,[{active ,once }]),
102
102
case lfu :store () of
103
103
ok ->
@@ -106,7 +106,7 @@ common(info,{tcp,S,<<"STORE",_/binary>>},[S,T]) ->
106
106
T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
107
107
end ,
108
108
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 " >> ->
110
110
T :setopts (S ,[{active ,once }]),
111
111
case lfu :score () of
112
112
ready ->
@@ -115,7 +115,7 @@ common(info,{tcp,S,<<"SCORE",_/binary>>},[S,T]) ->
115
115
T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
116
116
end ,
117
117
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 " >> ->
119
119
T :setopts (S ,[{active ,once }]),
120
120
case catch ets :info (lfu :fetch ()) of
121
121
I when is_list (I ) ->
@@ -136,7 +136,7 @@ common(info,{tcp,S,<<"FETCH",_/binary>>},[S,T]) ->
136
136
T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>)
137
137
end ,
138
138
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 " >> ->
140
140
T :setopts (S ,[{active ,once }]),
141
141
case lfu :clean (sync ) of
142
142
{TID ,R } when is_reference (TID ) andalso is_reference (R ) ->
@@ -159,7 +159,7 @@ common(info,{tcp,S,<<"CLEAN",":","SYNC",_/binary>>},[S,T]) ->
159
159
T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_ERROR" ," }" >>),
160
160
keep_state_and_data
161
161
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 " >> ->
163
163
T :setopts (S ,[{active ,once }]),
164
164
case lfu :clean (async ) of
165
165
TID when is_reference (TID ) ->
@@ -185,7 +185,7 @@ common(info,{tcp,S,<<"CLEAN",":",_P/binary>>},[S,T]) ->
185
185
T :setopts (S ,[{active ,once }]),
186
186
T :send (S ,<<" {" ," ERROR" ," :" ," EXPIRED_REF" ," }" >>),
187
187
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 " >> ->
189
189
T :setopts (S ,[{active ,once }]),
190
190
case lfu :clean (async ) of
191
191
TID when is_reference (TID ) ->
@@ -214,9 +214,13 @@ common(info,{tcp,S,_B},[S,T]) ->
214
214
215
215
delete (state_timeout ,BR ,[S ,T ,#{ref := BR , tid := _T }]) ->
216
216
{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 ]};
217
221
delete (info ,{tcp ,S ,<<" CLEAN" ," :" ,P /binary >>},[S ,T ,#{ref := BR , tid := TID }]) ->
218
222
T :setopts (S ,[{active ,once }]),
219
- case break_binary_string (P ) =:= BR of
223
+ case break_binary_string (byte_size ( P ), P ) =:= BR of
220
224
true ->
221
225
case lfu :clean (list_to_ref (binary_to_list (BR )),TID ) of
222
226
ok ->
@@ -230,21 +234,21 @@ delete(info,{tcp,S,<<"CLEAN",":",P/binary>>},[S,T,#{ref := BR, tid := TID}]) ->
230
234
T :send (S ,<<" {" ," ERROR" ," :" ," UNKNOW_REF" ," }" >>),
231
235
keep_state_and_data
232
236
end ;
233
- delete (info ,{tcp ,_S ,<<" POINT" , _ : 1 / binary ,_P /binary >>},_StateData ) ->
237
+ delete (info ,{tcp ,_S ,<<" POINT: " ,_P /binary >>},_StateData ) ->
234
238
{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 ) ->
236
240
{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 ) ->
238
242
{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 " >> ->
240
244
{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 " >> ->
242
246
{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 " >> ->
244
248
{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 " >> ->
246
250
{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 " >> ->
248
252
{keep_state_and_data ,[postpone ]};
249
253
delete (info ,{tcp ,S ,_B },[S ,T ,_MD ]) ->
250
254
T :setopts (S ,[{active ,once }]),
@@ -272,5 +276,14 @@ pack_list_to_binary([H|T],B) ->
272
276
pack_list_to_binary (T ,<<B /binary ," ," ,H /binary >>)
273
277
end .
274
278
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