Commit 60e0d647d96b3c38fdd76f1583a17f1bb6bcbd14

Authored by totoro
1 parent 095da71b

add shutdown_required management in http server. Since we manage HTTP 1.1 with n…

…o disconnect between request, when we want to restart gracefully the anubis adm "restart(true)", we wait for all tcp, udp server are down. If a web browser keep a connection with the http server, the server will never shutdown until the browser close the browsing window.
So the shutdown_required is emitted by the application core to request to quit. In that case the http server stop to maintain socket and close it after sending last request.
web/CXM_making_a_web_site.anubis
@@ -2695,12 +2695,14 @@ public define Start_Web_Sites_Result @@ -2695,12 +2695,14 @@ public define Start_Web_Sites_Result
2695 with http_server_r = 2695 with http_server_r =
2696 start_http_server(ip_address,http_port, 2696 start_http_server(ip_address,http_port,
2697 map(get_description,web_sites), 2697 map(get_description,web_sites),
2698 - load_denial_of_service_info), 2698 + load_denial_of_service_info,
  2699 + shutdown_required),
2699 with https_server_r = 2700 with https_server_r =
2700 start_https_server(ip_address,https_port, 2701 start_https_server(ip_address,https_port,
2701 ssl_certificate_common_name, 2702 ssl_certificate_common_name,
2702 map(get_description,web_sites), 2703 map(get_description,web_sites),
2703 - load_denial_of_service_info), 2704 + load_denial_of_service_info,
  2705 + shutdown_required),
2704 if http_server_r is ok(http_server) 2706 if http_server_r is ok(http_server)
2705 then 2707 then
2706 ( 2708 (
web/CXM_multihost_http_server.anubis
@@ -3168,12 +3168,17 @@ define One @@ -3168,12 +3168,17 @@ define One
3168 BufferedConnection connection, 3168 BufferedConnection connection,
3169 Bool is_https, 3169 Bool is_https,
3170 DenialOfService dos, 3170 DenialOfService dos,
3171 - SState s 3171 + SState s,
  3172 + (One) -> Bool shutdown_required
3172 ) = 3173 ) =
3173 //t0 <- (UTime)unow; 3174 //t0 <- (UTime)unow;
3174 with start_time = (Int)now, 3175 with start_time = (Int)now,
3175 s.sttm <- start_time; 3176 s.sttm <- start_time;
3176 //println("Request time: " + format_http_date(start_time)); 3177 //println("Request time: " + format_http_date(start_time));
  3178 + if shutdown_required(unique) then
  3179 + println("shutdown required on http_https_handler");
  3180 + unique
  3181 + else
