some small things
This commit is contained in:
parent
2a2dbd5ff1
commit
18c8ec77dd
2 changed files with 45 additions and 19 deletions
|
|
@ -13,7 +13,8 @@ v-byte-helpers = { git = "https://github.com/RusticMaple/VByteMacros", version =
|
|||
simplelog = "0.12.2"
|
||||
chrono = "0.4.39"
|
||||
log = "0.4.25"
|
||||
rand = "0.8.5"
|
||||
rand = "0.8.5
|
||||
"
|
||||
cfg-if = "1.0.4"
|
||||
hmac = "0.12.1"
|
||||
md-5 = "^0.10.6"
|
||||
|
|
@ -29,13 +30,17 @@ ureq = { version = "3.1.4", features = [ "json" ] }
|
|||
serde = { version = "1.0.228", features = [ "derive" ] }
|
||||
serde_json = "1.0.149"
|
||||
|
||||
[dependencies.sqlx]
|
||||
version = "0.8.6"
|
||||
optional = true
|
||||
|
||||
[dev-dependencies]
|
||||
# criterion = "0.7.0"
|
||||
|
||||
[features]
|
||||
rmc_struct_header = []
|
||||
guest_login = []
|
||||
friends = ["guest_login"]
|
||||
friends = ["guest_login", "dep:sqlx"]
|
||||
big_pid = []
|
||||
v3-8-15 = ["rmc_struct_header"]
|
||||
v4-3-11 = ["v3-8-15"]
|
||||
|
|
|
|||
|
|
@ -1,24 +1,26 @@
|
|||
use std::ops::Deref;
|
||||
use std::sync::Arc;
|
||||
use log::{error, info};
|
||||
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
|
||||
use tokio::sync::mpsc::{channel, Receiver, Sender};
|
||||
use tokio::sync::Notify;
|
||||
use tokio::task;
|
||||
use crate::reggie::{UnitPacketRead, UnitPacketWrite};
|
||||
use log::{error, info};
|
||||
use std::iter::FilterMap;
|
||||
use std::ops::Deref;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::{slice, vec};
|
||||
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt};
|
||||
use tokio::sync::Notify;
|
||||
use tokio::sync::mpsc::{Receiver, Sender, channel};
|
||||
use tokio::task;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SendingBufferConnection(Sender<Vec<u8>>, Arc<Notify>);
|
||||
|
||||
pub struct SplittableBufferConnection(SendingBufferConnection, Receiver<Vec<u8>>);
|
||||
|
||||
impl AsRef<SendingBufferConnection> for SplittableBufferConnection{
|
||||
impl AsRef<SendingBufferConnection> for SplittableBufferConnection {
|
||||
fn as_ref(&self) -> &SendingBufferConnection {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Deref for SplittableBufferConnection{
|
||||
impl Deref for SplittableBufferConnection {
|
||||
type Target = SendingBufferConnection;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
|
|
@ -26,9 +28,7 @@ impl Deref for SplittableBufferConnection{
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
impl<T: Send + Unpin + AsyncWrite + AsyncRead + 'static> From<T> for SplittableBufferConnection{
|
||||
impl<T: Send + Unpin + AsyncWrite + AsyncRead + 'static> From<T> for SplittableBufferConnection {
|
||||
fn from(value: T) -> Self {
|
||||
Self::new(value)
|
||||
}
|
||||
|
|
@ -48,7 +48,6 @@ impl SplittableBufferConnection {
|
|||
let mut recver = inside_recv;
|
||||
let mut stream = stream;
|
||||
|
||||
|
||||
loop {
|
||||
tokio::select! {
|
||||
data = recver.recv() => {
|
||||
|
|
@ -81,7 +80,7 @@ impl SplittableBufferConnection {
|
|||
}
|
||||
}
|
||||
}
|
||||
if let Err(e) = stream.shutdown().await{
|
||||
if let Err(e) = stream.shutdown().await {
|
||||
error!("failed to shut down stream: {}", e);
|
||||
}
|
||||
});
|
||||
|
|
@ -91,11 +90,11 @@ impl SplittableBufferConnection {
|
|||
}
|
||||
}
|
||||
|
||||
impl SendingBufferConnection{
|
||||
pub async fn send(&self, buffer: Vec<u8>) -> Option<()>{
|
||||
impl SendingBufferConnection {
|
||||
pub async fn send(&self, buffer: Vec<u8>) -> Option<()> {
|
||||
self.0.send(buffer).await.ok()
|
||||
}
|
||||
pub fn is_alive(&self) -> bool{
|
||||
pub fn is_alive(&self) -> bool {
|
||||
!self.0.is_closed()
|
||||
}
|
||||
pub async fn disconnect(&self) {
|
||||
|
|
@ -106,12 +105,34 @@ impl SendingBufferConnection{
|
|||
}
|
||||
}
|
||||
|
||||
impl SplittableBufferConnection{
|
||||
pub async fn recv(&mut self) -> Option<Vec<u8>>{
|
||||
impl SplittableBufferConnection {
|
||||
pub async fn recv(&mut self) -> Option<Vec<u8>> {
|
||||
self.1.recv().await
|
||||
}
|
||||
|
||||
pub fn duplicate_sender(&self) -> SendingBufferConnection{
|
||||
pub fn duplicate_sender(&self) -> SendingBufferConnection {
|
||||
self.0.clone()
|
||||
}
|
||||
}
|
||||
|
||||
struct WeakVec<T>(Vec<Weak<T>>);
|
||||
|
||||
impl<T> WeakVec<T> {
|
||||
pub fn new() -> Self {
|
||||
Self(vec![])
|
||||
}
|
||||
|
||||
pub fn from_vec(vec: Vec<Weak<T>>) -> Self {
|
||||
Self(vec)
|
||||
}
|
||||
|
||||
pub fn push(&mut self, val: Weak<T>) {
|
||||
self.0.retain(|v| v.upgrade().is_some());
|
||||
|
||||
self.0.push(val);
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = Arc<T>> {
|
||||
self.0.iter().filter_map(|w| w.upgrade())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue