improvements

This commit is contained in:
nora 2022-02-19 18:38:50 +01:00
parent 13deef42fd
commit c5d83fe776
7 changed files with 15 additions and 15 deletions

View file

@ -32,7 +32,6 @@ struct Domain {
asserts: Vec<Assert>,
#[xml(child = "doc")]
doc: Vec<Doc>,
}
#[derive(Debug, XmlRead)]
@ -72,7 +71,6 @@ struct Method {
index: u16,
#[xml(child = "doc")]
doc: Vec<Doc>,
}
#[derive(Debug, XmlRead)]
@ -88,7 +86,6 @@ struct Field {
asserts: Vec<Assert>,
#[xml(child = "doc")]
doc: Vec<Doc>,
}
#[derive(Debug, XmlRead)]
@ -100,7 +97,6 @@ struct Doc {
kind: Option<String>,
}
fn main() {
let content = fs::read_to_string("./amqp0-9-1.xml").unwrap();
@ -115,6 +111,7 @@ fn main() {
}
fn codegen(amqp: &Amqp) {
println!("#![allow(dead_code)]");
println!("// This file has been generated by `amqp_codegen`. Do not edit it manually.\n");
codegen_domain_defs(amqp);
codegen_class_defs(amqp);

View file

@ -1,3 +1,4 @@
#![allow(dead_code)]
// This file has been generated by `amqp_codegen`. Do not edit it manually.
pub type ClassId = u16;

View file

@ -68,6 +68,8 @@ pub fn longstr<W: Write>(value: Longstr, writer: &mut W) -> Result<(), TransErro
Ok(())
}
// this appears to be unused right now, but it could be used in `Basic` things?
#[allow(dead_code)]
pub fn timestamp<W: Write>(value: Timestamp, writer: &mut W) -> Result<(), TransError> {
writer.write_all(&value.to_be_bytes())?;
Ok(())

View file

@ -7,7 +7,6 @@ use std::net::SocketAddr;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpStream;
use tracing::{debug, error, info};
use uuid::Uuid;
fn ensure_conn(condition: bool) -> Result<()> {
if condition {
@ -27,17 +26,15 @@ pub struct Connection {
max_frame_size: usize,
heartbeat_delay: u16,
channel_max: u16,
id: Uuid,
}
impl Connection {
pub fn new(stream: TcpStream, id: Uuid) -> Self {
pub fn new(stream: TcpStream) -> Self {
Self {
stream,
max_frame_size: FRAME_SIZE_MIN_MAX,
heartbeat_delay: HEARTBEAT_DELAY,
channel_max: CHANNEL_MAX,
id,
}
}
@ -196,7 +193,7 @@ impl Connection {
Ok(())
} else {
debug!(?version, expected_version = ?SUPPORTED_PROTOCOL_VERSION, "Version negotiation failed, unsupported version");
Err(ProtocolError::OtherCloseConnection.into())
Err(ProtocolError::CloseNow.into())
}
}
}

View file

@ -1,3 +1,5 @@
#![allow(dead_code)]
use std::io::Error;
pub type StdResult<T, E> = std::result::Result<T, E>;
@ -26,8 +28,10 @@ pub enum ProtocolError {
ConException(#[from] ConException),
#[error("{0}")]
ChannelException(#[from] ChannelException),
#[error("closing connection")]
OtherCloseConnection,
#[error("Connection must be closed")]
CloseNow,
#[error("Graceful connection closing requested")]
GracefulClose,
}
#[derive(Debug, thiserror::Error)]
@ -37,7 +41,7 @@ pub enum ConException {
#[error("503 Command invalid")]
CommandInvalid,
#[error("503 Syntax error | {0:?}")]
/// A method was received but there was a syntax error. The string stores where it occured.
/// A method was received but there was a syntax error. The string stores where it occurred.
SyntaxError(Vec<String>),
#[error("504 Channel error")]
ChannelError,

View file

@ -1,5 +1,3 @@
#![allow(dead_code)]
extern crate core;
mod classes;
@ -29,7 +27,7 @@ pub async fn do_thing_i_guess() -> Result<()> {
info!(local_addr = ?stream.local_addr(), %id, "Accepted new connection");
let span = info_span!("client-connection", %id);
let connection = Connection::new(stream, id);
let connection = Connection::new(stream);
tokio::spawn(connection.start_connection_processing().instrument(span));
}

View file

@ -9,6 +9,7 @@ async fn main() -> Result<()> {
for arg in env::args().skip(1) {
match arg.as_str() {
"--trace" => level = Level::TRACE,
"ignore-this-clippy" => eprintln!("yes please"),
_ => {}
}
}