blob: 20c4b5dc3195f4b8a424fd7234b137403e39c8f2 [file] [log] [blame]
Gavin McDonald0b75e1a2010-10-28 02:12:01 +00001%%
2%% Licensed to the Apache Software Foundation (ASF) under one
3%% or more contributor license agreements. See the NOTICE file
4%% distributed with this work for additional information
5%% regarding copyright ownership. The ASF licenses this file
6%% to you under the Apache License, Version 2.0 (the
7%% "License"); you may not use this file except in compliance
8%% with the License. You may obtain a copy of the License at
9%%
10%% http://www.apache.org/licenses/LICENSE-2.0
11%%
12%% Unless required by applicable law or agreed to in writing,
13%% software distributed under the License is distributed on an
14%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15%% KIND, either express or implied. See the License for the
16%% specific language governing permissions and limitations
17%% under the License.
18%%
19
20-module(thrift_transport).
21
22-export([behaviour_info/1]).
23
24-export([new/2,
25 write/2,
26 read/2,
27 flush/1,
28 close/1
29 ]).
30
31behaviour_info(callbacks) ->
32 [{read, 2},
33 {write, 2},
34 {flush, 1},
35 {close, 1}
36 ].
37
38-record(transport, {module, data}).
39
40new(Module, Data) when is_atom(Module) ->
41 {ok, #transport{module = Module,
42 data = Data}}.
43
44%% Data :: iolist()
45write(Transport, Data) ->
46 Module = Transport#transport.module,
47 Module:write(Transport#transport.data, Data).
48
49read(Transport, Len) when is_integer(Len) ->
50 Module = Transport#transport.module,
51 Module:read(Transport#transport.data, Len).
52
53flush(#transport{module = Module, data = Data}) ->
54 Module:flush(Data).
55
56close(#transport{module = Module, data = Data}) ->
57 Module:close(Data).