server cast int to string only where it is needed

This commit is contained in:
Dennis Luxen 2014-05-28 12:34:48 +02:00
parent bb5973f2fd
commit aed04c7d55
2 changed files with 9 additions and 7 deletions

View File

@ -28,6 +28,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef SERVER_H #ifndef SERVER_H
#define SERVER_H #define SERVER_H
#include "../Util/StringUtil.h"
#include "Connection.h" #include "Connection.h"
#include "RequestHandler.h" #include "RequestHandler.h"
@ -42,12 +44,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
class Server class Server
{ {
public: public:
explicit Server(const std::string &address, const std::string &port, unsigned thread_pool_size) explicit Server(const std::string &address, const int port, const unsigned thread_pool_size)
: thread_pool_size(thread_pool_size), acceptor(io_service), : thread_pool_size(thread_pool_size), acceptor(io_service),
new_connection(new http::Connection(io_service, request_handler)), request_handler() new_connection(new http::Connection(io_service, request_handler)), request_handler()
{ {
const std::string port_string = IntToString(port);
boost::asio::ip::tcp::resolver resolver(io_service); boost::asio::ip::tcp::resolver resolver(io_service);
boost::asio::ip::tcp::resolver::query query(address, port); boost::asio::ip::tcp::resolver::query query(address, port_string);
boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query); boost::asio::ip::tcp::endpoint endpoint = *resolver.resolve(query);
acceptor.open(endpoint.protocol()); acceptor.open(endpoint.protocol());

View File

@ -30,7 +30,6 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "Server.h" #include "Server.h"
#include "../Util/SimpleLogger.h" #include "../Util/SimpleLogger.h"
#include "../Util/StringUtil.h"
#include <zlib.h> #include <zlib.h>
@ -41,10 +40,9 @@ struct ServerFactory
static Server *CreateServer(std::string &ip_address, int ip_port, unsigned requested_num_threads) static Server *CreateServer(std::string &ip_address, int ip_port, unsigned requested_num_threads)
{ {
SimpleLogger().Write() << "http 1.1 compression handled by zlib version " << zlibVersion(); SimpleLogger().Write() << "http 1.1 compression handled by zlib version " << zlibVersion();
std::string port_stream = IntToString(ip_port); const unsigned hardware_threads = std::max(1u, std::thread::hardware_concurrency());
unsigned hardware_threads = std::max(1u, std::thread::hardware_concurrency()); const unsigned real_num_threads = std::min(hardware_threads, requested_num_threads);
unsigned real_num_threads = std::min(hardware_threads, requested_num_threads); return new Server(ip_address, ip_port, real_num_threads);
return new Server(ip_address, port_stream, real_num_threads);
} }
}; };