blob: 1c39f50878a32060e752d06256c0a26aa8762382 [file] [log] [blame]
Allen George8b96bfb2016-11-02 08:01:08 -04001// Licensed to the Apache Software Foundation (ASF) under one
2// or more contributor license agreements. See the NOTICE file
3// distributed with this work for additional information
4// regarding copyright ownership. The ASF licenses this file
5// to you under the Apache License, Version 2.0 (the
6// "License"); you may not use this file except in compliance
7// with the License. You may obtain a copy of the License at
8//
9// http://www.apache.org/licenses/LICENSE-2.0
10//
11// Unless required by applicable law or agreed to in writing,
12// software distributed under the License is distributed on an
13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14// KIND, either express or implied. See the License for the
15// specific language governing permissions and limitations
16// under the License.
17
18//! Types required to send and receive bytes over an I/O channel.
19//!
20//! The core type is the `TTransport` trait, through which a `TProtocol` can
21//! send and receive primitives over the wire. While `TProtocol` instances deal
22//! with primitive types, `TTransport` instances understand only bytes.
23
24use std::cell::RefCell;
25use std::io;
26use std::rc::Rc;
27
28mod buffered;
29mod framed;
30mod passthru;
31mod socket;
32
Allen George8b96bfb2016-11-02 08:01:08 -040033pub mod mem;
34
Flier Lu11870602017-03-20 17:31:34 +080035pub use self::mem::TBufferTransport;
Allen George8b96bfb2016-11-02 08:01:08 -040036pub use self::buffered::{TBufferedTransport, TBufferedTransportFactory};
37pub use self::framed::{TFramedTransport, TFramedTransportFactory};
38pub use self::passthru::TPassThruTransport;
39pub use self::socket::TTcpTransport;
40
41/// Identifies an I/O channel that can be used to send and receive bytes.
42pub trait TTransport: io::Read + io::Write {}
43impl<I: io::Read + io::Write> TTransport for I {}
44
45/// Helper type used by servers to create `TTransport` instances for accepted
46/// client connections.
47pub trait TTransportFactory {
48 /// Create a `TTransport` that wraps an `inner` transport, thus creating
49 /// a transport stack.
50 fn create(&self, inner: Rc<RefCell<Box<TTransport>>>) -> Box<TTransport>;
51}