Skip to content

Commit

Permalink
If the amount of data transmitted is large, an error will be reported.
Browse files Browse the repository at this point in the history
Client: erl
Patch: TianMaiChengGhostRidder <[email protected]>
  • Loading branch information
TianMaiChengGhostRidder authored and Jens-G committed Aug 30, 2022
1 parent bce985b commit 22f6a8a
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion lib/erl/src/thrift_socket_transport.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,24 @@ when is_integer(Len), Len >= 0 ->
X when X >= Len ->
{Result, Remaining} = split_binary(Binary, Len),
{State#t_socket{buffer = Remaining}, {ok, Result}};
_ -> recv(State, Len)
_ ->
%%recv(State, Len)
loop_recv(State,Len,Len)
end.

loop_recv(State=#t_socket{buffer = Buf},ReadLen,NextReadLen) when NextReadLen =< 0->
{Result,Remaining}=split_binary(Buf,ReadLen),
{State#t_socket{buffer = Remaining},{ok,Result}};

loop_recv(State=#t_socket{socket = Socket,buffer = Buf},ReadLen,NextReadLen) when NextReadLen >0 ->
case gen_tcp:recv(Socket,0,State#t_socket.recv_timeout) of
{error,Error}->
gen_tcp:close(Socket),
{State,{error,Error}};
{ok,Data}->
Binary=iolist_to_binary([Buf,Data]),
Give=min(iolist_size(Binary),ReadLen),
loop_recv(State#t_socket{buffer = Binary},ReadLen,ReadLen-Give)
end.

recv(State = #t_socket{socket = Socket, buffer = Buf}, Len) ->
Expand Down

0 comments on commit 22f6a8a

Please sign in to comment.