Skip to content

Commit

Permalink
Add support for OTP-22.1
Browse files Browse the repository at this point in the history
  • Loading branch information
lpgauth committed Oct 7, 2019
1 parent f79bd06 commit 7ea2b08
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ language: erlang
notifications:
email: false
otp_release:
- 21.0.3
- 22.1
- 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
21 changes: 18 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,28 @@
-spec header(inet:ip_address(), inet:port_number()) ->
iodata().

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

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

-else.
-ifdef(UDP_HEADER_2).
header(IP, Port) ->
[?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(X)].

-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 7ea2b08

Please sign in to comment.