Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion cth/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ cth_pkg_target_include_directories(
INTERFACE incl
)

target_compile_options(cth INTERFACE $<$<CXX_COMPILER_ID:MSVC>:/Zc:preprocessor>)
# nvcc rejects cl flags, it forwards them to its MSVC host compiler with -Xcompiler
target_compile_options(
cth
INTERFACE
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/Zc:preprocessor>
$<$<AND:$<COMPILE_LANGUAGE:CUDA>,$<CXX_COMPILER_ID:MSVC>>:-Xcompiler=/Zc:preprocessor>
)

# cth/hash/hash_aggregates.hpp includes boost/pfr.hpp
cth_pkg_target_find_package(cth boost_pfr CONFIG REQUIRED)
Expand Down
28 changes: 28 additions & 0 deletions cth_net/src/websocket_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,44 @@
#include "websocket_connection_state.hpp"

#include "cth/data/hash_map.hpp"
#include "cth/io/log.hpp"

#include <hv/WebSocketServer.h>
#include <hv/hlog.h>
#include <hv/hsocket.h>

#include <atomic>
#include <deque>
#include <format>
#include <mutex>
#include <string_view>
#include <utility>
#include <vector>

namespace cth::net {
namespace {
void forward_libhv_log(int level, char const* message, int length) {
std::string_view text{message, static_cast<std::size_t>(length)};
while(text.ends_with('\n') || text.ends_with('\r'))
text.remove_suffix(1);

auto const severity = level >= LOG_LEVEL_ERROR ? except::ERR : except::WARNING;
log::msg(severity, std::format("libhv: {}", text));
}

/**
* libhv's default logger writes libhv.<date>.log into the working directory,
* its warnings and errors go to cth::log instead
*/
void route_libhv_log() {
static std::once_flag once;
std::call_once(once, [] {
hlog_set_format("%s");
hlog_set_level(LOG_LEVEL_WARN);
hlog_set_handler(forward_libhv_log);
});
}
}

struct websocket_server::impl {
hv::WebSocketService service;
Expand Down Expand Up @@ -48,6 +75,7 @@ websocket_server::impl::impl(std::uint16_t port, std::size_t maxMessageSize) :
maxMessageSize{maxMessageSize} {
CTH_CRITICAL(maxMessageSize == 0, "WebSocket maximum message size must be positive") {}

route_libhv_log();
configure_callbacks();

auto const listenFd = Listen(port, "127.0.0.1");
Expand Down
4 changes: 3 additions & 1 deletion cth_win/src/io/win_key_convert.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,9 @@ struct win_key_params {
break;

default:
if(p.vkCode >= 'A' && p.vkCode <= 'Z')
if(p.vkCode >= VK_F1 && p.vkCode <= VK_F12)
key = static_cast<Key>(static_cast<uint16_t>(Key::F1) + (p.vkCode - VK_F1));
else if(p.vkCode >= 'A' && p.vkCode <= 'Z')
key = static_cast<Key>(static_cast<uint16_t>(Key::A) + (p.vkCode - 'A'));
else if(p.vkCode >= '0' && p.vkCode <= '9')
key = static_cast<Key>(static_cast<uint16_t>(Key::DIGIT_0) + (p.vkCode - '0'));
Expand Down
Loading