blob: 4bbb0a2cf4cbd988a45d37a1bcf4c49a5d630550 [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
David Reiss914ebb42008-06-11 01:01:48 +000025%% Data :: iolist()
26write(Transport, Data) ->
David Reissac549552008-06-10 22:56:59 +000027 Module = Transport#transport.module,
28 Module:write(Transport#transport.data, Data).
29
30read(Transport, Len) when is_integer(Len) ->
31 Module = Transport#transport.module,
32 Module:read(Transport#transport.data, Len).
David Reiss90b40832008-06-10 22:58:52 +000033
34flush(#transport{module = Module, data = Data}) ->
35 Module:flush(Data).
David Reissc11734e2008-06-11 00:59:48 +000036
37close(#transport{module = Module, data = Data}) ->
38 Module:close(Data).