Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse receiving data exception #2

Open
601806081 opened this issue Sep 29, 2020 · 0 comments
Open

parse receiving data exception #2

601806081 opened this issue Sep 29, 2020 · 0 comments

Comments

@601806081
Copy link

ssdb_conn.erl
parse_recv fun,when step =:= ?SSDB_STEP_DATA
the last message can match <<BlockData:Size/binary-unit:8, $\n:8, $\n:8, Res/binary>> or <<BlockData:Size/binary-unit:8, $\n:8, Res/binary>>
If the match <<BlockData:Size/binary-unit:8, $\n:8, Res/binary>>,step state = ?SSDB_STEP_SIZE,but it was the last message.
solution:
parse_recv(#ssdb_conn{step = ?SSDB_STEP_SIZE, data = Data} = State, InData) ->
NewData = <<Data/binary, InData/binary>>,
case binary:split(NewData, <<"\n">>) of
[<<>>, <<>>] -> %% repair
Reply = State#ssdb_conn.reply,
State#ssdb_conn{step = ?SSDB_STEP_FINISH, size = 0, data = <<>>, reply = lists:reverse(Reply)};
[BinSize, BlockData] ->
Size = erlang:binary_to_integer(BinSize),
NewState = State#ssdb_conn{data = BlockData, size = Size, step = ?SSDB_STEP_DATA},
parse_recv(NewState, <<>>); %% parse data
_ ->
%% wait for get size
State#ssdb_conn{data = NewData}
end;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant