Guest User

Untitled

a guest
Jun 7th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Erlang 1.99 KB | None | 0 0
  1. protocol_func( Parent, Sock, Buffer ) ->                                                                      
  2.    receive                                                                                                    
  3.      {tcp, Sock, Data} ->                                                                                      
  4.        Data1 = <<Buffer/binary, Data/binary>>,                                                                
  5.        <<Length:32/little-signed, Data2/binary>> = Data1,                                                      
  6.        ActualLength = byte_size(Data2),                                                                        
  7.        if                                                                                                      
  8.          ActualLength > Length ->                                                                              
  9.            Parent ! decode_packet( binary:part( Data2, 0, Length - 1 ) ),                                      
  10.            protocol_func( Parent, Sock, binary:part( Data2, Length, ActualLength - Length ) );                
  11.          ActualLength == Length ->                                                                            
  12.            Parent ! decode_packet( Data2 ),                                                                    
  13.            protocol_func( Parent, Sock, <<>> );                                                                
  14.          ActualLength < Length ->                                                                              
  15.            protocol_func( Parent, Sock, Data2 )                                                                
  16.        end;                                                                                                    
  17.      {send_packet_data, From, Data } ->                                                                        
  18.        From ! send( Sock, Data )                                                                              
  19.      end.
Add Comment
Please, Sign In to add comment