use super::*;
#[derive(Debug)]
pub struct Ping;
impl Ping {
#[inline]
pub fn new() -> Ping {
Ping
}
}
impl Default for Ping {
#[inline]
fn default() -> Self {
Ping
}
}
impl<IC: InboundContext> SendDesc<IC> for Ping {
fn write_options(
&self,
_msg: &mut dyn OptionInsert,
_socket_addr: &IC::SocketAddr,
_start: Bound<OptionNumber>,
_end: Bound<OptionNumber>,
) -> Result<(), Error> {
Ok(())
}
fn write_payload(
&self,
msg: &mut dyn MessageWrite,
_socket_addr: &IC::SocketAddr,
) -> Result<(), Error> {
msg.set_msg_code(MsgCode::Empty);
msg.set_msg_type(MsgType::Con);
msg.set_msg_token(MsgToken::EMPTY);
Ok(())
}
fn handler(&mut self, context: Result<&IC, Error>) -> Result<ResponseStatus<()>, Error> {
let context = context?;
if context.message().msg_type() == MsgType::Res {
Ok(ResponseStatus::Done(()))
} else {
Err(Error::BadResponse)
}
}
}