aboutsummaryrefslogtreecommitdiff
path: root/src/send.rs
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2022-09-01 11:34:53 +0200
committerAlex Auvolat <alex@adnab.me>2022-09-01 11:34:53 +0200
commit745c78618479c4177647e4d7fed97d5fd2d00d4f (patch)
tree0f1d0dfa4bda8c4ae286ec12d726e03a55d7c2ec /src/send.rs
parent7909a95d3c02a738c9a088c1cb8a5d6f70b06046 (diff)
downloadnetapp-745c78618479c4177647e4d7fed97d5fd2d00d4f.tar.gz
netapp-745c78618479c4177647e4d7fed97d5fd2d00d4f.zip
Also encode errorkind in stream
Diffstat (limited to 'src/send.rs')
-rw-r--r--src/send.rs23
1 files changed, 16 insertions, 7 deletions
diff --git a/src/send.rs b/src/send.rs
index f362962..287fe40 100644
--- a/src/send.rs
+++ b/src/send.rs
@@ -4,7 +4,7 @@ use std::sync::Arc;
use std::task::{Context, Poll};
use async_trait::async_trait;
-use bytes::Bytes;
+use bytes::{Bytes, BytesMut, BufMut};
use log::*;
use futures::AsyncWriteExt;
@@ -22,7 +22,11 @@ use crate::stream::*;
// CHUNK_HAS_CONTINUATION when this is not the last chunk of the stream
// ERROR_MARKER if this chunk denotes an error
// (these two flags are exclusive, an error denotes the end of the stream)
-// - [u8; chunk_length] chunk data / error message
+// - [u8; chunk_length], either
+// - if not error: chunk data
+// - if error:
+// - u8: error kind, encoded using error::io_errorkind_to_u8
+// - rest: error message
pub(crate) type RequestID = u32;
pub(crate) type ChunkLength = u16;
@@ -136,12 +140,17 @@ impl DataFrame {
Self::Data(bytes, has_cont)
}
Err(e) => {
- let msg = format!("{}", e);
- let mut msg = Bytes::from(msg.into_bytes());
- if msg.len() > MAX_CHUNK_LENGTH as usize {
- msg = msg.slice(..MAX_CHUNK_LENGTH as usize);
+ let mut buf = BytesMut::new();
+ buf.put_u8(io_errorkind_to_u8(e.kind()));
+
+ let msg = format!("{}", e).into_bytes();
+ if msg.len() > (MAX_CHUNK_LENGTH - 1) as usize {
+ buf.put(&msg[..(MAX_CHUNK_LENGTH - 1) as usize]);
+ } else {
+ buf.put(&msg[..]);
}
- Self::Error(msg)
+
+ Self::Error(buf.freeze())
}
}
}