Skip to content

Commit

Permalink
Merge b8239f1 into f79bd06
Browse files Browse the repository at this point in the history
  • Loading branch information
lpgauth committed Oct 15, 2019
2 parents f79bd06 + b8239f1 commit bd866b9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ language: erlang
notifications:
email: false
otp_release:
- 21.0.3
- 22.1
- 22.0
- 21.3.8
- 20.3
- 19.3
- 18.3
Expand Down
3 changes: 2 additions & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

{erl_opts, [
debug_info,
{platform_define, "19|^2", 'UDP_HEADER'}
{platform_define, "^18", 'UDP_HEADER_1'},
{platform_define, "^19|^20|^21|^22.0", 'UDP_HEADER_2'}
]}.

{profiles, [
Expand Down
22 changes: 19 additions & 3 deletions src/statsderl_udp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@

-compile(inline).
-compile({inline_size, 512}).
-compile({nowarn_unused_function, [{uint32, 1}]}).

-ignore_xref([
{?MODULE, uint32, 1}
]).

-export([
header/2
Expand All @@ -15,18 +20,29 @@
-spec header(inet:ip_address(), inet:port_number()) ->
iodata().

-ifdef(UDP_HEADER).
-ifdef(UDP_HEADER_1).

header(IP, Port) ->
[?INT16(Port), ip4_to_bytes(IP)].

-else.
-ifdef(UDP_HEADER_2).

header(IP, Port) ->
[?INET_AF_INET, ?INT16(Port) | ip4_to_bytes(IP)].
[?INET_AF_INET, ?INT16(Port), ip4_to_bytes(IP)].

-else.

header(IP, Port) ->
[?INT16(Port) | ip4_to_bytes(IP)].
[?INET_AF_INET, ?INT16(Port), ip4_to_bytes(IP), uint32(0)].

-endif.
-endif.

%% private
ip4_to_bytes({A, B, C, D}) ->
[A band 16#ff, B band 16#ff, C band 16#ff, D band 16#ff].

uint32(X) ->
[((X) bsr 24) band 16#ff, ((X) bsr 16) band 16#ff,
((X) bsr 8) band 16#ff, (X) band 16#ff].

0 comments on commit bd866b9

Please sign in to comment.