mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-27 17:22:57 +01:00
Reduce copies in ping/pong
This commit is contained in:
parent
b3c5934b00
commit
a66f20a106
@ -82,7 +82,7 @@ async fn ws(
|
||||
|
||||
loop {
|
||||
interval.tick().await;
|
||||
if session2.ping(b"").await.is_err() {
|
||||
if session2.ping(&b""[..]).await.is_err() {
|
||||
break;
|
||||
}
|
||||
|
||||
@ -97,7 +97,7 @@ async fn ws(
|
||||
while let Some(Ok(msg)) = stream.recv().await {
|
||||
match msg {
|
||||
AggregatedMessage::Ping(bytes) => {
|
||||
if session.pong(&bytes).await.is_err() {
|
||||
if session.pong(bytes).await.is_err() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -103,11 +103,11 @@ impl Session {
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
pub async fn ping(&mut self, msg: &[u8]) -> Result<(), Closed> {
|
||||
pub async fn ping(&mut self, msg: impl Into<Bytes>) -> Result<(), Closed> {
|
||||
self.pre_check();
|
||||
if let Some(inner) = self.inner.as_mut() {
|
||||
inner
|
||||
.send(Message::Ping(Bytes::copy_from_slice(msg)))
|
||||
.send(Message::Ping(msg.into()))
|
||||
.await
|
||||
.map_err(|_| Closed)
|
||||
} else {
|
||||
@ -127,11 +127,11 @@ impl Session {
|
||||
/// _ => (),
|
||||
/// }
|
||||
/// # }
|
||||
pub async fn pong(&mut self, msg: &[u8]) -> Result<(), Closed> {
|
||||
pub async fn pong(&mut self, msg: impl Into<Bytes>) -> Result<(), Closed> {
|
||||
self.pre_check();
|
||||
if let Some(inner) = self.inner.as_mut() {
|
||||
inner
|
||||
.send(Message::Pong(Bytes::copy_from_slice(msg)))
|
||||
.send(Message::Pong(msg.into()))
|
||||
.await
|
||||
.map_err(|_| Closed)
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user