Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 24213b0dc5
Fetching contributors…

Cannot retrieve contributors at this time

file 64 lines (53 sloc) 2.13 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
%%%
%%% Copyright 2012 © Nicolas Niclausse
%%%
%%% Author : Nicolas Niclausse <nicolas.nniclausse@niclux.org>
%%% Created: 7 sep 2012 by Nicolas Niclausse <nicolas.nniclausse@niclux.org>
%%%
%%% This program is free software; you can redistribute it and/or modify
%%% it under the terms of the GNU General Public License as published by
%%% the Free Software Foundation; either version 2 of the License, or
%%% (at your option) any later version.
%%%
%%% This program is distributed in the hope that it will be useful,
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%%% GNU General Public License for more details.
%%%
%%% You should have received a copy of the GNU General Public License
%%% along with this program; if not, write to the Free Software
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
%%%
%%% In addition, as a special exception, you have the permission to
%%% link the code of this program with any library released under
%%% the EPL license and distribute linked combinations including
%%% the two.

-module(ts_udp).

-export([ connect/3, send/3, close/1, set_opts/2, protocol_options/1, normalize_incomming_data/2 ]).

-behaviour(gen_ts_transport).

-include("ts_profile.hrl").
-include("ts_config.hrl").

protocol_options(#proto_opts{udp_rcv_size=Rcv, udp_snd_size=Snd}) ->
    [binary,
     {active, once},
     {recbuf, Rcv},
     {sndbuf, Snd}
    ].

%% -> {ok, Socket}
connect(_Host, _Port, Opts) ->
    gen_udp:open(0, Opts).

%% send/3 -> ok | {error, Reason}
send(Socket, Data, [{host, Host}, {port, Port}]) ->
    gen_udp:send(Socket, Host,Port, Data).

close(none) -> ok;
close(Socket) ->
    gen_udp:close(Socket).

% set_opts/2 -> socket()
set_opts(Socket, Opts) ->
    inet:setopts(Socket, Opts),
    Socket.


normalize_incomming_data(Socket, {udp, Socket,_IP,_InPortNo, Data}) ->
    ?DebugF("UDP packet received: size=~p ~n",[size(Data)]),
    {gen_ts_transport, Socket, Data};
normalize_incomming_data(_Socket, X) ->
    X. %%Other, non gen_udp packet.
Something went wrong with that request. Please try again.