Commit f0855c8e3b
Unsigned
Layout: unified · split
src/lib.rs +3 −3
| @@ -308,14 +308,14 @@ impl Drop for Matrix { | ||
| 308 | 308 | fn drop(&mut self) { |
| 309 | 309 | let servers = self.servers.borrow(); |
| 310 | 310 | |
| 311 | // Buffer close callbacks get called after this, so disconnect here so | |
| 312 | // we don't leave all our rooms. | |
| 311 | // Buffer close callbacks get called after this, so drop active | |
| 312 | // connections here so we don't leave all our rooms. | |
| 313 | 313 | // |
| 314 | 314 | // TODO set a flag on the server as well so we don't even try to leave |
| 315 | 315 | // the rooms, once leaving the rooms is implemented when the buffer gets |
| 316 | 316 | // closed. |
| 317 | 317 | for server in servers.values() { |
| 318 | server.disconnect(); | |
| 318 | server.shutdown(); | |
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | drop(servers); |
src/server.rs +25 −6
| @@ -526,9 +526,14 @@ impl Drop for MatrixServer { | ||
| 526 | 526 | let config = &self.config; |
| 527 | 527 | let mut config_borrow = config.borrow_mut(); |
| 528 | 528 | |
| 529 | let mut section = config_borrow | |
| 530 | .search_section_mut("server") | |
| 531 | .expect("Can't get server section"); | |
| 529 | let Some(mut section) = config_borrow.search_section_mut("server") | |
| 530 | else { | |
| 531 | error!( | |
| 532 | "Can't get server section while dropping Matrix server {}", | |
| 533 | self.server_name | |
| 534 | ); | |
| 535 | return; | |
| 536 | }; | |
| 532 | 537 | |
| 533 | 538 | for option_name in &[ |
| 534 | 539 | "autoconnect", |
| @@ -540,9 +545,9 @@ impl Drop for MatrixServer { | ||
| 540 | 545 | ] { |
| 541 | 546 | let option_name = |
| 542 | 547 | &format!("{}.{}", self.server_name, option_name); |
| 543 | section.free_option(option_name).unwrap_or_else(|_| { | |
| 544 | panic!("Can't free option {}", option_name) | |
| 545 | }); | |
| 548 | if section.free_option(option_name).is_err() { | |
| 549 | error!("Can't free option {}", option_name); | |
| 550 | } | |
| 546 | 551 | } |
| 547 | 552 | } |
| 548 | 553 | } |
| @@ -1616,6 +1621,20 @@ impl InnerServer { | ||
| 1616 | 1621 | )); |
| 1617 | 1622 | } |
| 1618 | 1623 | |
| 1624 | pub fn shutdown(&self) { | |
| 1625 | let _runtime_guard = self.servers.runtime().enter(); | |
| 1626 | ||
| 1627 | let mut connection = self.connection.borrow_mut(); | |
| 1628 | connection.take(); | |
| 1629 | drop(connection); | |
| 1630 | ||
| 1631 | self.verification_buffers.borrow_mut().clear(); | |
| 1632 | self.rooms.borrow_mut().clear(); | |
| 1633 | ||
| 1634 | let mut client = self.client.borrow_mut(); | |
| 1635 | client.take(); | |
| 1636 | } | |
| 1637 | ||
| 1619 | 1638 | pub fn get_info_str(&self, details: bool) -> String { |
| 1620 | 1639 | let mut s = String::from(&format!( |
| 1621 | 1640 | "{}{}{} [{}]", |