Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made sctp PollStream Send + Sync #538

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

emcell
Copy link

@emcell emcell commented Mar 1, 2024

I've tried using sctp in a context outside of webrtc and tried the following.

use std::sync::Arc;

use tokio::{io::AsyncReadExt, net::UdpSocket};
use webrtc_sctp::{
    association::{Association, Config},
    chunk::chunk_payload_data::PayloadProtocolIdentifier,
    stream::PollStream,
};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let conn = Arc::new(UdpSocket::bind("0.0.0.0:0").await.unwrap());
    conn.connect("127.0.0.1:132").await.unwrap();

    let config = Config {
        net_conn: conn,
        max_receive_buffer_size: 0,
        max_message_size: 0,
        name: "client".to_owned(),
    };
    let association = Association::client(config).await?;

    let stream = association
        .open_stream(0, PayloadProtocolIdentifier::Binary)
        .await?;
    let stream = PollStream::new(stream);
    tokio::spawn(async move {
        let mut buf = [0u8; 10];
        stream.read(&mut buf).await;
    });

    Ok(())
}

This code wasn't compiling because PollStream is not Send+Sync.

This PR fixes the problem. I think this doesn't cause any Problems.

What do you think?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant