Code refactoring.
This commit is contained in:
@@ -3,7 +3,6 @@
|
||||
#include <list>
|
||||
#include <iostream>
|
||||
|
||||
#include "boost/lexical_cast.hpp"
|
||||
#include "boost/thread/thread.hpp"
|
||||
#include "json/json.h"
|
||||
#include "webcc/logger.h"
|
||||
|
||||
@@ -36,7 +36,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||
|
||||
unsigned short port = std::atoi(argv[1]);
|
||||
std::uint16_t port = static_cast<std::uint16_t>(std::atoi(argv[1]));
|
||||
|
||||
int sleep_seconds = 0;
|
||||
if (argc >= 3) {
|
||||
@@ -56,7 +56,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
server.Run();
|
||||
|
||||
} catch (std::exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "calc_client.h"
|
||||
|
||||
#include <iostream>
|
||||
#include "boost/lexical_cast.hpp"
|
||||
|
||||
#include "webcc/logger.h"
|
||||
|
||||
// Set to 0 to test our own calculator server created with webcc.
|
||||
@@ -80,8 +81,8 @@ bool CalcClient::Calc(const std::string& operation,
|
||||
|
||||
// Convert the result from string to double.
|
||||
try {
|
||||
*result = boost::lexical_cast<double>(result_str);
|
||||
} catch (boost::bad_lexical_cast&) {
|
||||
*result = std::stod(result_str);
|
||||
} catch (const std::exception&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
#include "calc_service.h"
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
|
||||
// Sleep several seconds for the client to test timeout control.
|
||||
#define SLEEP_FOR_TIMEOUT_TEST 0
|
||||
|
||||
#include "boost/lexical_cast.hpp"
|
||||
|
||||
#if SLEEP_FOR_TIMEOUT_TEST
|
||||
#include "boost/thread/thread.hpp"
|
||||
#endif
|
||||
@@ -82,10 +83,10 @@ bool CalcService::GetParameters(const webcc::SoapRequest& soap_request,
|
||||
double* x,
|
||||
double* y) {
|
||||
try {
|
||||
*x = boost::lexical_cast<double>(soap_request.GetParameter("x"));
|
||||
*y = boost::lexical_cast<double>(soap_request.GetParameter("y"));
|
||||
*x = std::stod(soap_request.GetParameter("x"));
|
||||
*y = std::stod(soap_request.GetParameter("y"));
|
||||
|
||||
} catch (boost::bad_lexical_cast& e) {
|
||||
} catch (const std::exception& e) {
|
||||
LOG_ERRO("Parameter cast error: %s", e.what());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
WEBCC_LOG_INIT("", webcc::LOG_CONSOLE);
|
||||
|
||||
unsigned short port = std::atoi(argv[1]);
|
||||
std::uint16_t port = static_cast<std::uint16_t>(std::atoi(argv[1]));
|
||||
|
||||
std::size_t workers = 2;
|
||||
|
||||
@@ -30,7 +30,7 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
server.Run();
|
||||
|
||||
} catch (std::exception& e) {
|
||||
} catch (const std::exception& e) {
|
||||
std::cerr << "Exception: " << e.what() << std::endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user