@@ -1287,6 +1287,13 @@ asio::awaitable<void> httpserver::http1_send_file(std::shared_ptr<httppeer> peer
12871287 while (readnum < send_file_obj->content_length )
12881288 {
12891289 send_file_obj->content .resize (4096 );
1290+ if (!send_file_obj->fp .get ())
1291+ {
1292+ peer_session->isclose = true ;
1293+ peer->isclose = true ;
1294+ peer->state .keepalive = false ;
1295+ break ;
1296+ }
12901297 unsigned int nread = fread (&send_file_obj->content [0 ], 1 , 4096 , send_file_obj->fp .get ());
12911298 if (nread == 0 )
12921299 {
@@ -1441,6 +1448,13 @@ asio::awaitable<void> httpserver::http1_send_file_range(std::shared_ptr<httppeer
14411448 while (readnum < send_file_obj->content_length )
14421449 {
14431450 send_file_obj->content .resize (4096 );
1451+ if (!send_file_obj->fp .get ())
1452+ {
1453+ peer_session->isclose = true ;
1454+ peer->isclose = true ;
1455+ peer->state .keepalive = false ;
1456+ break ;
1457+ }
14441458 unsigned int nread = fread (&send_file_obj->content [0 ], 1 , 4096 , send_file_obj->fp .get ());
14451459 if (nread == 0 )
14461460 {
@@ -2663,6 +2677,17 @@ bool httpserver::http2_loop_send_sequence(std::shared_ptr<http2_send_data_t> sq_
26632677 // send file
26642678 if (sq_obj->current_num < sq_obj->content_length )
26652679 {
2680+ if (!sq_obj->fp .get ())
2681+ {
2682+ peer->socket_session ->http2_send_enddata (peer->stream_id );
2683+ peer->issend = true ;
2684+ sq_obj->standby_next = true ;
2685+ if (peer->socket_session ->http2_need_wakeup )
2686+ {
2687+ peer->socket_session ->waituphttp2 (this ->io_context );
2688+ }
2689+ return false ;
2690+ }
26662691 per_size = fread (&sq_obj->cache_data [9 ], 1 , vsize_send, sq_obj->fp .get ());
26672692 if (per_size == 0 && vsize_send > 0 )
26682693 {
@@ -3239,6 +3264,7 @@ void httpserver::listeners()
32393264 unsigned long long temp_domain = 0 ;
32403265 SSL_CTX_set_alpn_select_cb (context_.native_handle (), alpn_cb, (void *)temp_domain);
32413266
3267+ unsigned int error_count = 0 ;
32423268 for (;;)
32433269 {
32443270 try
@@ -3254,17 +3280,30 @@ void httpserver::listeners()
32543280 if (ec_error)
32553281 {
32563282 std::unique_lock<std::mutex> lock (log_mutex);
3257- error_loglist.emplace_back (" https accept ec_error " );
3283+ error_loglist.emplace_back (" https accept ec_error\n " );
32583284 lock.unlock ();
3259- std::this_thread::sleep_for (std::chrono::nanoseconds (200 ));
3285+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
3286+ error_count++;
3287+ if (error_count > 128 )
3288+ {
3289+ isstop = true ;
3290+ }
32603291 continue ;
32613292 }
3293+ total_http2_count++;
3294+ // The IP should be available now
3295+ peer_session->getremoteip ();
3296+ peer_session->getremoteport ();
3297+
32623298#ifndef BENCHMARK
32633299 std::unique_lock<std::mutex> lock_sock (socket_session_lists_mutex);
32643300 socket_session_lists.push_back (peer_session);
32653301 lock_sock.unlock ();
32663302#endif
3267- total_http2_count++;
3303+
3304+
3305+
3306+
32683307 co_spawn (this ->io_context , sslhandshake (peer_session), asio::detached);
32693308 if (isstop)
32703309 {
@@ -3275,7 +3314,7 @@ void httpserver::listeners()
32753314 catch (...)
32763315 {
32773316 std::unique_lock<std::mutex> lock (log_mutex);
3278- error_loglist.emplace_back (" https accept ec_error " );
3317+ error_loglist.emplace_back (" https accept catch \n " );
32793318 lock.unlock ();
32803319 }
32813320 if (isstop)
@@ -3316,6 +3355,7 @@ void httpserver::listener()
33163355 exit (1 );
33173356 }
33183357 DEBUG_LOG (" http accept" );
3358+ unsigned int error_count = 0 ;
33193359 for (;;)
33203360 {
33213361 try
@@ -3331,17 +3371,27 @@ void httpserver::listener()
33313371 if (ec)
33323372 {
33333373 std::unique_lock<std::mutex> lock (log_mutex);
3334- error_loglist.emplace_back (" http accept ec_error " );
3374+ error_loglist.emplace_back (" http accept ec_error\n " );
33353375 lock.unlock ();
3336- std::this_thread::sleep_for (std::chrono::nanoseconds (200 ));
3376+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
3377+ error_count++;
3378+ if (error_count > 128 )
3379+ {
3380+ isstop = true ;
3381+ }
33373382 continue ;
33383383 }
3384+ total_http1_count++;
3385+ // The IP should be available now
3386+ peer_session->getremoteip ();
3387+ peer_session->getremoteport ();
3388+
33393389#ifndef BENCHMARK
33403390 std::unique_lock<std::mutex> lock_sock (socket_session_lists_mutex);
33413391 socket_session_lists.push_back (peer_session);
33423392 lock_sock.unlock ();
33433393#endif
3344- total_http1_count++;
3394+
33453395 co_spawn (this ->io_context , clientpeerfun (peer_session, false ), asio::detached);
33463396 if (isstop)
33473397 {
@@ -3352,7 +3402,7 @@ void httpserver::listener()
33523402 catch (...)
33533403 {
33543404 std::unique_lock<std::mutex> lock (log_mutex);
3355- error_loglist.emplace_back (" http accept ec_error " );
3405+ error_loglist.emplace_back (" http accept catch \n " );
33563406 lock.unlock ();
33573407 }
33583408 if (isstop)
0 commit comments