David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 1 | -module(thrift_transport). |
| 2 | |
David Reiss | 3b9c342 | 2008-06-11 00:59:19 +0000 | [diff] [blame] | 3 | -export([behaviour_info/1]). |
David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 4 | |
David Reiss | 3b9c342 | 2008-06-11 00:59:19 +0000 | [diff] [blame] | 5 | -export([new/2, |
David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 6 | write/2, |
David Reiss | 90b4083 | 2008-06-10 22:58:52 +0000 | [diff] [blame] | 7 | read/2, |
David Reiss | c11734e | 2008-06-11 00:59:48 +0000 | [diff] [blame] | 8 | flush/1, |
| 9 | close/1 |
David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 10 | ]). |
| 11 | |
| 12 | behaviour_info(callbacks) -> |
David Reiss | 3b9c342 | 2008-06-11 00:59:19 +0000 | [diff] [blame] | 13 | [{read, 2}, |
| 14 | {write, 2}, |
David Reiss | c11734e | 2008-06-11 00:59:48 +0000 | [diff] [blame] | 15 | {flush, 1}, |
| 16 | {close, 1} |
David Reiss | 3b9c342 | 2008-06-11 00:59:19 +0000 | [diff] [blame] | 17 | ]. |
David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 18 | |
David Reiss | 80664fe | 2008-06-11 01:00:30 +0000 | [diff] [blame] | 19 | -record(transport, {module, data}). |
David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 20 | |
David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 21 | new(Module, Data) when is_atom(Module) -> |
| 22 | {ok, #transport{module = Module, |
| 23 | data = Data}}. |
| 24 | |
David Reiss | 914ebb4 | 2008-06-11 01:01:48 +0000 | [diff] [blame] | 25 | %% Data :: iolist() |
| 26 | write(Transport, Data) -> |
David Reiss | ac54955 | 2008-06-10 22:56:59 +0000 | [diff] [blame] | 27 | Module = Transport#transport.module, |
| 28 | Module:write(Transport#transport.data, Data). |
| 29 | |
| 30 | read(Transport, Len) when is_integer(Len) -> |
| 31 | Module = Transport#transport.module, |
| 32 | Module:read(Transport#transport.data, Len). |
David Reiss | 90b4083 | 2008-06-10 22:58:52 +0000 | [diff] [blame] | 33 | |
| 34 | flush(#transport{module = Module, data = Data}) -> |
| 35 | Module:flush(Data). |
David Reiss | c11734e | 2008-06-11 00:59:48 +0000 | [diff] [blame] | 36 | |
| 37 | close(#transport{module = Module, data = Data}) -> |
| 38 | Module:close(Data). |