mirror of
https://github.com/pezkuwichain/pezkuwi-telemetry.git
synced 2026-06-12 03:01:09 +00:00
use ws_client in shard, too, and make it better at handling core disconnecting
This commit is contained in:
@@ -105,7 +105,7 @@ impl FromStr for FromFeedWebsocket {
|
||||
/// The aggregator can these messages back to a feed connection.
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum ToFeedWebsocket {
|
||||
Bytes(Vec<u8>),
|
||||
Bytes(bytes::Bytes),
|
||||
}
|
||||
|
||||
/// Instances of this are responsible for handling incoming and
|
||||
|
||||
@@ -68,7 +68,7 @@ impl FeedMessageSerializer {
|
||||
|
||||
/// Return the bytes we've serialized so far and prepare a new buffer. If you're
|
||||
/// finished serializing data, prefer [`FeedMessageSerializer::into_finalized`]
|
||||
pub fn finalize(&mut self) -> Option<Vec<u8>> {
|
||||
pub fn finalize(&mut self) -> Option<bytes::Bytes> {
|
||||
if self.buffer.is_empty() {
|
||||
return None;
|
||||
}
|
||||
@@ -77,17 +77,17 @@ impl FeedMessageSerializer {
|
||||
|
||||
let bytes = mem::replace(&mut self.buffer, Vec::with_capacity(BUFCAP));
|
||||
|
||||
Some(bytes)
|
||||
Some(bytes.into())
|
||||
}
|
||||
|
||||
/// Return the bytes that we've serialized so far, consuming the serializer.
|
||||
pub fn into_finalized(mut self) -> Option<Vec<u8>> {
|
||||
pub fn into_finalized(mut self) -> Option<bytes::Bytes> {
|
||||
if self.buffer.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.buffer.push(b']');
|
||||
Some(self.buffer)
|
||||
Some(self.buffer.into())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -254,9 +254,7 @@ where
|
||||
ToFeedWebsocket::Bytes(bytes) => bytes
|
||||
};
|
||||
|
||||
log::debug!("Message to feed: {}", std::str::from_utf8(&bytes).unwrap_or("INVALID UTF8"));
|
||||
|
||||
if let Err(e) = websocket.send(ws::Message::binary(bytes)).await {
|
||||
if let Err(e) = websocket.send(ws::Message::binary(&*bytes)).await {
|
||||
log::warn!("Closing feed websocket due to error: {}", e);
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user