Fix linking wrong asio library

gitea-master
John Montagu, the 4th Earl of Sandvich 2026-04-04 22:28:36 -07:00
parent 208e64c6dc
commit db2d190ab6
Signed by: sandvich
GPG Key ID: 9A39BE37E602B22D
3 changed files with 15 additions and 11 deletions

View File

@ -7,5 +7,9 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# adding this option to make clangd work
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
add_library(asio INTERFACE)
target_include_directories(asio INTERFACE asio/include)
target_compile_definitions(asio INTERFACE ASIO_STANDALONE)
add_executable(as7 as7.cpp)
target_link_libraries(as7 PRIVATE pthread)
target_link_libraries(as7 PRIVATE asio pthread)

View File

@ -1,6 +1,6 @@
#pragma once
#include <boost/asio.hpp>
#include <asio.hpp>
#include <deque>
#include <iostream>
#include <memory>
@ -8,7 +8,7 @@
#include <string_view>
#include <thread>
namespace asio = boost::asio;
namespace asio = ::asio;
std::string client_read_buffer;
std::deque<std::string> client_write_queue;
@ -20,7 +20,7 @@ inline void client_handle_write(std::shared_ptr<asio::ip::tcp::socket> socket) {
}
asio::async_write(*socket, asio::buffer(client_write_queue.front()),
[socket](boost::system::error_code ec, std::size_t length) {
[socket](asio::error_code ec, std::size_t length) {
(void)length;
if (ec) {
std::cerr << "Error: " << ec.message() << std::endl;
@ -55,7 +55,7 @@ inline bool handle_local_color_command(const std::string &message) {
inline void client_handle_read(std::shared_ptr<asio::ip::tcp::socket> socket) {
asio::async_read_until(*socket, asio::dynamic_buffer(client_read_buffer), '\n',
[socket](boost::system::error_code ec, std::size_t length) {
[socket](asio::error_code ec, std::size_t length) {
(void)length;
if (ec) {
std::cerr << "Error: " << ec.message() << std::endl;
@ -104,7 +104,7 @@ inline void run_client(std::string_view host = "127.0.0.1", std::string_view por
}
}
boost::system::error_code ec;
asio::error_code ec;
socket->shutdown(asio::ip::tcp::socket::shutdown_both, ec);
socket->close(ec);
ctx.stop();

View File

@ -1,6 +1,6 @@
#pragma once
#include <boost/asio.hpp>
#include <asio.hpp>
#include <deque>
#include <iostream>
#include <memory>
@ -8,7 +8,7 @@
#include <string>
#include <vector>
namespace asio = boost::asio;
namespace asio = ::asio;
struct ClientConnection {
std::shared_ptr<asio::ip::tcp::socket> connection;
@ -27,7 +27,7 @@ inline void handle_client_write(std::shared_ptr<ClientConnection> client) {
}
asio::async_write(*client->connection, asio::buffer(client->write_queue.front()),
[client](boost::system::error_code ec, std::size_t length) {
[client](asio::error_code ec, std::size_t length) {
if (ec) {
std::cerr << "Error: " << ec.message() << std::endl;
clients.erase(client);
@ -55,7 +55,7 @@ inline void broadcast_message(const std::string &message) {
inline void handle_client_read(std::shared_ptr<ClientConnection> client) {
// it looks like this because of clang-format
asio::async_read_until(*client->connection, asio::dynamic_buffer(client->read_buffer), '\n',
[client](boost::system::error_code ec, std::size_t length) {
[client](asio::error_code ec, std::size_t length) {
if (ec) {
std::cerr << "Error: " << ec.message() << std::endl;
clients.erase(client);
@ -93,7 +93,7 @@ inline void handle_client_read(std::shared_ptr<ClientConnection> client) {
}
inline void accept_connections(asio::ip::tcp::acceptor &acceptor) {
acceptor.async_accept([&acceptor](boost::system::error_code ec, asio::ip::tcp::socket socket) {
acceptor.async_accept([&acceptor](asio::error_code ec, asio::ip::tcp::socket socket) {
if (ec) {
std::cerr << "Error: " << ec.message() << std::endl;
return;