Merge pull request #171 from yorickdewid/master

Set cast type without dereferencing pointer
This commit is contained in:
Jaeseung Ha 2017-09-18 00:44:36 +09:00 committed by GitHub
commit 6da6579ce9
6 changed files with 54 additions and 48 deletions

View File

@ -7,11 +7,13 @@ conan_basic_setup()
endif() endif()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
find_package(Tcmalloc) find_package(Tcmalloc)
find_package(Threads) find_package(Threads)
find_package(OpenSSL) find_package(OpenSSL)
if(OPENSSL_FOUND) if(OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR}) include_directories(${OPENSSL_INCLUDE_DIR})
endif() endif()
find_program(CCACHE_FOUND ccache) find_program(CCACHE_FOUND ccache)
@ -24,23 +26,22 @@ if(CCACHE_FOUND)
endif(CCACHE_FOUND) endif(CCACHE_FOUND)
if (NOT CMAKE_BUILD_TYPE) if (NOT CMAKE_BUILD_TYPE)
message(STATUS "No build type selected, default to Release") message(STATUS "No build type selected, default to Release")
set(CMAKE_BUILD_TYPE "Release") set(CMAKE_BUILD_TYPE "Release")
endif() endif()
if (MSVC) if (MSVC)
set(Boost_USE_STATIC_LIBS "On") set(Boost_USE_STATIC_LIBS "On")
find_package( Boost 1.52 COMPONENTS system thread regex REQUIRED ) find_package( Boost 1.52 COMPONENTS system thread regex REQUIRED )
else() else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++1y -pedantic -Wextra") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++1y -pedantic -Wextra")
find_package( Boost 1.52 COMPONENTS system thread REQUIRED ) find_package( Boost 1.52 COMPONENTS system thread REQUIRED )
endif() endif()
include_directories( ${Boost_INCLUDE_DIR} ) include_directories( ${Boost_INCLUDE_DIR} )
set(PROJECT_INCLUDE_DIR set(PROJECT_INCLUDE_DIR
${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/include
) )
include_directories("${PROJECT_INCLUDE_DIR}") include_directories("${PROJECT_INCLUDE_DIR}")
@ -48,22 +49,23 @@ include_directories("${PROJECT_SOURCE_DIR}")
#add_subdirectory(src) #add_subdirectory(src)
add_subdirectory(examples) add_subdirectory(examples)
if (MSVC) if (MSVC)
else() else()
add_subdirectory(tests) add_subdirectory(tests)
enable_testing() enable_testing()
add_test(NAME crow_test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/unittest) add_test(NAME crow_test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/unittest)
add_test(NAME template_test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/template/test.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests/template) add_test(NAME template_test COMMAND ${CMAKE_CURRENT_BINARY_DIR}/tests/template/test.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/tests/template)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/amalgamate) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/amalgamate)
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/amalgamate/crow_all.h add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/amalgamate/crow_all.h
COMMAND python ${PROJECT_SOURCE_DIR}/amalgamate/merge_all.py ${PROJECT_SOURCE_DIR}/include COMMAND python ${PROJECT_SOURCE_DIR}/amalgamate/merge_all.py ${PROJECT_SOURCE_DIR}/include
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/amalgamate/crow_all.h ${PROJECT_SOURCE_DIR}/amalgamate COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/amalgamate/crow_all.h ${PROJECT_SOURCE_DIR}/amalgamate
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/amalgamate WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/amalgamate
DEPENDS ${PROJECT_SOURCE_DIR}/include/*.h DEPENDS ${PROJECT_SOURCE_DIR}/include/*.h
) )
add_custom_target(amalgamation ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/amalgamate/crow_all.h) add_custom_target(amalgamation ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/amalgamate/crow_all.h)
endif() endif()

View File

@ -2,29 +2,28 @@ cmake_minimum_required(VERSION 2.8)
project (crow_examples) project (crow_examples)
if (MSVC) if (MSVC)
add_executable(example_vs example_vs.cpp) add_executable(example_vs example_vs.cpp)
target_link_libraries(example_vs ${Boost_LIBRARIES}) target_link_libraries(example_vs ${Boost_LIBRARIES})
target_link_libraries(example_vs ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(example_vs ${CMAKE_THREAD_LIBS_INIT})
else () else ()
add_executable(helloworld helloworld.cpp)
add_executable(helloworld helloworld.cpp) target_link_libraries(helloworld ${Boost_LIBRARIES})
target_link_libraries(helloworld ${Boost_LIBRARIES}) target_link_libraries(helloworld ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries(helloworld ${CMAKE_THREAD_LIBS_INIT})
if (OPENSSL_FOUND) if (OPENSSL_FOUND)
add_executable(example_ssl ssl/example_ssl.cpp) add_executable(example_ssl ssl/example_ssl.cpp)
target_link_libraries(example_ssl ${Boost_LIBRARIES}) target_link_libraries(example_ssl ${Boost_LIBRARIES})
target_link_libraries(example_ssl ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES}) target_link_libraries(example_ssl ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES})
endif() endif()
add_executable(example_websocket websocket/example_ws.cpp) add_executable(example_websocket websocket/example_ws.cpp)
target_link_libraries(example_websocket ${Boost_LIBRARIES}) target_link_libraries(example_websocket ${Boost_LIBRARIES})
target_link_libraries(example_websocket ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES}) target_link_libraries(example_websocket ${CMAKE_THREAD_LIBS_INIT} ${OPENSSL_LIBRARIES})
add_custom_command(OUTPUT ws.html add_custom_command(OUTPUT ws.html
COMMAND ${CMAKE_COMMAND} -E COMMAND ${CMAKE_COMMAND} -E
copy ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html ${CMAKE_CURRENT_BINARY_DIR}/templates/ws.html copy ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html ${CMAKE_CURRENT_BINARY_DIR}/templates/ws.html
DEPENDS ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html DEPENDS ${PROJECT_SOURCE_DIR}/websocket/templates/ws.html
) )
add_custom_target(example_ws_copy ALL DEPENDS ws.html) add_custom_target(example_ws_copy ALL DEPENDS ws.html)
add_executable(example example.cpp) add_executable(example example.cpp)
@ -33,7 +32,7 @@ target_link_libraries(example ${Boost_LIBRARIES})
target_link_libraries(example ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(example ${CMAKE_THREAD_LIBS_INIT})
if (Tcmalloc_FOUND) if (Tcmalloc_FOUND)
target_link_libraries(example ${Tcmalloc_LIBRARIES}) target_link_libraries(example ${Tcmalloc_LIBRARIES})
endif(Tcmalloc_FOUND) endif(Tcmalloc_FOUND)
add_executable(example_with_all example_with_all.cpp) add_executable(example_with_all example_with_all.cpp)
@ -42,21 +41,20 @@ target_link_libraries(example_with_all ${Boost_LIBRARIES})
target_link_libraries(example_with_all ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(example_with_all ${CMAKE_THREAD_LIBS_INIT})
add_custom_command(OUTPUT example_test.py add_custom_command(OUTPUT example_test.py
COMMAND ${CMAKE_COMMAND} -E COMMAND ${CMAKE_COMMAND} -E
copy ${PROJECT_SOURCE_DIR}/example_test.py ${CMAKE_CURRENT_BINARY_DIR}/example_test.py copy ${PROJECT_SOURCE_DIR}/example_test.py ${CMAKE_CURRENT_BINARY_DIR}/example_test.py
DEPENDS ${PROJECT_SOURCE_DIR}/example_test.py DEPENDS ${PROJECT_SOURCE_DIR}/example_test.py
) )
add_custom_target(example_copy ALL DEPENDS example_test.py) add_custom_target(example_copy ALL DEPENDS example_test.py)
add_executable(example_chat example_chat.cpp) add_executable(example_chat example_chat.cpp)
#target_link_libraries(example_chat crow)
target_link_libraries(example_chat ${Boost_LIBRARIES}) target_link_libraries(example_chat ${Boost_LIBRARIES})
target_link_libraries(example_chat ${CMAKE_THREAD_LIBS_INIT}) target_link_libraries(example_chat ${CMAKE_THREAD_LIBS_INIT})
add_custom_command(OUTPUT example_chat.html add_custom_command(OUTPUT example_chat.html
COMMAND ${CMAKE_COMMAND} -E COMMAND ${CMAKE_COMMAND} -E
copy ${PROJECT_SOURCE_DIR}/example_chat.html ${CMAKE_CURRENT_BINARY_DIR}/example_chat.html copy ${PROJECT_SOURCE_DIR}/example_chat.html ${CMAKE_CURRENT_BINARY_DIR}/example_chat.html
DEPENDS ${PROJECT_SOURCE_DIR}/example_chat.html DEPENDS ${PROJECT_SOURCE_DIR}/example_chat.html
) )
add_custom_target(example_chat_copy ALL DEPENDS example_chat.html) add_custom_target(example_chat_copy ALL DEPENDS example_chat.html)
#SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pg" ) #SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -pg" )

View File

@ -15,7 +15,7 @@ void broadcast(const string& msg)
x["msgs"][0] = msgs.back(); x["msgs"][0] = msgs.back();
x["last"] = msgs.size(); x["last"] = msgs.size();
string body = crow::json::dump(x); string body = crow::json::dump(x);
for(auto p:ress) for(auto p : ress)
{ {
auto* res = p.first; auto* res = p.first;
CROW_LOG_DEBUG << res << " replied: " << body; CROW_LOG_DEBUG << res << " replied: " << body;

View File

@ -86,6 +86,12 @@ namespace crow
completed_ = false; completed_ = false;
} }
void redirect(const std::string& location)
{
code = 301;
set_header("Location", location);
}
void write(const std::string& body_part) void write(const std::string& body_part)
{ {
body += body_part; body += body_part;

View File

@ -148,7 +148,7 @@ namespace crow
}); });
} }
CROW_LOG_INFO << server_name_ << " server is running on port " << port_ CROW_LOG_INFO << server_name_ << " server is running at " << bindaddr_ <<":" << port_
<< " using " << concurrency_ << " threads"; << " using " << concurrency_ << " threads";
signals_.async_wait( signals_.async_wait(

View File

@ -226,7 +226,7 @@ namespace crow
case WebSocketReadState::Len16: case WebSocketReadState::Len16:
{ {
remaining_length_ = 0; remaining_length_ = 0;
uint16_t remaining_length16_ = 0; uint16_t remaining_length16_ = 0;
boost::asio::async_read(adaptor_.socket(), boost::asio::buffer(&remaining_length16_, 2), boost::asio::async_read(adaptor_.socket(), boost::asio::buffer(&remaining_length16_, 2),
[this,&remaining_length16_](const boost::system::error_code& ec, std::size_t bytes_transferred) [this,&remaining_length16_](const boost::system::error_code& ec, std::size_t bytes_transferred)
{ {