1
#![doc(html_logo_url = "https://raw.githubusercontent.com/sevki/jetstream/main/logo/JetStream.png")]
2
#![doc(
3
    html_favicon_url = "https://raw.githubusercontent.com/sevki/jetstream/main/logo/JetStream.png"
4
)]
5
//! # JetStream Server
6
//! ## Feature Flags
7
//! - `proxy` - Enables the proxy server
8
//! - `quic` - Enables the QUIC server
9
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
10
// Copyright (c) 2024, Sevki <s@sevki.io>
11
// Use of this source code is governed by a BSD-style license that can be
12
// found in the LICENSE file.
13
#[cfg(feature = "proxy")]
14
pub mod proxy;
15
#[cfg(feature = "quic")]
16
pub mod quic;
17

            
18
pub mod service;
19

            
20
use {
21
    std::fmt::Debug,
22
    tokio::io::{AsyncRead, AsyncWrite},
23
};
24

            
25
#[cfg(feature = "vsock")]
26
use tokio_vsock::{VsockAddr, VsockListener};
27

            
28
#[async_trait::async_trait]
29
pub trait ListenerStream: Send + Sync + Debug + 'static {
30
    type Stream: AsyncRead + AsyncWrite + Unpin + Send + Sync;
31
    type Addr: std::fmt::Debug;
32
    async fn accept(&mut self) -> std::io::Result<(Self::Stream, Self::Addr)>;
33
}
34

            
35
#[async_trait::async_trait]
36
impl ListenerStream for tokio::net::UnixListener {
37
    type Stream = tokio::net::UnixStream;
38
    type Addr = tokio::net::unix::SocketAddr;
39
    async fn accept(&mut self) -> std::io::Result<(Self::Stream, Self::Addr)> {
40
        tokio::net::UnixListener::accept(self).await
41
    }
42
}
43

            
44
#[cfg(feature = "vsock")]
45
#[async_trait::async_trait]
46
impl ListenerStream for VsockListener {
47
    type Stream = tokio_vsock::VsockStream;
48
    type Addr = VsockAddr;
49
    async fn accept(&mut self) -> std::io::Result<(Self::Stream, Self::Addr)> {
50
        VsockListener::accept(self).await
51
    }
52
}