2012-03-26 4 views
0

クライアントに送信されるデータを圧縮するためにzlibを使用しようとしています。私は通常、send()を使ってJSONのブロブをクライアントに送信します。ここで仕事を処理する関数です:Erlang:なぜzlibが空のボディを返すのですか?

handle_tcp({data, RawData}, #s1{socket=Socket}=State) -> 
    case decode_and_dispatch(RawData, State#s1.state, Socket) of 
    {ok, NewState, Body} -> 
     lager:debug("Sending to client decompressed ~p",[Body]), 
     send(Socket, Body), 
     {noreply, State#s1{state=NewState}}; 
    {error, _NewState, Msg} -> 
     lager:info("calling client_err_msg with ~p~n",[Msg]), 
     send(Socket, client_err_msg(Msg)), 
     {noreply, State}; 
    Else -> 
     lager:error("Unexpected error: ~p", [Else]), 
     send(Socket, client_err_msg(<<"server rejected the message">>)), 
     {noreply, State} 
    end; 

が私の変化は微妙であり、残念ながら、これは空のリストを返して、それをクライアントに返送する前にボディを圧縮するために句の最初の部分です。誰でも私がここで間違っていることをキャッチすることはできますか?プロセスのクラッシュやエラーログに何かが表示されていません。空のリストだけがクライアントに渡されます。

あなたは、例えば、デフレートの最後の呼び出しへのフラッシュパラメータを「完了」を提供する必要が
handle_tcp({data, RawData}, #s1{socket=Socket}=State) -> 
    case decode_and_dispatch(RawData, State#s1.state, Socket) of 
    {ok, NewState, Body} -> 
     lager:debug("Sending to client decompressed ~p",[Body]), 
     %% compress the payload 
     Z = zlib:open(), 
     zlib:deflateInit(Z), 
     CompressedBody = zlib:deflate(Z,Body), 
     lager:debug("Sending to client compressed ~p",[CompressedBody]), 
     %%zlib:deflateEnd(Z), 
     send(Socket, CompressedBody), 
     %%send(Socket, Body), 
     {noreply, State#s1{state=NewState}}; 
    {error, _NewState, Msg} -> 
     lager:info("calling client_err_msg with ~p~n",[Msg]), 
     send(Socket, client_err_msg(Msg)), 
     {noreply, State}; 
    Else -> 
     lager:error("Unexpected error: ~p", [Else]), 
     send(Socket, client_err_msg(<<"server rejected the message">>)), 
     {noreply, State} 
    end; 

答えて

関連する問題