fn tcp_write(&mut self, sn: Sn, buf: &[u8]) -> Result<u16, Self::Error> {
        debug_assert!(!matches!(
            self.sn_sr(sn)?,
            Ok(SocketStatus::Udp) | Ok(SocketStatus::Init) | Ok(SocketStatus::Macraw)
        ));

        let tx_bytes: u16 = {
            let data_len: u16 = u16::try_from(buf.len()).unwrap_or(u16::MAX);
            let free_size: u16 = self.sn_tx_fsr(sn)?;
            min(data_len, free_size)
        };
        if tx_bytes != 0 {
            let ptr: u16 = self.sn_tx_wr(sn)?;
            self.set_sn_tx_buf(sn, ptr, &buf[..usize::from(tx_bytes)])?;
            self.set_sn_tx_wr(sn, ptr.wrapping_add(tx_bytes))?;
            self.set_sn_cr(sn, SocketCommand::Send)?;
        }
        Ok(tx_bytes)
    }
/// Send data to the remote host, returning the number of bytes written.
///
/// # Panics
///
/// * (debug) The socket must be an [`Established`] TCP socket.
///
/// # Example
///
/// Send a MQTT CONNECT packet.
///
/// ```no_run
/// # use embedded_hal_mock as h;
/// # let mut w5500 = w5500_ll::blocking::vdm::W5500::new(h::spi::Mock::new(&[]), h::pin::Mock::new(&[]));
/// use w5500_hl::{
///     ll::{Registers, Sn, SocketInterrupt},
///     net::{Ipv4Addr, SocketAddrV4},
///     Tcp,
/// };
///
/// const MQTT_SOCKET: Sn = Sn::Sn0;
/// const MQTT_SOURCE_PORT: u16 = 33650;
/// const MQTT_SERVER: SocketAddrV4 = SocketAddrV4::new(Ipv4Addr::new(192, 168, 2, 10), 1883);
///
/// w5500.tcp_connect(MQTT_SOCKET, MQTT_SOURCE_PORT, &MQTT_SERVER)?;
///
/// // ... wait for a CON interrupt
///
/// const CONNECT: [u8; 14] = [
///     0x10, 0x0C, 0x00, 0x04, b'M', b'Q', b'T', b'T', 0x04, 0x02, 0x0E, 0x10, 0x00, 0x00,
/// ];
/// let tx_bytes: u16 = w5500.tcp_write(MQTT_SOCKET, &CONNECT)?;
/// assert_eq!(usize::from(tx_bytes), CONNECT.len());
/// # Ok::<(), w5500_hl::ll::blocking::vdm::Error<_, _>>(())
/// ```
///
/// [`Established`]: w5500_ll::SocketStatus::Established
Send data to the remote host, returning the number of bytes written.
Send data to the remote host returning the number of bytes written .
fn tcp_write(&mut self, sn: Sn, buf: &[u8]) -> Result<u16, Self::Error> {
        debug_assert!(!matches!(
            self.sn_sr(sn)?,
            Ok(SocketStatus::Udp) | Ok(SocketStatus::Init) | Ok(SocketStatus::Macraw)
        ));
        let tx_bytes: u16 = {
            let data_len: u16 = u16::try_from(buf.len()).unwrap_or(u16::MAX);
            let free_size: u16 = self.sn_tx_fsr(sn)?;
            min(data_len, free_size)
        };
        if tx_bytes != 0 {
            let ptr: u16 = self.sn_tx_wr(sn)?;
            self.set_sn_tx_buf(sn, ptr, &buf[..usize::from(tx_bytes)])?;
            self.set_sn_tx_wr(sn, ptr.wrapping_add(tx_bytes))?;
            self.set_sn_cr(sn, SocketCommand::Send)?;
        }
        Ok(tx_bytes)
    }
fn tcp_write ( & mut self , sn : Sn , buf : & [ u8 ] ) -> Result < u16 , Self :: Error > { debug_assert ! ( matches ( self sn_sr ( sn ) Ok ( SocketStatus Udp ) Ok ( SocketStatus Init ) Ok ( SocketStatus Macraw ) ) ) ; let tx_bytes : u16 = { let data_len : u16 = u16 :: try_from ( buf . len ( ) ) . unwrap_or ( u16 :: MAX ) ; let free_size : u16 = self . sn_tx_fsr ( sn ) ? ; min ( data_len , free_size ) } ; if tx_bytes != 0 { let ptr : u16 = self . sn_tx_wr ( sn ) ? ; self . set_sn_tx_buf ( sn , ptr , & buf [ .. usize :: from ( tx_bytes ) ] ) ? ; self . set_sn_tx_wr ( sn , ptr . wrapping_add ( tx_bytes ) ) ? ; self . set_sn_cr ( sn , SocketCommand :: Send ) ? ; } Ok ( tx_bytes ) }
Send data to the remote host, returning the number of bytes written.
Send data to the remote host returning the number of bytes written .
&mut self
sn
Sn
buf
&[u8]
&mut self
sn
Sn
buf
&[u8]
panics
(debug) The socket must be an [`Established`] TCP socket.
( debug ) The socket must be an [ ` Established ` ] TCP socket .
example
Send a MQTT CONNECT packet.


Send a MQTT CONNECT packet .
use embedded_hal_mock as h;
None
let mut w5500 = w5500_ll::blocking::vdm::w5500::new(h::spi::mock::new(&[]), h::pin::mock::new(&[]));
use w5500_hl::{
ll::{Registers, Sn, SocketInterrupt},
net::{Ipv4Addr, SocketAddrV4},
Tcp,
}.



w5500.tcp_connect(MQTT_SOCKET, MQTT_SOURCE_PORT, &MQTT_SERVER)?.

wait for a CON interrupt


use w5500_hl :: { ll :: { Registers Sn SocketInterrupt } net :: { Ipv4Addr SocketAddrV4 } Tcp } . w5500 . tcp_connect ( MQTT_SOCKET MQTT_SOURCE_PORT &MQTT_SERVER ) ? . wait for a CON interrupt
ok::<(), w5500_hl::ll::blocking::vdm::error<_, _>>(())
None