Handle session creation error
This commit is contained in:
parent
7503d6695a
commit
dee375bfac
@ -643,8 +643,15 @@ impl<Message> Host<Message> where Message: Send + Sync + Clone {
|
||||
}
|
||||
}
|
||||
let h = Arc::try_unwrap(h).ok().unwrap().into_inner().unwrap();
|
||||
let mut session = match Session::new(h, &self.info.read().unwrap()) {
|
||||
Ok(s) => s,
|
||||
Err(e) => {
|
||||
warn!("Session creation error: {:?}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let result = sessions.insert_with(move |session_token| {
|
||||
let session = Session::new(h, session_token, &self.info.read().unwrap()).expect("Session creation error");
|
||||
session.set_token(session_token);
|
||||
io.update_registration(session_token).expect("Error updating session registration");
|
||||
self.stats.inc_sessions();
|
||||
Arc::new(Mutex::new(session))
|
||||
|
@ -108,7 +108,7 @@ const PACKET_LAST: u8 = 0x7f;
|
||||
|
||||
impl Session {
|
||||
/// Create a new session out of comepleted handshake. Consumes handshake object.
|
||||
pub fn new(h: Handshake, token: StreamToken, host: &HostInfo) -> Result<Session, UtilError> {
|
||||
pub fn new(h: Handshake, host: &HostInfo) -> Result<Session, UtilError> {
|
||||
let id = h.id.clone();
|
||||
let connection = try!(EncryptedConnection::new(h));
|
||||
let mut session = Session {
|
||||
@ -124,7 +124,6 @@ impl Session {
|
||||
ping_time_ns: 0,
|
||||
pong_time_ns: None,
|
||||
};
|
||||
session.connection.set_token(token);
|
||||
try!(session.write_hello(host));
|
||||
try!(session.send_ping());
|
||||
Ok(session)
|
||||
@ -140,6 +139,11 @@ impl Session {
|
||||
self.had_hello
|
||||
}
|
||||
|
||||
/// Replace socket token
|
||||
pub fn set_token(&mut self, token: StreamToken) {
|
||||
self.connection.set_token(token);
|
||||
}
|
||||
|
||||
/// Readable IO handler. Returns packet data if available.
|
||||
pub fn readable<Message>(&mut self, io: &IoContext<Message>, host: &HostInfo) -> Result<SessionData, UtilError> where Message: Send + Sync + Clone {
|
||||
match try!(self.connection.readable(io)) {
|
||||
|
Loading…
Reference in New Issue
Block a user