More restructuring

This commit is contained in:
Carl Lerche
2017-08-02 14:48:10 -07:00
parent 77681674e2
commit 9f9bf85168
7 changed files with 105 additions and 89 deletions

View File

@@ -1,8 +1,6 @@
use {ConnectionError, Frame, Peer};
use {ConnectionError, Frame};
use HeaderMap;
use frame::{self, StreamId};
use client::Client;
use server::Server;
use proto::*;
@@ -26,34 +24,29 @@ pub struct Connection<T, P, B: IntoBuf = Bytes> {
_phantom: PhantomData<P>,
}
pub fn new<T, P, B>(codec: Codec<T, B::Buf>)
-> Connection<T, P, B>
where T: AsyncRead + AsyncWrite,
P: Peer,
B: IntoBuf,
{
// TODO: Actually configure
let streams = Streams::new(streams::Config {
max_remote_initiated: None,
init_remote_window_sz: DEFAULT_INITIAL_WINDOW_SIZE,
max_local_initiated: None,
init_local_window_sz: DEFAULT_INITIAL_WINDOW_SIZE,
});
Connection {
codec: codec,
ping_pong: PingPong::new(),
settings: Settings::new(),
streams: streams,
_phantom: PhantomData,
}
}
impl<T, P, B> Connection<T, P, B>
where T: AsyncRead + AsyncWrite,
P: Peer,
B: IntoBuf,
{
pub fn new(codec: Codec<T, B::Buf>) -> Connection<T, P, B> {
// TODO: Actually configure
let streams = Streams::new(streams::Config {
max_remote_initiated: None,
init_remote_window_sz: DEFAULT_INITIAL_WINDOW_SIZE,
max_local_initiated: None,
init_local_window_sz: DEFAULT_INITIAL_WINDOW_SIZE,
});
Connection {
codec: codec,
ping_pong: PingPong::new(),
settings: Settings::new(),
streams: streams,
_phantom: PhantomData,
}
}
/// Polls for the next update to a remote flow control window.
pub fn poll_window_update(&mut self) -> Poll<WindowUpdate, ConnectionError> {
self.streams.poll_window_update()
@@ -250,6 +243,7 @@ impl<T, P, B> Connection<T, P, B>
}
}
/*
impl<T, B> Connection<T, Client, B>
where T: AsyncRead + AsyncWrite,
B: IntoBuf,
@@ -296,6 +290,7 @@ impl<T, B> Connection<T, Server, B>
})
}
}
*/
impl<T, P, B> Stream for Connection<T, P, B>
where T: AsyncRead + AsyncWrite,

View File

@@ -13,15 +13,35 @@ use self::ping_pong::PingPong;
use self::settings::Settings;
use self::streams::Streams;
use {StreamId, Peer};
use StreamId;
use error::Reason;
use frame::Frame;
use frame::{self, Frame};
use futures::*;
use bytes::{Buf, IntoBuf};
use tokio_io::{AsyncRead, AsyncWrite};
use tokio_io::codec::length_delimited;
/// Either a Client or a Server
pub trait Peer {
/// Message type sent into the transport
type Send;
/// Message type polled from the transport
type Poll;
fn is_server() -> bool;
#[doc(hidden)]
fn convert_send_message(
id: StreamId,
headers: Self::Send,
end_of_stream: bool) -> frame::Headers;
#[doc(hidden)]
fn convert_poll_message(headers: frame::Headers) -> Self::Poll;
}
pub type PingPayload = [u8; 8];
pub type WindowSize = u32;
@@ -69,7 +89,7 @@ pub fn from_framed_write<T, P, B>(framed_write: FramedWrite<T, B::Buf>)
let codec = FramedRead::new(framed);
connection::new(codec)
Connection::new(codec)
}
impl WindowUpdate {

View File

@@ -14,7 +14,7 @@ use self::send::Send;
use self::state::State;
use self::store::{Store, Entry};
use {frame, Peer, StreamId, ConnectionError};
use {frame, StreamId, ConnectionError};
use proto::*;
use error::Reason::*;
use error::User::*;

View File

@@ -1,4 +1,4 @@
use {frame, Peer, ConnectionError};
use {frame, ConnectionError};
use proto::*;
use super::*;

View File

@@ -1,4 +1,4 @@
use {frame, Peer, ConnectionError};
use {frame, ConnectionError};
use proto::*;
use super::*;