3177 if dos is denial_of_service(mc_v,rld_v,hd_v,ad_v,ld_v,ra_v) then 3182 if dos is denial_of_service(mc_v,rld_v,hd_v,ad_v,ld_v,ra_v) then
3178 if remote_IP_address_and_port(connection.conn) is (ip_addr,port) then 3183 if remote_IP_address_and_port(connection.conn) is (ip_addr,port) then
3179 if read_request_line(connection) is 3184 if read_request_line(connection) is
@@ -3210,7 +3215,7 @@ define One @@ -3210,7 +3215,7 @@ define One
3210 ok(body) then 3215 ok(body) then
3211 www_url_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, body, generate_tt); 3216 www_url_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, body, generate_tt);
3212 //it's HTTP 1.1 keep-alive is default 3217 //it's HTTP 1.1 keep-alive is default
3213 - http_https_handler(sites, connection, is_https, dos, s) 3218 + http_https_handler(sites, connection, is_https, dos, s, shutdown_required)
3214 } 3219 }
3215 //MULTIPART_FORM_DATA 3220 //MULTIPART_FORM_DATA
3216 multipart_form_data then 3221 multipart_form_data then
@@ -3250,7 +3255,7 @@ define One @@ -3250,7 +3255,7 @@ define One
3250 multipart_form_data_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, desc.site_directory + tmp_body_file, generate_tt, s); 3255 multipart_form_data_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, desc.site_directory + tmp_body_file, generate_tt, s);
3251 3256
3252 //it's HTTP 1.1 keep-alive is default 3257 //it's HTTP 1.1 keep-alive is default
3253 - http_https_handler(sites, connection, is_https, dos, s) 3258 + http_https_handler(sites, connection, is_https, dos, s, shutdown_required)
3254 3259
3255 else 3260 else
3256 println("Can't copy data from stream to temporary file "), 3261 println("Can't copy data from stream to temporary file "),
@@ -3264,7 +3269,7 @@ define One @@ -3264,7 +3269,7 @@ define One
3264 multipart_form_data_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, desc.site_directory + tmp_body_file, generate_tt, s); 3269 multipart_form_data_answer(host_name, desc, connection.conn, ip_addr, rqline2, headers, desc.site_directory + tmp_body_file, generate_tt, s);
3265 3270
3266 //it's HTTP 1.1 keep-alive is default 3271 //it's HTTP 1.1 keep-alive is default
3267 - http_https_handler(sites, connection, is_https, dos, s) 3272 + http_https_handler(sites, connection, is_https, dos, s, shutdown_required)
3268 3273
3269 else 3274 else
3270 println("Can't copy data from stream to temporary file ") 3275 println("Can't copy data from stream to temporary file ")
@@ -3300,7 +3305,8 @@ define Server -&gt; ((RWStream) -&gt; One) @@ -3300,7 +3305,8 @@ define Server -&gt; ((RWStream) -&gt; One)
3300 make_http_handler 3305 make_http_handler
3301 ( 3306 (
3302 List(Web_Site_Description) sites, 3307 List(Web_Site_Description) sites,
3303 - DenialOfService dos 3308 + DenialOfService dos,
  3309 + (One) -> Bool shutdown_required
3304 ) = 3310 ) =
3305 (Server server) |-> (RWStream conn) |-> 3311 (Server server) |-> (RWStream conn) |->
3306 if remote_IP_address_and_port(conn) is (addr,_) then 3312 if remote_IP_address_and_port(conn) is (addr,_) then
@@ -3308,31 +3314,33 @@ define Server -&gt; ((RWStream) -&gt; One) @@ -3308,31 +3314,33 @@ define Server -&gt; ((RWStream) -&gt; One)
3308 then print("Rejecting dubious IP address "+ip_addr_to_string(addr)+"\n") 3314 then print("Rejecting dubious IP address "+ip_addr_to_string(addr)+"\n")
3309 else 3315 else
3310 with connection = buffered_connection(tcp(conn), var(constant_byte_array(0, 0)), var(0), var([])), 3316 with connection = buffered_connection(tcp(conn), var(constant_byte_array(0, 0)), var(0), var([])),
3311 - http_https_handler(sites, connection, false, dos, sstate(var(0),var(0))). 3317 + http_https_handler(sites, connection, false, dos, sstate(var(0),var(0)), shutdown_required).
3312 public define One 3318 public define One
3313 http_direct_handler 3319 http_direct_handler
3314 ( 3320 (
3315 List(Web_Site_Description) sites, 3321 List(Web_Site_Description) sites,
3316 RWStream conn, 3322 RWStream conn,
3317 - DenialOfService dos 3323 + DenialOfService dos,
  3324 + (One) -> Bool shutdown_required
3318 ) = 3325 ) =
3319 if remote_IP_address_and_port(conn) is (addr,_) then 3326 if remote_IP_address_and_port(conn) is (addr,_) then
3320 if is_dubious_IP(addr,dos) 3327 if is_dubious_IP(addr,dos)
3321 then print("Rejecting dubious IP address "+ip_addr_to_string(addr)+"\n") 3328 then print("Rejecting dubious IP address "+ip_addr_to_string(addr)+"\n")
3322 else 3329 else
3323 with connection = buffered_connection(tcp(conn), var(constant_byte_array(0, 0)), var(0), var([])), 3330 with connection = buffered_connection(tcp(conn), var(constant_byte_array(0, 0)), var(0), var([])),
3324 - http_https_handler(sites, connection, false, dos, sstate(var(0),var(0))). 3331 + http_https_handler(sites, connection, false, dos, sstate(var(0),var(0)), shutdown_required).
3325 3332
3326 3333
3327 define Server -> (SSL_Connection -> One) 3334 define Server -> (SSL_Connection -> One)
3328 make_https_handler 3335 make_https_handler
3329 ( 3336 (
3330 List(Web_Site_Description) sites, 3337 List(Web_Site_Description) sites,
3331 - DenialOfService dos 3338 + DenialOfService dos,
  3339 + (One) -> Bool shutdown_required
3332 ) = 3340 ) =
3333 (Server server) |-> (SSL_Connection conn) |-> 3341 (Server server) |-> (SSL_Connection conn) |->
3334 with connection = buffered_connection(ssl(conn), var(constant_byte_array(0, 0)), var(0), var([])), 3342 with connection = buffered_connection(ssl(conn), var(constant_byte_array(0, 0)), var(0), var([])),
3335 - http_https_handler(sites, connection, true, dos, sstate(var(0),var(0))). 3343 + http_https_handler(sites, connection, true, dos, sstate(var(0),var(0)), shutdown_required).
3336 3344
3337 3345
3338 3346
@@ -3614,11 +3622,12 @@ public define StartServerResult @@ -3614,11 +3622,12 @@ public define StartServerResult
3614 Word32 ip_address, 3622 Word32 ip_address,
3615 Word32 port, 3623 Word32 port,
3616 List(Web_Site_Description) sites, 3624 List(Web_Site_Description) sites,
3617 - DenialOfService dos 3625 + DenialOfService dos,
  3626 + (One) -> Bool shutdown_required
3618 ) = 3627 ) =
3619 create_directories(sites); 3628 create_directories(sites);
3620 start_http_server(ip_address,port, 3629 start_http_server(ip_address,port,
3621 - make_http_handler(sites, dos), 3630 + make_http_handler(sites, dos, shutdown_required),
3622 0, 3631 0,
3623 dos). 3632 dos).
3624 3633
@@ -3662,11 +3671,12 @@ public define StartServerResult @@ -3662,11 +3671,12 @@ public define StartServerResult
3662 Word32 port, 3671 Word32 port,
3663 String certificate_common_name, // of SSL server certificate 3672 String certificate_common_name, // of SSL server certificate
3664 List(Web_Site_Description) sites, 3673 List(Web_Site_Description) sites,
3665 - DenialOfService dos 3674 + DenialOfService dos,
  3675 + (One) -> Bool shutdown_required
3666 ) = 3676 ) =
3667 create_directories(sites); 3677 create_directories(sites);
3668 start_https_server(ip_address,port,certificate_common_name, 3678 start_https_server(ip_address,port,certificate_common_name,
3669 - make_https_handler(sites, dos), 3679 + make_https_handler(sites, dos, shutdown_required),
3670 0,dos). 3680 0,dos).
3671 3681
3672 3682