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

            
20
pub mod service;
21

            
22
use std::fmt::Debug;
23

            
24
use tokio::io::{AsyncRead, AsyncWrite};
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 Addr = tokio::net::unix::SocketAddr;
38
    type Stream = tokio::net::UnixStream;
39

            
40
    async fn accept(&mut self) -> std::io::Result<(Self::Stream, Self::Addr)> {
41
        tokio::net::UnixListener::accept(self).await
42
    }
43
}
44

            
45
#[cfg(feature = "vsock")]
46
#[async_trait::async_trait]
47
impl ListenerStream for VsockListener {
48
    type Addr = VsockAddr;
49
    type Stream = tokio_vsock::VsockStream;
50

            
51
    async fn accept(&mut self) -> std::io::Result<(Self::Stream, Self::Addr)> {
52
        VsockListener::accept(self).await
53
    }
54
}