pub fn send_data(&mut self, socket: &UdpSocket, config: &Config){
        // create buffer
        let mut buffer = vec![0;self.static_properties.packet_size as usize];
        // for each part of the message
        for i in 0..min(self.static_properties.window_size, self.loaded_parts.len() as u16) {
            // get the part from the cache
            let current_index = Wrapping(self.window_position) + Wrapping(i);
            let part = self.loaded_parts.get_mut(&current_index.0).expect("Part is not within the map");
            // do not send if the timeout time doesn't exceed
            if part.send && Instant::now() - part.last_transition < Duration::from_millis(config.timeout as u64){
                continue;
            }
            config.vlog(&format!(
                "Connection {} will send data packet with seq {} and {}b of data",
                self.static_properties.id,
                part.seq,
                part.content.len()
            ));
            // create the packet for the part
            let data_packet = DataPacket::new(
                Clone::clone(&part.content),
                self.static_properties.id,
                part.seq,
                self.window_position,
            );
            // send the packet
            let response_size = Packet::from(data_packet).to_bin_buff(&mut buffer, self.static_properties.checksum_size as usize);
            socket.send_to(&buffer[..response_size], self.static_properties.socket_addr).expect("Can't send part of data");
            // update attributes of the part
            part.last_transition = Instant::now();
            part.send = true;
            config.vlog("Data packet send");
        }
    }
/// Sends data over `socket` to the receiver of this connection.
Sends data over `socket` to the receiver of this connection.
Sends data over ` socket ` to the receiver of this connection .
pub fn send_data(&mut self, socket: &UdpSocket, config: &Config){
        // create buffer
        let mut buffer = vec![0;self.static_properties.packet_size as usize];
        // for each part of the message
        for i in 0..min(self.static_properties.window_size, self.loaded_parts.len() as u16) {
            // get the part from the cache
            let current_index = Wrapping(self.window_position) + Wrapping(i);
            let part = self.loaded_parts.get_mut(&current_index.0).expect("Part is not within the map");
            // do not send if the timeout time doesn't exceed
            if part.send && Instant::now() - part.last_transition < Duration::from_millis(config.timeout as u64){
                continue;
            }
            config.vlog(&format!(
                "Connection {} will send data packet with seq {} and {}b of data",
                self.static_properties.id,
                part.seq,
                part.content.len()
            ));
            // create the packet for the part
            let data_packet = DataPacket::new(
                Clone::clone(&part.content),
                self.static_properties.id,
                part.seq,
                self.window_position,
            );
            // send the packet
            let response_size = Packet::from(data_packet).to_bin_buff(&mut buffer, self.static_properties.checksum_size as usize);
            socket.send_to(&buffer[..response_size], self.static_properties.socket_addr).expect("Can't send part of data");
            // update attributes of the part
            part.last_transition = Instant::now();
            part.send = true;
            config.vlog("Data packet send");
        }
    }
pub fn send_data ( & mut self , socket : & UdpSocket , config : & Config ) { // create buffer let mut buffer = vec ! [ 0 self static_properties packet_size as usize ] ; // for each part of the message for i in 0 .. min ( self . static_properties . window_size , self . loaded_parts . len ( ) as u16 ) { // get the part from the cache let current_index = Wrapping ( self . window_position ) + Wrapping ( i ) ; let part = self . loaded_parts . get_mut ( & current_index . 0 ) . expect ( " " ) ; // do not send if the timeout time doesn't exceed if part . send && Instant :: now ( ) - part . last_transition < Duration :: from_millis ( config . timeout as u64 ) { continue ; } config . vlog ( & format ! ( " " self static_properties id part seq part content len ( ) ) ) ; // create the packet for the part let data_packet = DataPacket :: new ( Clone :: clone ( & part . content ) , self . static_properties . id , part . seq , self . window_position , ) ; // send the packet let response_size = Packet :: from ( data_packet ) . to_bin_buff ( & mut buffer , self . static_properties . checksum_size as usize ) ; socket . send_to ( & buffer [ .. response_size ] , self . static_properties . socket_addr ) . expect ( " " ) ; // update attributes of the part part . last_transition = Instant :: now ( ) ; part . send = true ; config . vlog ( " " ) ; } }
Sends data over `socket` to the receiver of this connection.
Sends data over ` socket ` to the receiver of this connection .
&mut self
socket
&UdpSocket
config
&Config
&mut self
socket
&UdpSocket
config
&Config