webrtc
webrtc copied to clipboard
Made sctp PollStream Send + Sync
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?