/// Runs a specific instance of the client running at the given socket address.
/// This function takes in a closure who constructs a packet which will be sent out to the client.
Runs a specific instance of the client running at the given socket address.
This function takes in a closure who constructs a packet which will be sent out to the client.
Runs a specific instance of the client running at the given socket address . This function takes in a closure who constructs a packet which will be sent out to the client .
pub fn run_instance<F>(&self, create_packet: F, endpoint: SocketAddr) -> ClientHandle
    where
        F: Fn() -> Packet + Send + 'static,
    {
        let timeout = self.sending_timeout;
        let packets_to_send = self.packets_to_send;
        let handle = thread::spawn(move || {
            let mut socket = Socket::bind(endpoint).unwrap();
            info!("Client {:?} starts to send packets.", endpoint);
            for _ in 0..packets_to_send {
                let packet = create_packet();
                socket.send(packet).unwrap();
                socket.manual_poll(Instant::now());
                let beginning_park = Instant::now();
                let mut timeout_remaining = timeout;
                loop {
                    thread::park_timeout(timeout_remaining);
                    let elapsed = beginning_park.elapsed();
                    if elapsed >= timeout {
                        break;
                    }
                    timeout_remaining = timeout - elapsed;
                }
            }
            info!("Client {:?} sent all messages.", endpoint);
        });
        ClientHandle::new(handle)
    }
pub fn run_instance < F > ( & self , create_packet : F , endpoint : SocketAddr ) -> ClientHandle where F : Fn ( ) -> Packet + Send + ' static , { let timeout = self . sending_timeout ; let packets_to_send = self . packets_to_send ; let handle = thread :: spawn ( move | | { let mut socket = Socket :: bind ( endpoint ) . unwrap ( ) ; info ! ( " " endpoint ) ; for _ in 0 .. packets_to_send { let packet = create_packet ( ) ; socket . send ( packet ) . unwrap ( ) ; socket . manual_poll ( Instant :: now ( ) ) ; let beginning_park = Instant :: now ( ) ; let mut timeout_remaining = timeout ; loop { thread :: park_timeout ( timeout_remaining ) ; let elapsed = beginning_park . elapsed ( ) ; if elapsed >= timeout { break ; } timeout_remaining = timeout - elapsed ; } } info ! ( " " endpoint ) ; } ) ; ClientHandle :: new ( handle ) }
Runs a specific instance of the client running at the given socket address.
Runs a specific instance of the client running at the given socket address .
&self
create_packet
F
endpoint
SocketAddr