pub(crate) fn build_websocket_pair(
    config: Arc<WebsocketConfig>,
    socket: RawSocket,
) -> Result<(WebsocketSender, WebsocketReceiver)> {
    let remote_addr = url2!(
        "{}#{}",
        addr_to_url(socket.get_ref().peer_addr()?, config.scheme),
        nanoid::nanoid!(),
    );

    // split the sink and stream so we can handle them simultaneously
    use futures::stream::StreamExt;
    let (raw_sink, raw_stream) = socket.split();

    // create our public channel for the WebsocketReceiver
    let (send_pub, recv_pub) = tokio::sync::mpsc::channel(config.max_send_queue);

    // the socket sink task handles sending outgoing data
    let send_sink = task_socket_sink::build(config.clone(), remote_addr.clone(), raw_sink);

    // the dispatch task gathers:
    //  - register responses from the WebsocketSender
    //  - incoming data from the socket stream task
    let send_dispatch =
        task_dispatch_incoming::build(config, remote_addr.clone(), send_pub, send_sink.clone());

    // the socket stream task forwards incoming data to the dispatcher
    // it also responds to pings by directly sending to the sink
    task_socket_stream::build(
        remote_addr.clone(),
        send_sink.clone(),
        send_dispatch.clone(),
        raw_stream,
    );

    // return our send / recv pair
    Ok((
        WebsocketSender::priv_new(send_sink, send_dispatch),
        WebsocketReceiver::priv_new(remote_addr, recv_pub),
    ))
}
/// internal set up the tokio tasks that keep a websocket running
/// and produce the public (WebsocketSender, WebsocketReceiver) pair.
internal set up the tokio tasks that keep a websocket running
and produce the public (WebsocketSender, WebsocketReceiver) pair.
internal set up the tokio tasks that keep a websocket running and produce the public ( WebsocketSender WebsocketReceiver ) pair .
pub(crate) fn build_websocket_pair(
    config: Arc<WebsocketConfig>,
    socket: RawSocket,
) -> Result<(WebsocketSender, WebsocketReceiver)> {
    let remote_addr = url2!(
        "{}#{}",
        addr_to_url(socket.get_ref().peer_addr()?, config.scheme),
        nanoid::nanoid!(),
    );
    // split the sink and stream so we can handle them simultaneously
    use futures::stream::StreamExt;
    let (raw_sink, raw_stream) = socket.split();
    // create our public channel for the WebsocketReceiver
    let (send_pub, recv_pub) = tokio::sync::mpsc::channel(config.max_send_queue);
    // the socket sink task handles sending outgoing data
    let send_sink = task_socket_sink::build(config.clone(), remote_addr.clone(), raw_sink);
    // the dispatch task gathers:
    //  - register responses from the WebsocketSender
    //  - incoming data from the socket stream task
    let send_dispatch =
        task_dispatch_incoming::build(config, remote_addr.clone(), send_pub, send_sink.clone());
    // the socket stream task forwards incoming data to the dispatcher
    // it also responds to pings by directly sending to the sink
    task_socket_stream::build(
        remote_addr.clone(),
        send_sink.clone(),
        send_dispatch.clone(),
        raw_stream,
    );
    // return our send / recv pair
    Ok((
        WebsocketSender::priv_new(send_sink, send_dispatch),
        WebsocketReceiver::priv_new(remote_addr, recv_pub),
    ))
}
pub ( crate ) fn build_websocket_pair ( config : Arc < WebsocketConfig > , socket : RawSocket , ) -> Result < ( WebsocketSender , WebsocketReceiver ) > { let remote_addr = url2 ! ( " " addr_to_url ( socket get_ref ( ) peer_addr ( ) config scheme ) nanoid nanoid ( ) ) ; // split the sink and stream so we can handle them simultaneously use futures :: stream :: StreamExt ; let ( raw_sink , raw_stream ) = socket . split ( ) ; // create our public channel for the WebsocketReceiver let ( send_pub , recv_pub ) = tokio :: sync :: mpsc :: channel ( config . max_send_queue ) ; // the socket sink task handles sending outgoing data let send_sink = task_socket_sink :: build ( config . clone ( ) , remote_addr . clone ( ) , raw_sink ) ; // the dispatch task gathers: //  - register responses from the WebsocketSender //  - incoming data from the socket stream task let send_dispatch = task_dispatch_incoming :: build ( config , remote_addr . clone ( ) , send_pub , send_sink . clone ( ) ) ; // the socket stream task forwards incoming data to the dispatcher // it also responds to pings by directly sending to the sink task_socket_stream :: build ( remote_addr . clone ( ) , send_sink . clone ( ) , send_dispatch . clone ( ) , raw_stream , ) ; // return our send / recv pair Ok ( ( WebsocketSender :: priv_new ( send_sink , send_dispatch ) , WebsocketReceiver :: priv_new ( remote_addr , recv_pub ) , ) ) }
internal set up the tokio tasks that keep a websocket running
and produce the public (WebsocketSender, WebsocketReceiver) pair.
internal set up the tokio tasks that keep a websocket running and produce the public ( WebsocketSender WebsocketReceiver ) pair .
config
Arc<WebsocketConfig>
socket
RawSocket
config
Arc<WebsocketConfig>
socket
RawSocket