1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
//! Unix Domain Socket server for local IPC and reverse proxy communication.
//!
//! Provides both raw Unix socket and HTTP-over-Unix-socket servers.
//! The HTTP variant is ideal for production deployments behind nginx/`HAProxy`
//! where the app communicates via a local socket file instead of TCP.
//!
//! Filesystem and Linux abstract-namespace paths are both supported. A path
//! whose string representation starts with `@` is interpreted as a Linux
//! abstract socket: e.g. `@tako.sock` binds to the abstract name `tako.sock`
//! (NUL-prefixed in the kernel). Abstract sockets do not touch the filesystem,
//! so the stale-socket cleanup and post-shutdown removal are skipped for them.
//!
//! # Examples
//!
//! ## Raw Unix socket (echo server)
//! ```rust,no_run
//! use tako::server_unix::serve_unix;
//! # #[cfg(not(feature = "compio"))]
//! # async fn example() -> std::io::Result<()> {
//! use tokio::io::{AsyncReadExt, AsyncWriteExt};
//! serve_unix("/tmp/tako.sock", |mut stream, _addr| {
//! Box::pin(async move {
//! let mut buf = vec![0u8; 4096];
//! let n = stream.read(&mut buf).await?;
//! stream.write_all(&buf[..n]).await?;
//! Ok(())
//! })
//! }).await?;
//! # Ok(())
//! # }
//! # #[cfg(feature = "compio")]
//! # async fn example() -> std::io::Result<()> {
//! # use compio::io::{AsyncRead, AsyncWriteExt};
//! # serve_unix("/tmp/tako.sock", |mut stream, _peer| Box::pin(async move {
//! # let compio::BufResult(result, mut buf) = stream.read(vec![0u8; 4096]).await;
//! # buf.truncate(result?);
//! # let compio::BufResult(result, _) = stream.write_all(buf).await;
//! # result
//! # })).await
//! # }
//! ```
//!
//! ## HTTP over Unix socket
//! ```rust,no_run
//! # #[cfg(not(feature = "compio"))]
//! # async fn example() -> Result<(), tako::types::BoxError> {
//! use tako::router::Router;
//! use tako::Server;
//!
//! let router = Router::new();
//! let handle = Server::builder()
//! .build()
//! .try_spawn_unix_http("/tmp/tako-http.sock", router)
//! .await?;
//! handle.result().await?;
//! # Ok(())
//! # }
//! # #[cfg(feature = "compio")]
//! # async fn example() -> Result<(), tako::types::BoxError> {
//! # let router = tako::router::Router::new();
//! # let handle = tako::CompioServer::builder()
//! # .build()
//! # .try_spawn_unix_http("/tmp/tako-http.sock", router)
//! # .await?;
//! # handle.result().await?;
//! # Ok(())
//! # }
//! ```
pub
pub
pub use serve_unix_http;
pub use serve_unix_http_with_config;
pub use serve_unix_http_with_shutdown;
pub use serve_unix_http_with_shutdown_and_config;
pub use serve_unix;
pub use serve_unix_with_shutdown;
pub use serve_unix_with_shutdown_and_drain;
pub use serve_unix;
pub use serve_unix_with_shutdown;
pub use serve_unix_with_shutdown_and_drain;
pub use UnixPeerAddr;