aboutsummaryrefslogtreecommitdiffstats
path: root/mumd/src/network
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-06-11 18:24:56 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-06-11 18:24:56 +0200
commitf072343eb4be3ebb60c2d3736b095ab59c630705 (patch)
tree7f91891fc4f9f9f6ccda619b95ce3e2a2495f507 /mumd/src/network
parent47eb3c8835695ffba375d79efc8a91989003ea2b (diff)
downloadmum-f072343eb4be3ebb60c2d3736b095ab59c630705.tar.gz
doc tcpevent
Diffstat (limited to 'mumd/src/network')
-rw-r--r--mumd/src/network/tcp.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/mumd/src/network/tcp.rs b/mumd/src/network/tcp.rs
index 1c7123f..d7b7c0d 100644
--- a/mumd/src/network/tcp.rs
+++ b/mumd/src/network/tcp.rs
@@ -1,14 +1,12 @@
+use crate::error::{ServerSendError, TcpError};
use crate::network::ConnectionInfo;
+use crate::notifications;
use crate::state::{State, StatePhase};
-use crate::{
- error::{ServerSendError, TcpError},
- notifications,
-};
-use log::*;
use futures_util::select;
use futures_util::stream::{SplitSink, SplitStream, Stream};
use futures_util::{FutureExt, SinkExt, StreamExt};
+use log::*;
use mumble_protocol::control::{msgs, ClientControlCodec, ControlCodec, ControlPacket};
use mumble_protocol::crypt::ClientCryptState;
use mumble_protocol::voice::VoicePacket;
@@ -35,12 +33,14 @@ type TcpReceiver =
pub(crate) type TcpEventCallback = Box<dyn FnOnce(TcpEventData)>;
pub(crate) type TcpEventSubscriber = Box<dyn FnMut(TcpEventData) -> bool>; //the bool indicates if it should be kept or not
+/// Why the TCP was disconnected.
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
pub enum DisconnectedReason {
InvalidTls,
Other,
}
+/// Something a callback can register to. Data is sent via a respective [TcpEventData].
#[derive(Debug, Clone, Copy, Hash, Eq, PartialEq)]
pub enum TcpEvent {
Connected, //fires when the client has connected to a server
@@ -48,6 +48,13 @@ pub enum TcpEvent {
TextMessage, //fires when a text message comes in
}
+/// When a [TcpEvent] occurs, this contains the data for the event.
+///
+/// The events are picked up by a [crate::state::ExecutionContext].
+///
+/// Having two different types might feel a bit confusing. Essentially, a
+/// callback _registers_ to a [TcpEvent] but _takes_ a [TcpEventData] as
+/// parameter.
#[derive(Clone)]
pub enum TcpEventData<'a> {
Connected(Result<&'a msgs::ServerSync, mumlib::Error>),