fn send_alert<W5500: Registers>(
        &mut self,
        w5500: &mut W5500,
        level: AlertLevel,
        description: AlertDescription,
        monotonic_secs: u32,
    ) {
        debug!("send_alert {:?} {:?}", level, description);

        let mut try_send_alert = || -> Result<(), AlertDescription> {
            if self.key_schedule.server_traffic_secret_exists() {
                self.send_encrypted_record(
                    w5500,
                    ContentType::Alert,
                    &[level.into(), description.into()],
                )
                .map_err(AlertDescription::map_w5500)?;
            } else {
                #[rustfmt::skip]
                let buf: [u8; 7] = [
                    ContentType::Alert.into(),
                    TlsVersion::V1_2.msb(),
                    TlsVersion::V1_2.lsb(),
                    0, 2, // length
                    level.into(),
                    description.into(),
                ];
                let mut writer: TcpWriter<W5500> = w5500
                    .tcp_writer(self.sn)
                    .map_err(|_| AlertDescription::InternalError)?;
                writer
                    .write_all(&buf)
                    .map_err(AlertDescription::map_w5500)?;
                writer.send().map_err(|_| AlertDescription::InternalError)?;
            }
            Ok(())
        };

        let result: Result<(), AlertDescription> = try_send_alert();

        self.key_schedule.reset();

        if let Err(e1) = result {
            error!("error while sending alert: {:?}", e1);
            self.set_state_send_discon(monotonic_secs);
        } else {
            self.key_schedule.reset();
            self.set_state_with_timeout(State::WaitAlertSendOk, monotonic_secs);
        }
    }
/// Send an alert to the server.
///
/// # References
///
/// * [RFC 8446 Appendix B.2](https://datatracker.ietf.org/doc/html/rfc8446#appendix-B.2)
///
/// ```text
/// struct {
///     AlertLevel level;
///     AlertDescription description;
/// } Alert;
/// ```
Send an alert to the server.
Send an alert to the server .
fn send_alert<W5500: Registers>(
        &mut self,
        w5500: &mut W5500,
        level: AlertLevel,
        description: AlertDescription,
        monotonic_secs: u32,
    ) {
        debug!("send_alert {:?} {:?}", level, description);
        let mut try_send_alert = || -> Result<(), AlertDescription> {
            if self.key_schedule.server_traffic_secret_exists() {
                self.send_encrypted_record(
                    w5500,
                    ContentType::Alert,
                    &[level.into(), description.into()],
                )
                .map_err(AlertDescription::map_w5500)?;
            } else {
                #[rustfmt::skip]
                let buf: [u8; 7] = [
                    ContentType::Alert.into(),
                    TlsVersion::V1_2.msb(),
                    TlsVersion::V1_2.lsb(),
                    0, 2, // length
                    level.into(),
                    description.into(),
                ];
                let mut writer: TcpWriter<W5500> = w5500
                    .tcp_writer(self.sn)
                    .map_err(|_| AlertDescription::InternalError)?;
                writer
                    .write_all(&buf)
                    .map_err(AlertDescription::map_w5500)?;
                writer.send().map_err(|_| AlertDescription::InternalError)?;
            }
            Ok(())
        };
        let result: Result<(), AlertDescription> = try_send_alert();
        self.key_schedule.reset();
        if let Err(e1) = result {
            error!("error while sending alert: {:?}", e1);
            self.set_state_send_discon(monotonic_secs);
        } else {
            self.key_schedule.reset();
            self.set_state_with_timeout(State::WaitAlertSendOk, monotonic_secs);
        }
    }
fn send_alert < W5500 : Registers > ( & mut self , w5500 : & mut W5500 , level : AlertLevel , description : AlertDescription , monotonic_secs : u32 , ) { debug ! ( " " level description ) ; let mut try_send_alert = | | -> Result < ( ) , AlertDescription > { if self . key_schedule . server_traffic_secret_exists ( ) { self . send_encrypted_record ( w5500 , ContentType :: Alert , & [ level . into ( ) , description . into ( ) ] , ) . map_err ( AlertDescription :: map_w5500 ) ? ; } else { # [ rustfmt :: skip ] let buf : [ u8 ; 7 ] = [ ContentType :: Alert . into ( ) , TlsVersion :: V1_2 . msb ( ) , TlsVersion :: V1_2 . lsb ( ) , 0 , 2 , // length level . into ( ) , description . into ( ) , ] ; let mut writer : TcpWriter < W5500 > = w5500 . tcp_writer ( self . sn ) . map_err ( | _ | AlertDescription :: InternalError ) ? ; writer . write_all ( & buf ) . map_err ( AlertDescription :: map_w5500 ) ? ; writer . send ( ) . map_err ( | _ | AlertDescription :: InternalError ) ? ; } Ok ( ( ) ) } ; let result : Result < ( ) , AlertDescription > = try_send_alert ( ) ; self . key_schedule . reset ( ) ; if let Err ( e1 ) = result { error ! ( " " e1 ) ; self . set_state_send_discon ( monotonic_secs ) ; } else { self . key_schedule . reset ( ) ; self . set_state_with_timeout ( State :: WaitAlertSendOk , monotonic_secs ) ; } }
Send an alert to the server.
Send an alert to the server .
&mut self
w5500
&mut W5500
level
AlertLevel
description
AlertDescription
monotonic_secs
u32
&mut self
w5500
&mut W5500
level
AlertLevel
description
AlertDescription
monotonic_secs
u32
references


```text
struct {
AlertLevel level;
AlertDescription description;
} Alert;
```
` ` ` text struct { AlertLevel level ; AlertDescription description ; } Alert ; ` ` `