From 79dca558d2ca3ea821dacd3d2ea8e5c18b6f9096 Mon Sep 17 00:00:00 2001 From: eidheim Date: Mon, 2 May 2016 13:12:57 +0200 Subject: [PATCH] Resolved most warning messages when compiled with -Wextra or -Weverything. Related to #44 and #45 --- client_http.hpp | 18 ++++++++++-------- client_https.hpp | 4 ++-- http_examples.cpp | 6 +++--- https_examples.cpp | 6 +++--- server_http.hpp | 24 +++++++++++++----------- server_https.hpp | 2 +- test/parse_test.cpp | 2 +- 7 files changed, 33 insertions(+), 29 deletions(-) diff --git a/client_http.hpp b/client_http.hpp index 65eb63c..2703102 100644 --- a/client_http.hpp +++ b/client_http.hpp @@ -14,6 +14,8 @@ namespace SimpleWeb { template class ClientBase { public: + virtual ~ClientBase() {} + class Response { friend class ClientBase; @@ -43,7 +45,7 @@ namespace SimpleWeb { private: boost::asio::streambuf content_buffer; - Response(): content(&content_buffer) {}; + Response(): content(&content_buffer) {} }; std::shared_ptr request(const std::string& request_type, const std::string& path="/", boost::string_ref content="", @@ -86,7 +88,7 @@ namespace SimpleWeb { corrected_path="/"; content.seekp(0, std::ios::end); - size_t content_length=content.tellp(); + auto content_length=content.tellp(); content.seekp(0, std::ios::beg); boost::asio::streambuf write_buffer; @@ -135,7 +137,7 @@ namespace SimpleWeb { } else { host=host_port.substr(0, host_end); - port=(unsigned short)stoul(host_port.substr(host_end+1)); + port=static_cast(stoul(host_port.substr(host_end+1))); } asio_endpoint=boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), port); @@ -191,7 +193,7 @@ namespace SimpleWeb { boost::asio::streambuf streambuf; std::ostream content(&streambuf); - size_t length; + std::streamsize length; std::string buffer; do { size_t bytes_transferred = boost::asio::read_until(*socket, response->content_buffer, "\r\n"); @@ -199,16 +201,16 @@ namespace SimpleWeb { getline(response->content, line); bytes_transferred-=line.size()+1; line.pop_back(); - length=stoull(line, 0, 16); + length=stol(line, 0, 16); - size_t num_additional_bytes=response->content_buffer.size()-bytes_transferred; + auto num_additional_bytes=static_cast(response->content_buffer.size()-bytes_transferred); if((2+length)>num_additional_bytes) { boost::asio::read(*socket, response->content_buffer, boost::asio::transfer_exactly(2+length-num_additional_bytes)); } - buffer.resize(length); + buffer.resize(static_cast(length)); response->content.read(&buffer[0], length); content.write(&buffer[0], length); @@ -257,4 +259,4 @@ namespace SimpleWeb { }; } -#endif /* CLIENT_HTTP_HPP */ \ No newline at end of file +#endif /* CLIENT_HTTP_HPP */ diff --git a/client_https.hpp b/client_https.hpp index f6fb865..1a15747 100644 --- a/client_https.hpp +++ b/client_https.hpp @@ -28,7 +28,7 @@ namespace SimpleWeb { asio_context.load_verify_file(verify_file); socket=std::make_shared(asio_io_service, asio_context); - }; + } private: boost::asio::ssl::context asio_context; @@ -49,4 +49,4 @@ namespace SimpleWeb { }; } -#endif /* CLIENT_HTTPS_HPP */ \ No newline at end of file +#endif /* CLIENT_HTTPS_HPP */ diff --git a/http_examples.cpp b/http_examples.cpp index 664763e..d1119ca 100644 --- a/http_examples.cpp +++ b/http_examples.cpp @@ -102,7 +102,7 @@ int main() { if(ifs) { ifs.seekg(0, ios::end); - size_t length=ifs.tellg(); + auto length=ifs.tellg(); ifs.seekg(0, ios::beg); @@ -111,14 +111,14 @@ int main() { //read and send 128 KB at a time const size_t buffer_size=131072; vector buffer(buffer_size); - size_t read_length; + streamsize read_length; try { while((read_length=ifs.read(&buffer[0], buffer_size).gcount())>0) { response.write(&buffer[0], read_length); response.flush(); } } - catch(const exception &e) { + catch(const exception &) { cerr << "Connection interrupted, closing file" << endl; } diff --git a/https_examples.cpp b/https_examples.cpp index 2d05146..2e9d8b5 100644 --- a/https_examples.cpp +++ b/https_examples.cpp @@ -102,7 +102,7 @@ int main() { if(ifs) { ifs.seekg(0, ios::end); - size_t length=ifs.tellg(); + auto length=ifs.tellg(); ifs.seekg(0, ios::beg); @@ -111,14 +111,14 @@ int main() { //read and send 128 KB at a time const size_t buffer_size=131072; vector buffer(buffer_size); - size_t read_length; + streamsize read_length; try { while((read_length=ifs.read(&buffer[0], buffer_size).gcount())>0) { response.write(&buffer[0], read_length); response.flush(); } } - catch(const exception &e) { + catch(const exception &) { cerr << "Connection interrupted, closing file" << endl; } diff --git a/server_http.hpp b/server_http.hpp index 51f4a4f..557c219 100644 --- a/server_http.hpp +++ b/server_http.hpp @@ -17,6 +17,8 @@ namespace SimpleWeb { template class ServerBase { public: + virtual ~ServerBase() {} + class Response : public std::ostream { friend class ServerBase; private: @@ -101,7 +103,7 @@ namespace SimpleWeb { remote_endpoint_address=socket.lowest_layer().remote_endpoint().address().to_string(); remote_endpoint_port=socket.lowest_layer().remote_endpoint().port(); } - catch(const std::exception& e) {} + catch(const std::exception&) {} } }; @@ -195,16 +197,16 @@ namespace SimpleWeb { boost::asio::ip::tcp::acceptor acceptor; std::vector threads; - size_t timeout_request; - size_t timeout_content; + long timeout_request; + long timeout_content; - ServerBase(unsigned short port, size_t num_threads, size_t timeout_request, size_t timeout_send_or_receive) : + ServerBase(unsigned short port, size_t num_threads, long timeout_request, long timeout_send_or_receive) : config(port, num_threads), acceptor(io_service), timeout_request(timeout_request), timeout_content(timeout_send_or_receive) {} virtual void accept()=0; - std::shared_ptr set_timeout_on_socket(std::shared_ptr socket, size_t seconds) { + std::shared_ptr set_timeout_on_socket(std::shared_ptr socket, long seconds) { std::shared_ptr timer(new boost::asio::deadline_timer(io_service)); timer->expires_from_now(boost::posix_time::seconds(seconds)); timer->async_wait([socket](const boost::system::error_code& ec){ @@ -217,7 +219,7 @@ namespace SimpleWeb { return timer; } - std::shared_ptr set_timeout_on_socket(std::shared_ptr socket, std::shared_ptr request, size_t seconds) { + std::shared_ptr set_timeout_on_socket(std::shared_ptr socket, std::shared_ptr request, long seconds) { std::shared_ptr timer(new boost::asio::deadline_timer(io_service)); timer->expires_from_now(boost::posix_time::seconds(seconds)); timer->async_wait(request->strand.wrap([socket](const boost::system::error_code& ec){ @@ -266,7 +268,7 @@ namespace SimpleWeb { try { content_length=stoull(it->second); } - catch(const std::exception &e) { + catch(const std::exception &) { return; } if(content_length>num_additional_bytes) { @@ -367,7 +369,7 @@ namespace SimpleWeb { try { resource_function(response, request); } - catch(const std::exception& e) { + catch(const std::exception&) { return; } @@ -375,7 +377,7 @@ namespace SimpleWeb { try { response.flush(); } - catch(const std::exception &e) { + catch(const std::exception &) { return; } } @@ -385,7 +387,7 @@ namespace SimpleWeb { try { http_version=stof(request->http_version); } - catch(const std::exception &e) { + catch(const std::exception &) { return; } @@ -408,7 +410,7 @@ namespace SimpleWeb { template<> class Server : public ServerBase { public: - Server(unsigned short port, size_t num_threads=1, size_t timeout_request=5, size_t timeout_content=300) : + Server(unsigned short port, size_t num_threads=1, long timeout_request=5, long timeout_content=300) : ServerBase::ServerBase(port, num_threads, timeout_request, timeout_content) {} private: diff --git a/server_https.hpp b/server_https.hpp index 097ac25..3972475 100644 --- a/server_https.hpp +++ b/server_https.hpp @@ -11,7 +11,7 @@ namespace SimpleWeb { class Server : public ServerBase { public: Server(unsigned short port, size_t num_threads, const std::string& cert_file, const std::string& private_key_file, - size_t timeout_request=5, size_t timeout_content=300, + long timeout_request=5, long timeout_content=300, const std::string& verify_file=std::string()) : ServerBase::ServerBase(port, num_threads, timeout_request, timeout_content), context(boost::asio::ssl::context::sslv23) { diff --git a/test/parse_test.cpp b/test/parse_test.cpp index 40b41c0..77bdc27 100644 --- a/test/parse_test.cpp +++ b/test/parse_test.cpp @@ -98,7 +98,7 @@ public: } }; -int main(int argc, char** argv) { +int main() { ServerTest serverTest; if(!serverTest.parse_request_test()) {