-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Web Socket support for StreamProxy (#3)
* Add Web Socket support for StreamProxy * update Cargo.lock
- Loading branch information
Showing
9 changed files
with
258 additions
and
56 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,35 @@ | ||
use socket2::TcpKeepalive; | ||
use std::time::Duration; | ||
use tokio::net::TcpStream; | ||
|
||
pub mod config; | ||
pub mod metric; | ||
pub mod server; | ||
pub mod signal; | ||
|
||
fn set_nodelay_or_warn(socket: &TcpStream) { | ||
if let Err(e) = socket.set_nodelay(true) { | ||
tracing::warn!("failed to set nodelay: {}", e); | ||
} | ||
} | ||
|
||
fn set_keepalive_or_warn( | ||
tcp: tokio::net::TcpStream, | ||
keepalive_duration: Option<Duration>, | ||
) -> eyre::Result<tokio::net::TcpStream> { | ||
let sock = { | ||
let stream: std::net::TcpStream = tokio::net::TcpStream::into_std(tcp)?; | ||
socket2::Socket::from(stream) | ||
}; | ||
|
||
let ka = keepalive_duration | ||
.into_iter() | ||
.fold(TcpKeepalive::new(), |k, t| k.with_time(t)); | ||
|
||
if let Err(e) = sock.set_tcp_keepalive(&ka) { | ||
tracing::warn!("failed to set keepalive: {}", e); | ||
} | ||
|
||
let stream: std::net::TcpStream = socket2::Socket::into(sock); | ||
Ok(tokio::net::TcpStream::from_std(stream)?) | ||
} |
Oops, something went wrong.