@@ -87,13 +87,13 @@ namespace HttpServer
8787
8888 if (false == range_begin_str.empty () )
8989 {
90- const size_t range_begin = std::stoull (range_begin_str) * range_unit;
90+ const size_t range_begin = std::strtoull (range_begin_str. c_str (), nullptr , 10 ) * range_unit;
9191
9292 if (range_begin < fileSize)
9393 {
9494 if (false == range_end_str.empty () )
9595 {
96- size_t range_end = std::stoull (range_end_str) * range_unit;
96+ size_t range_end = std::strtoull (range_end_str. c_str (), nullptr , 10 ) * range_unit;
9797
9898 if (range_end >= range_begin)
9999 {
@@ -125,7 +125,7 @@ namespace HttpServer
125125 }
126126 else if (false == range_end_str.empty () ) // if range_begin_str empty
127127 {
128- size_t range_end = std::stoull (range_end_str) * range_unit;
128+ size_t range_end = std::strtoull (range_end_str. c_str (), nullptr , 10 ) * range_unit;
129129
130130 const size_t length = range_end < fileSize ? fileSize - range_end : fileSize;
131131
@@ -580,7 +580,7 @@ namespace HttpServer
580580 const std::string host = it_host->second .substr (0 , delimiter);
581581
582582 // Получить номер порта
583- const int port = (std::string::npos != delimiter) ? std::stoi (it_host->second .substr (delimiter + 1 ) ) : 80 ;
583+ const int port = (std::string::npos != delimiter) ? std::strtol (it_host->second .substr (delimiter + 1 ). c_str (), nullptr , 10 ) : 80 ;
584584
585585 // Поиск настроек приложения по имени
586586 ServerApplicationSettings *app_sets = apps_tree.find (host);
@@ -655,7 +655,7 @@ namespace HttpServer
655655
656656 if (incoming_headers.end () != it_len)
657657 {
658- data_length = std::stoull (it_len->second );
658+ data_length = std::strtoull (it_len->second . c_str (), nullptr , 10 );
659659 }
660660
661661 // Если размер запроса не превышает лимит (если лимит был установлен)
@@ -849,12 +849,19 @@ namespace HttpServer
849849
850850 if (settings.end () != it_option)
851851 {
852- threads_max_count = std::stoul (it_option->second );
852+ threads_max_count = std::strtoull (it_option->second . c_str (), nullptr , 10 );
853853 }
854854
855855 if (0 == threads_max_count)
856856 {
857- threads_max_count = System::getProcessorsCount ();
857+ threads_max_count = std::thread::hardware_concurrency ();
858+
859+ if (0 == threads_max_count)
860+ {
861+ threads_max_count = 1 ;
862+ }
863+
864+ threads_max_count *= 2 ;
858865 }
859866
860867 std::function<int (Server *, Socket)> serverThreadRequestProc = std::mem_fn (&Server::threadRequestProc);
@@ -1126,7 +1133,7 @@ namespace HttpServer
11261133
11271134 auto it_request_max_size = app.find (" request_max_size" );
11281135
1129- const size_t request_max_size = app.end () != it_request_max_size ? std::stoull (it_request_max_size->second ) : defaults.request_max_size ;
1136+ const size_t request_max_size = app.end () != it_request_max_size ? std::strtoull (it_request_max_size->second . c_str (), nullptr , 10 ) : defaults.request_max_size ;
11301137
11311138 auto it_module_update = app.find (" server_module_update" );
11321139
@@ -1167,7 +1174,7 @@ namespace HttpServer
11671174
11681175 // Create application settings struct
11691176 ServerApplicationSettings *sets = new ServerApplicationSettings {
1170- std::stoi (it_port->second .c_str () ),
1177+ std::strtol (it_port->second .c_str (), nullptr , 10 ),
11711178 root_dir,
11721179 temp_dir,
11731180 request_max_size,
@@ -1319,7 +1326,7 @@ namespace HttpServer
13191326
13201327 auto it_default_request_max_size = settings.find (" request_max_size" );
13211328
1322- const size_t default_request_max_size = settings.end () != it_default_request_max_size ? std::stoull (it_default_request_max_size->second ) : 0 ;
1329+ const size_t default_request_max_size = settings.end () != it_default_request_max_size ? std::strtoull (it_default_request_max_size->second . c_str (), nullptr , 10 ) : 0 ;
13231330
13241331 ServerApplicationDefaultSettings defaults {
13251332 default_temp_dir,
@@ -1575,13 +1582,13 @@ namespace HttpServer
15751582
15761583 bool Server::init ()
15771584 {
1578- if (0 == Socket::Startup () )
1585+ if (Socket::Startup () && loadConfig () )
15791586 {
15801587 addDataVariant (new DataVariantFormUrlencoded () );
15811588 addDataVariant (new DataVariantMultipartFormData () );
15821589 addDataVariant (new DataVariantTextPlain () );
15831590
1584- return loadConfig () ;
1591+ return true ;
15851592 }
15861593
15871594 return false ;
@@ -1661,45 +1668,6 @@ namespace HttpServer
16611668 }
16621669 }
16631670
1664- /* void Server::accept(std::vector<Socket> &sockets, const System::native_socket_type max_val) const
1665- {
1666- ::fd_set readset;
1667- FD_ZERO(&readset);
1668-
1669- for (auto &sock : server_sockets)
1670- {
1671- FD_SET(sock.get_handle(), &readset);
1672- }
1673-
1674- if (0 < ::select(max_val + 1, &readset, nullptr, nullptr, nullptr) )
1675- {
1676- for (auto &sock : server_sockets)
1677- {
1678- if (FD_ISSET(sock.get_handle(), &readset) )
1679- {
1680- System::native_socket_type client_socket = ~0;
1681-
1682- do
1683- {
1684- #ifdef WIN32
1685- client_socket = ::accept(sock.get_handle(), static_cast<sockaddr *>(nullptr), static_cast<int *>(nullptr) );
1686- #elif POSIX
1687- client_socket = ::accept(sock.get_handle(), static_cast<sockaddr *>(nullptr), static_cast<socklen_t *>(nullptr) );
1688- #else
1689- #error "Undefine platform"
1690- #endif
1691-
1692- if (~0 != client_socket)
1693- {
1694- sockets.emplace_back(Socket(client_socket) );
1695- }
1696- }
1697- while (~0 != client_socket);
1698- }
1699- }
1700- }
1701- }*/
1702-
17031671 int Server::run ()
17041672 {
17051673 if (false == init () )
@@ -1901,7 +1869,7 @@ namespace HttpServer
19011869
19021870 if (file.gcount () )
19031871 {
1904- pid = std::stoull (str_pid);
1872+ pid = std::strtoull (str_pid, nullptr , 10 );
19051873 }
19061874 }
19071875
0 commit comments