blob: 919927d8db826d409c739a9c85c9e389a8935ce6 [file] [log] [blame]
David Reissac549552008-06-10 22:56:59 +00001-module(thrift_transport).
2
David Reiss3b9c3422008-06-11 00:59:19 +00003-export([behaviour_info/1]).
David Reissac549552008-06-10 22:56:59 +00004
David Reiss3b9c3422008-06-11 00:59:19 +00005-export([new/2,
David Reissac549552008-06-10 22:56:59 +00006 write/2,
David Reiss90b40832008-06-10 22:58:52 +00007 read/2,
David Reissc11734e2008-06-11 00:59:48 +00008 flush/1,
9 close/1
David Reissac549552008-06-10 22:56:59 +000010 ]).
11
12behaviour_info(callbacks) ->
David Reiss3b9c3422008-06-11 00:59:19 +000013 [{read, 2},
14 {write, 2},
David Reissc11734e2008-06-11 00:59:48 +000015 {flush, 1},
16 {close, 1}
David Reiss3b9c3422008-06-11 00:59:19 +000017 ].
David Reissac549552008-06-10 22:56:59 +000018
David Reiss80664fe2008-06-11 01:00:30 +000019-record(transport, {module, data}).
David Reissac549552008-06-10 22:56:59 +000020
David Reissac549552008-06-10 22:56:59 +000021new(Module, Data) when is_atom(Module) ->
22 {ok, #transport{module = Module,
23 data = Data}}.
24
25write(Transport, Data) when is_binary(Data) ->
26 Module = Transport#transport.module,
27 Module:write(Transport#transport.data, Data).
28
29read(Transport, Len) when is_integer(Len) ->
30 Module = Transport#transport.module,
31 Module:read(Transport#transport.data, Len).
David Reiss90b40832008-06-10 22:58:52 +000032
33flush(#transport{module = Module, data = Data}) ->
34 Module:flush(Data).
David Reissc11734e2008-06-11 00:59:48 +000035
36close(#transport{module = Module, data = Data}) ->
37 Module:close(Data).