Skip to content

Commit 44ca51c

Browse files
committed
log info
1 parent 2770521 commit 44ca51c

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/lib.rs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub use dump_logger::dns2socks_set_log_callback;
2525
const MAX_BUFFER_SIZE: usize = 4096;
2626

2727
pub async fn main_entry(config: Config, shutdown_token: tokio_util::sync::CancellationToken) -> Result<()> {
28+
log::info!("Starting DNS2Socks listening on {}...", config.listen_addr);
2829
let user_key = match (&config.username, &config.password) {
2930
(Some(username), password) => Some(UserKey::new(username, password.clone().unwrap_or_default())),
3031
_ => None,
@@ -54,11 +55,20 @@ pub async fn main_entry(config: Config, shutdown_token: tokio_util::sync::Cancel
5455
},
5556
}
5657

58+
log::info!("DNS2Socks stopped");
59+
5760
Ok(())
5861
}
5962

6063
pub(crate) async fn udp_thread(opt: Config, user_key: Option<UserKey>, cache: Cache<Vec<Query>, Message>, timeout: Duration) -> Result<()> {
61-
let listener = Arc::new(UdpSocket::bind(&opt.listen_addr).await?);
64+
let listener = match UdpSocket::bind(&opt.listen_addr).await {
65+
Ok(listener) => listener,
66+
Err(e) => {
67+
log::error!("UDP listener {} error \"{}\"", opt.listen_addr, e);
68+
return Err(e.into());
69+
}
70+
};
71+
let listener = Arc::new(listener);
6272
log::info!("Udp listening on: {}", opt.listen_addr);
6373

6474
loop {
@@ -135,7 +145,13 @@ async fn udp_incoming_handler(
135145
}
136146

137147
pub(crate) async fn tcp_thread(opt: Config, user_key: Option<UserKey>, cache: Cache<Vec<Query>, Message>, timeout: Duration) -> Result<()> {
138-
let listener = TcpListener::bind(&opt.listen_addr).await?;
148+
let listener = match TcpListener::bind(&opt.listen_addr).await {
149+
Ok(listener) => listener,
150+
Err(e) => {
151+
log::error!("TCP listener {} error \"{}\"", opt.listen_addr, e);
152+
return Err(e.into());
153+
}
154+
};
139155
log::info!("TCP listening on: {}", opt.listen_addr);
140156

141157
while let Ok((mut incoming, _)) = listener.accept().await {

0 commit comments

Comments
 (0)