use std::time::Duration;
use wireframe::{
app::Envelope,
codec::{CodecError, EofError, LengthDelimitedFrameCodec},
error::WireframeError,
push::PushQueuesBuilder,
serializer::BincodeSerializer,
server::{AppFactory, PrebuiltAppFactory, WireframeServer},
session::ConnectionId,
};
const fn configure_builder<F: Send + 'static>(
builder: PushQueuesBuilder<F>,
) -> PushQueuesBuilder<F> {
builder
.high_capacity(8)
.low_capacity(4)
.rate(Some(64))
.dlq_log_every_n(2)
.dlq_log_interval(Duration::from_secs(5))
}
const fn recalibrate_builder<F: Send + 'static>(
builder: PushQueuesBuilder<F>,
) -> PushQueuesBuilder<F> {
builder.unlimited().rate(Some(16))
}
const CONNECTION_ID: ConnectionId = ConnectionId::new(42);
const CONNECTION_ID_VALUE: u64 = CONNECTION_ID.as_u64();
const fn frame_limit(codec: &LengthDelimitedFrameCodec) -> usize {
codec.max_frame_length()
}
const CLEAN_CLOSE_CODEC: CodecError = CodecError::Eof(EofError::CleanClose);
const CLEAN_CLOSE_ERROR: WireframeError = WireframeError::from_codec(CLEAN_CLOSE_CODEC);
const fn is_clean_close(error: &WireframeError) -> bool { error.is_clean_close() }
const fn wrap_io(error: std::io::Error) -> WireframeError {
WireframeError::from_io(error)
}
const fn without_preamble_timeout<F>(server: WireframeServer<F>) -> WireframeServer<F>
where
F: AppFactory<BincodeSerializer, (), Envelope, LengthDelimitedFrameCodec>,
{
server.disable_preamble_timeout()
}
fn main() {
let _ = (
configure_builder::<Vec<u8>>,
recalibrate_builder::<Vec<u8>>,
CONNECTION_ID_VALUE,
frame_limit,
CLEAN_CLOSE_ERROR.is_clean_close(),
is_clean_close(&CLEAN_CLOSE_ERROR),
wrap_io,
without_preamble_timeout::<
PrebuiltAppFactory<BincodeSerializer, (), Envelope, LengthDelimitedFrameCodec>,
>,
);
}