This commit is contained in:
kingxsp 2018-07-11 06:57:06 +00:00 committed by GitHub
commit 04cd1a16b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 2 deletions

View File

@ -171,18 +171,28 @@ pub enum Message {
}
/// Do websocket handshake and start actor
pub fn start<A, S>(req: &HttpRequest<S>, actor: A) -> Result<HttpResponse, Error>
#[inline]
pub fn create<A, S>(req: &HttpRequest<S>, actor: A, max_size: usize) -> Result<HttpResponse, Error>
where
A: Actor<Context = WebsocketContext<A, S>> + StreamHandler<Message, ProtocolError>,
S: 'static,
{
let mut resp = handshake(req)?;
let stream = WsStream::new(req.payload());
let stream = WsStream::new(req.payload()).max_size(max_size);
let body = WebsocketContext::create(req.clone(), actor, stream);
Ok(resp.body(body))
}
/// Do websocket handshake and start actor
pub fn start<A, S>(req: &HttpRequest<S>, actor: A) -> Result<HttpResponse, Error>
where
A: Actor<Context = WebsocketContext<A, S>> + StreamHandler<Message, ProtocolError>,
S: 'static,
{
create(req, actor, 65_536)
}
/// Prepare `WebSocket` handshake response.
///
/// This function returns handshake `HttpResponse`, ready to send to peer.