Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WebServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
codecraft
WebServer
Commits
a9ee87ff
Commit
a9ee87ff
authored
1 year ago
by
codecraft
Browse files
Options
Downloads
Patches
Plain Diff
Add instant graceful shutdown with SIGNIT
parent
ab9873ad
No related branches found
No related tags found
1 merge request
!1
Initial feature merge
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
core/http/src/setup.rs
+15
-12
15 additions, 12 deletions
core/http/src/setup.rs
with
15 additions
and
12 deletions
core/http/src/setup.rs
+
15
−
12
View file @
a9ee87ff
...
...
@@ -2,7 +2,7 @@ use std::{
thread
::
available_parallelism
,
process
::
exit
,
};
use
tokio
::{
net
::
TcpListener
,
signal
::
unix
::{
SignalKind
,
signal
}};
use
tokio
::{
net
::
TcpListener
,
signal
::
unix
::{
SignalKind
,
signal
}
,
runtime
,
select
};
use
crate
::{
handlers
::
handlers
::
handle_connection
,
...
...
@@ -52,18 +52,21 @@ impl<'a> Config {
self
}
pub
async
fn
launch
(
self
)
{
// Set up a signal handler for SIGINT
tokio
::
spawn
(
async
{
let
mut
sigint
=
signal
(
SignalKind
::
interrupt
())
.unwrap
();
sigint
.recv
()
.await
;
println!
(
"Shutting down..."
);
exit
(
0
)
});
let
mut
sigint
=
signal
(
SignalKind
::
interrupt
())
.unwrap
();
loop
{
let
(
socket
,
_
)
=
self
.address
.accept
()
.await
.unwrap
();
let
mountpoints
=
self
.mountpoints
.clone
()
.unwrap
();
tokio
::
spawn
(
async
move
{
handle_connection
(
socket
,
mountpoints
)
.await
;
});
select!
{
_
=
sigint
.recv
()
=>
{
println!
(
"Shutting down..."
);
break
;
}
income
=
self
.address
.accept
()
=>
{
let
income
=
income
.unwrap
();
let
(
socket
,
_
)
=
income
;
let
mountpoints
=
self
.mountpoints
.clone
()
.unwrap
();
tokio
::
spawn
(
async
move
{
handle_connection
(
socket
,
mountpoints
)
.await
;
});
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment