Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  net_quickack.rs

  Sprache: Rust
 

#![warn(rust_2018_idioms)]
#![cfg(all(
    feature = "net",
    any(
        target_os = "linux",
        target_os = "android",
        target_os = "fuchsia",
        target_os = "cygwin",
    )
))]
#![cfg(not(miri))] // No `socket` in miri.

use tokio::io::{AsyncReadExt, AsyncWriteExt};
use tokio::net::TcpListener;
use tokio::net::TcpStream;
use tokio::sync::oneshot;

#[tokio::test]
async fn socket_works_with_quickack() {
    const MESSAGE: &str = "Hello, tokio!";

    let (tx_port, rx_port) = oneshot::channel();

    let server = tokio::spawn(async move {
        let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
        let addr = listener.local_addr().unwrap();

        tx_port.send(addr.port()).unwrap();

        let (mut stream, _) = listener.accept().await.unwrap();
        stream.set_quickack(true).unwrap();
        assert!(stream.quickack().unwrap());

        stream.write_all(MESSAGE.as_bytes()).await.unwrap();

        let mut buf = vec![0; MESSAGE.len()];
        stream.read_exact(&mut buf).await.unwrap();
        assert_eq!(buf, MESSAGE.as_bytes());

        // There is nothing special about setting quickack to false
        // at this point, we just want to test the `false` case.
        stream.set_quickack(false).unwrap();
        assert!(!stream.quickack().unwrap());

        stream.shutdown().await.unwrap();
    });

    let port = rx_port.await.unwrap();
    let client = tokio::spawn(async move {
        let mut stream = TcpStream::connect(format!("127.0.0.1:{port}"))
            .await
            .unwrap();
        stream.set_quickack(true).unwrap();
        assert!(stream.quickack().unwrap());

        let mut buf = vec![0; MESSAGE.len()];
        stream.read_exact(&mut buf).await.unwrap();
        assert_eq!(buf, MESSAGE.as_bytes());

        stream.write_all(MESSAGE.as_bytes()).await.unwrap();

        // There is nothing special about setting quickack to false
        // at this point, we just want to test the `false` case.
        stream.set_quickack(false).unwrap();
        assert!(!stream.quickack().unwrap());

        stream.shutdown().await.unwrap();
    });

    tokio::try_join!(server, client).unwrap();
}

Messung V0.5 in Prozent
C=92 H=91 G=91

¤ Dauer der Verarbeitung: 0.20 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=277311
#Domains=752002