Skip to content

Commit

Permalink
Use coroutines via boost::asio::spawn to improve overall code structu…
Browse files Browse the repository at this point in the history
…re in servers (wesnoth#5341)

* Convert server_base class to use coroutine instead of handlers

* Rework wesnothd's client login to use coroutine

* Merge 3 player handling functions into a single coroutine

* update cmakelists too

* Implement send_doc_queued in terms of coroutine

* Use brace initialization for making asio buffers

* Implement campaignd's request handling in coroutine

* Brace-initialize entire vector

* Remove old handler based send/receive helpers

* Document coroutine send/receive helpers

* Made coro_send_doc() helper take wml doc by reference

In most cases there is no need to rely on shared pointers to ensure
object lifetime if using coroutines since even when coroutine is
suspended args are still kept alive by its context.

* Document coro_send_file()

* Silence deprecation warning to fix build on earlier versions of boost

* Explicitly check for boost.context to allow linking against static boost libs

* Add boost.coroutine to flatpak manifest

* Port winapi TransmitFile codepath to coroutines

* Exception safety fix

* Add boost.scope_exit to vcpkg

* Fix build with pre-1.66 boost

* Move coro_* helpers into server_base class

Those helpers were in .ipp solely because they were templated on handler
types, this is no longer true after coroutine based rework.

* Make server_base::coro_send_file non-inline

* CleanUp Xcode project

Co-authored-by: Martin Hrubý (hrubymar10) <[email protected]>
  • Loading branch information
loonycyborg and hrubymar10 authored Dec 30, 2020
1 parent 204357c commit 3933eba
Show file tree
Hide file tree
Showing 16 changed files with 563 additions and 724 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci-main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ jobs:
shell: cmd
run: |
%~dp0../wesnoth/vcpkg/vcpkg integrate install
%~dp0../wesnoth/vcpkg/vcpkg install sdl2:x64-windows sdl2-image:x64-windows sdl2-image[libjpeg-turbo]:x64-windows sdl2-mixer[libvorbis,dynamic-load]:x64-windows sdl2-ttf:x64-windows bzip2:x64-windows zlib:x64-windows pango:x64-windows cairo:x64-windows fontconfig:x64-windows libvorbis:x64-windows libogg:x64-windows boost-filesystem:x64-windows boost-iostreams:x64-windows boost-locale[icu]:x64-windows boost-random:x64-windows boost-regex[icu]:x64-windows boost-asio:x64-windows boost-program-options:x64-windows boost-system:x64-windows boost-thread:x64-windows boost-bimap:x64-windows boost-multi-array:x64-windows boost-ptr-container:x64-windows boost-logic:x64-windows boost-format:x64-windows
%~dp0../wesnoth/vcpkg/vcpkg install sdl2:x64-windows sdl2-image:x64-windows sdl2-image[libjpeg-turbo]:x64-windows sdl2-mixer[libvorbis,dynamic-load]:x64-windows sdl2-ttf:x64-windows bzip2:x64-windows zlib:x64-windows pango:x64-windows cairo:x64-windows fontconfig:x64-windows libvorbis:x64-windows libogg:x64-windows boost-filesystem:x64-windows boost-iostreams:x64-windows boost-locale[icu]:x64-windows boost-random:x64-windows boost-regex[icu]:x64-windows boost-asio:x64-windows boost-program-options:x64-windows boost-system:x64-windows boost-thread:x64-windows boost-bimap:x64-windows boost-multi-array:x64-windows boost-ptr-container:x64-windows boost-logic:x64-windows boost-format:x64-windows boost-scope-exit:x64-windows
- name: DOS3
shell: cmd
run: |
Expand Down Expand Up @@ -374,7 +374,7 @@ jobs:
shell: cmd
run: |
%~dp0../wesnoth/vcpkg/vcpkg integrate install
%~dp0../wesnoth/vcpkg/vcpkg install sdl2:x64-windows sdl2-image:x64-windows sdl2-image[libjpeg-turbo]:x64-windows sdl2-mixer[libvorbis,dynamic-load]:x64-windows sdl2-ttf:x64-windows bzip2:x64-windows zlib:x64-windows pango:x64-windows cairo:x64-windows fontconfig:x64-windows libvorbis:x64-windows libogg:x64-windows boost-filesystem:x64-windows boost-iostreams:x64-windows boost-locale[icu]:x64-windows boost-random:x64-windows boost-regex[icu]:x64-windows boost-asio:x64-windows boost-program-options:x64-windows boost-system:x64-windows boost-thread:x64-windows boost-bimap:x64-windows boost-multi-array:x64-windows boost-ptr-container:x64-windows boost-logic:x64-windows boost-format:x64-windows
%~dp0../wesnoth/vcpkg/vcpkg install sdl2:x64-windows sdl2-image:x64-windows sdl2-image[libjpeg-turbo]:x64-windows sdl2-mixer[libvorbis,dynamic-load]:x64-windows sdl2-ttf:x64-windows bzip2:x64-windows zlib:x64-windows pango:x64-windows cairo:x64-windows fontconfig:x64-windows libvorbis:x64-windows libogg:x64-windows boost-filesystem:x64-windows boost-iostreams:x64-windows boost-locale[icu]:x64-windows boost-random:x64-windows boost-regex[icu]:x64-windows boost-asio:x64-windows boost-program-options:x64-windows boost-system:x64-windows boost-thread:x64-windows boost-bimap:x64-windows boost-multi-array:x64-windows boost-ptr-container:x64-windows boost-logic:x64-windows boost-format:x64-windows boost-scope-exit:x64-windows
- name: DOS3
shell: cmd
run: |
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ else()
set(CRYPTO_LIBRARY "-framework Security")
endif()

find_package(Boost ${BOOST_VERSION} REQUIRED COMPONENTS iostreams program_options regex system thread random)
find_package(Boost ${BOOST_VERSION} REQUIRED COMPONENTS iostreams
program_options regex system thread random coroutine)

# no, gettext executables are not required when NLS is deactivated
find_package(Gettext)
Expand Down
6 changes: 5 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,9 @@ if env["prereqs"]:
have_libpthread = conf.CheckLib("pthread")
return have_libpthread & \
conf.CheckBoost("system") & \
conf.CheckBoost("asio", header_only = True)
conf.CheckBoost("asio", header_only = True) & \
conf.CheckBoost("context") & \
conf.CheckBoost("coroutine")

def have_sdl_other():
return \
Expand Down Expand Up @@ -429,6 +431,8 @@ if env["prereqs"]:
if env["history"]:
client_env.Append(CPPDEFINES = ["HAVE_HISTORY"])

env.Append(CPPDEFINES = ["BOOST_COROUTINES_NO_DEPRECATION_WARNING"])

if env["forum_user_handler"]:
found_connector = False
for sql_config in ["mariadb_config", "mysql_config"]:
Expand Down
2 changes: 1 addition & 1 deletion packaging/flatpak/org.wesnoth.Wesnoth.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
],
"build-commands": [
"./bootstrap.sh --prefix=/app --with-libraries=filesystem,locale,iostreams,program_options,regex,random,thread",
"./bootstrap.sh --prefix=/app --with-libraries=filesystem,locale,iostreams,program_options,regex,random,thread,coroutine,context",
"./b2 -j$FLATPAK_BUILDER_N_JOBS install cxxflags='-fPIE -fstack-protector-strong' define=_FORTIFY_SOURCE=2 link=static variant=release address-model=64 --layout=system"
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
460D899E24DC7843000B1ABC /* forum_user_handler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D899324DC7842000B1ABC /* forum_user_handler.cpp */; };
460D899F24DC7843000B1ABC /* simple_wml.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D899524DC7842000B1ABC /* simple_wml.cpp */; };
460D89A024DC7843000B1ABC /* simple_wml.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D899524DC7842000B1ABC /* simple_wml.cpp */; };
460D89A124DC7843000B1ABC /* server_base.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D899824DC7842000B1ABC /* server_base.cpp */; };
460D89A224DC7843000B1ABC /* server_base.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D899824DC7842000B1ABC /* server_base.cpp */; };
460D89B624DC7863000B1ABC /* addon_utils.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D89AD24DC7862000B1ABC /* addon_utils.cpp */; };
460D89B724DC7863000B1ABC /* server.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D89AE24DC7862000B1ABC /* server.cpp */; };
460D89B824DC7863000B1ABC /* fs_commit.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D89B024DC7862000B1ABC /* fs_commit.cpp */; };
Expand Down Expand Up @@ -84,6 +82,8 @@
464C03752283695A007D2741 /* libSDL2_ttf-2.0.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 464C0366228361B6007D2741 /* libSDL2_ttf-2.0.0.dylib */; };
464C03762283695D007D2741 /* libSDL2_mixer-2.0.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 464C0368228361B7007D2741 /* libSDL2_mixer-2.0.0.dylib */; };
464C037722836961007D2741 /* libSDL2_image-2.0.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 464C0362228361B5007D2741 /* libSDL2_image-2.0.0.dylib */; };
464F7FD125937D72006AB37B /* server_base.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D899824DC7842000B1ABC /* server_base.cpp */; };
464F7FDA25937D74006AB37B /* server_base.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 460D899824DC7842000B1ABC /* server_base.cpp */; };
46515C302569CE0B00084CE2 /* libssl.1.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 46515C2E2569CE0B00084CE2 /* libssl.1.1.dylib */; };
46515C312569CE0B00084CE2 /* libssl.1.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 46515C2E2569CE0B00084CE2 /* libssl.1.1.dylib */; };
46515C322569CE0B00084CE2 /* libssl.1.1.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 46515C2E2569CE0B00084CE2 /* libssl.1.1.dylib */; };
Expand Down Expand Up @@ -1466,7 +1466,6 @@
460D899024DC7842000B1ABC /* user_handler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = user_handler.cpp; path = ../../src/server/common/user_handler.cpp; sourceTree = SOURCE_ROOT; };
460D899124DC7842000B1ABC /* user_handler.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = user_handler.hpp; path = ../../src/server/common/user_handler.hpp; sourceTree = SOURCE_ROOT; };
460D899324DC7842000B1ABC /* forum_user_handler.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = forum_user_handler.cpp; path = ../../src/server/common/forum_user_handler.cpp; sourceTree = SOURCE_ROOT; };
460D899424DC7842000B1ABC /* send_receive_wml_helpers.ipp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = send_receive_wml_helpers.ipp; path = ../../src/server/common/send_receive_wml_helpers.ipp; sourceTree = SOURCE_ROOT; };
460D899524DC7842000B1ABC /* simple_wml.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = simple_wml.cpp; path = ../../src/server/common/simple_wml.cpp; sourceTree = SOURCE_ROOT; };
460D899624DC7842000B1ABC /* dbconn.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = dbconn.hpp; path = ../../src/server/common/dbconn.hpp; sourceTree = SOURCE_ROOT; };
460D899724DC7842000B1ABC /* server_base.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = server_base.hpp; path = ../../src/server/common/server_base.hpp; sourceTree = SOURCE_ROOT; };
Expand Down Expand Up @@ -3385,7 +3384,6 @@
460D899324DC7842000B1ABC /* forum_user_handler.cpp */,
460D898D24DC7841000B1ABC /* forum_user_handler.hpp */,
460D89BC24DC95A2000B1ABC /* resultsets */,
460D899424DC7842000B1ABC /* send_receive_wml_helpers.ipp */,
460D899824DC7842000B1ABC /* server_base.cpp */,
460D899724DC7842000B1ABC /* server_base.hpp */,
460D899524DC7842000B1ABC /* simple_wml.cpp */,
Expand Down Expand Up @@ -5626,7 +5624,6 @@
46685CAD219D643C0009CFFE /* tokenizer.cpp in Sources */,
46F57088205FCF7E007031BF /* config_attribute_value.cpp in Sources */,
460D89A024DC7843000B1ABC /* simple_wml.cpp in Sources */,
460D89A224DC7843000B1ABC /* server_base.cpp in Sources */,
91C548F21D88707D00FE6A7B /* filesystem_common.cpp in Sources */,
46685CA8219D63FA0009CFFE /* preprocessor.cpp in Sources */,
46F57087205FCF5D007031BF /* filesystem_sdl.cpp in Sources */,
Expand All @@ -5640,6 +5637,7 @@
46F57086205FCE79007031BF /* hash.cpp in Sources */,
91C548DF1D886E2100FE6A7B /* log.cpp in Sources */,
46685CA9219D63FE0009CFFE /* binary_or_text.cpp in Sources */,
464F7FDA25937D74006AB37B /* server_base.cpp in Sources */,
91C548E01D886E2C00FE6A7B /* tstring.cpp in Sources */,
460D89C524DC95DD000B1ABC /* tournaments.cpp in Sources */,
460D89B624DC7863000B1ABC /* addon_utils.cpp in Sources */,
Expand Down Expand Up @@ -6232,6 +6230,7 @@
B5BB6C860F8943F600444FBF /* config_cache.cpp in Sources */,
46685CA1219D52DB0009CFFE /* parser.cpp in Sources */,
B5BB6B8D0F893F2300444FBF /* config.cpp in Sources */,
464F7FD125937D72006AB37B /* server_base.cpp in Sources */,
ECF9D43E19F3FF9400E6C9D9 /* filesystem.cpp in Sources */,
460D898B24DC7831000B1ABC /* player.cpp in Sources */,
903F959F1ED5496700F1BDD3 /* hash.cpp in Sources */,
Expand All @@ -6257,7 +6256,6 @@
46BED4D52050611600842FA5 /* crypt_blowfish.c in Sources */,
460D898724DC7831000B1ABC /* ban.cpp in Sources */,
EC64D7661A085F120092EF75 /* mt_rng.cpp in Sources */,
460D89A124DC7843000B1ABC /* server_base.cpp in Sources */,
EC64D7671A085F2F0092EF75 /* seed_rng.cpp in Sources */,
B5BB6C710F8941F000444FBF /* tstring.cpp in Sources */,
46685CA2219D52FA0009CFFE /* unicode.cpp in Sources */,
Expand Down Expand Up @@ -6341,10 +6339,6 @@
"FIFODIR=\\\"/var/run/wesnoth_campaignd\\\"",
);
INSTALL_PATH = /usr/local/bin;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/lib",
);
PRODUCT_NAME = campaignd;
};
name = Debug;
Expand All @@ -6360,10 +6354,6 @@
"FIFODIR=\\\"/var/run/wesnoth_campaignd\\\"",
);
INSTALL_PATH = /usr/local/bin;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/lib",
);
PRODUCT_NAME = campaignd;
};
name = Release;
Expand All @@ -6381,10 +6371,6 @@
BOOST_TEST_DYN_LINK,
);
INSTALL_PATH = /usr/local/bin;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/lib",
);
MACH_O_TYPE = mh_execute;
OTHER_LDFLAGS = (
"-lz",
Expand All @@ -6407,10 +6393,6 @@
BOOST_TEST_DYN_LINK,
);
INSTALL_PATH = /usr/local/bin;
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/lib",
);
MACH_O_TYPE = mh_execute;
OTHER_LDFLAGS = (
"-lz",
Expand Down Expand Up @@ -6461,11 +6443,11 @@
buildSettings = {
CLANG_ENABLE_OBJC_WEAK = YES;
CODE_SIGN_ENTITLEMENTS = Resources/Wesnoth.entitlements;
CODE_SIGN_IDENTITY = "-";
CODE_SIGN_IDENTITY = "Developer ID Application";
CODE_SIGN_STYLE = Manual;
COMBINE_HIDPI_IMAGES = YES;
COPY_PHASE_STRIP = NO;
DEVELOPMENT_TEAM = "";
DEVELOPMENT_TEAM = N5CYW96P9T;
ENABLE_HARDENED_RUNTIME = YES;
GCC_DYNAMIC_NO_PIC = NO;
GCC_PRECOMPILE_PREFIX_HEADER = YES;
Expand All @@ -6479,10 +6461,6 @@
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = /Applications;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/lib",
);
OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
OTHER_LDFLAGS = (
"-lz",
Expand Down Expand Up @@ -6519,10 +6497,6 @@
INFOPLIST_FILE = Info.plist;
INSTALL_PATH = /Applications;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks";
LIBRARY_SEARCH_PATHS = (
"$(inherited)",
"$(PROJECT_DIR)/lib",
);
OTHER_CPLUSPLUSFLAGS = "$(OTHER_CFLAGS)";
OTHER_LDFLAGS = (
"-lz",
Expand Down
4 changes: 3 additions & 1 deletion scons/boost.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ def CheckBoost(context, boost_lib, require_version = None, header_only = False):
"unit_test_framework" : "test/unit_test.hpp",
"filesystem" : "filesystem/operations.hpp",
"random" : "random/random_number_generator.hpp",
"system" : "system/error_code.hpp"}
"system" : "system/error_code.hpp",
"context" : "context/continuation.hpp",
"coroutine" : "coroutine/coroutine.hpp" }

header_name = boost_headers.get(boost_lib, boost_lib + ".hpp")
libname = "boost_" + boost_lib + env.get("boost_suffix", "")
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ set(server-external-libs
${common-external-libs}
${Boost_SYSTEM_LIBRARIES}
${Boost_RANDOM_LIBRARY}
${Boost_COROUTINE_LIBRARY}
${CRYPTO_LIBRARY}
${MYSQL_LIBS}
-lpthread
Expand Down
69 changes: 37 additions & 32 deletions src/server/campaignd/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ static lg::log_domain log_config("config");
static lg::log_domain log_server("server");
#define ERR_SERVER LOG_STREAM(err, log_server)

#include "server/common/send_receive_wml_helpers.ipp"

namespace campaignd {

namespace {
Expand Down Expand Up @@ -477,34 +475,35 @@ std::ostream& operator<<(std::ostream& o, const server::request& r)

void server::handle_new_client(socket_ptr socket)
{
async_receive_doc(socket,
std::bind(&server::handle_request, this, std::placeholders::_1, std::placeholders::_2)
);
}
boost::asio::spawn(io_service_, [this, socket](boost::asio::yield_context yield) {
while(true) {
boost::system::error_code ec;
auto doc { coro_receive_doc(socket, yield[ec]) };
if(check_error(ec, socket) || !doc) return;

void server::handle_request(socket_ptr socket, std::shared_ptr<simple_wml::document> doc)
{
config data;
read(data, doc->output());
config data;
read(data, doc->output());

config::all_children_iterator i = data.ordered_begin();
config::all_children_iterator i = data.ordered_begin();

if(i != data.ordered_end()) {
// We only handle the first child.
const config::any_child& c = *i;
if(i != data.ordered_end()) {
// We only handle the first child.
const config::any_child& c = *i;

request_handlers_table::const_iterator j
= handlers_.find(c.key);
request_handlers_table::const_iterator j
= handlers_.find(c.key);

if(j != handlers_.end()) {
// Call the handler.
request req{c.key, c.cfg, socket};
auto st = service_timer(req);
j->second(this, req);
} else {
send_error("Unrecognized [" + c.key + "] request.",socket);
if(j != handlers_.end()) {
// Call the handler.
request req{c.key, c.cfg, socket, yield};
auto st = service_timer(req);
j->second(this, req);
} else {
send_error("Unrecognized [" + c.key + "] request.",socket);
}
}
}
}
});
}

#ifndef _WIN32
Expand Down Expand Up @@ -764,7 +763,7 @@ void server::send_message(const std::string& msg, socket_ptr sock)
const auto& escaped_msg = simple_wml_escape(msg);
simple_wml::document doc;
doc.root().add_child("message").set_attr_dup("message", escaped_msg.c_str());
async_send_doc(sock, doc, std::bind(&server::handle_new_client, this, std::placeholders::_1), null_handler);
async_send_doc_queued(sock, doc);
}

void server::send_error(const std::string& msg, socket_ptr sock)
Expand All @@ -773,7 +772,7 @@ void server::send_error(const std::string& msg, socket_ptr sock)
const auto& escaped_msg = simple_wml_escape(msg);
simple_wml::document doc;
doc.root().add_child("error").set_attr_dup("message", escaped_msg.c_str());
async_send_doc(sock, doc, std::bind(&server::handle_new_client, this, std::placeholders::_1), null_handler);
async_send_doc_queued(sock, doc);
}

void server::send_error(const std::string& msg, const std::string& extra_data, unsigned int status_code, socket_ptr sock)
Expand All @@ -794,7 +793,7 @@ void server::send_error(const std::string& msg, const std::string& extra_data, u
err_cfg.set_attr_dup("extra_data", escaped_extra_data.c_str());
err_cfg.set_attr_dup("status_code", escaped_status_str.c_str());

async_send_doc(sock, doc, std::bind(&server::handle_new_client, this, std::placeholders::_1), null_handler);
async_send_doc_queued(sock, doc);
}

config& server::get_addon(const std::string& id)
Expand Down Expand Up @@ -867,7 +866,7 @@ void server::handle_server_id(const server::request& req)
simple_wml::document doc(wml.c_str(), simple_wml::INIT_STATIC);
doc.compress();

async_send_doc(req.sock, doc, std::bind(&server::handle_new_client, this, std::placeholders::_1));
async_send_doc_queued(req.sock, doc);
}

void server::handle_request_campaign_list(const server::request& req)
Expand Down Expand Up @@ -968,7 +967,7 @@ void server::handle_request_campaign_list(const server::request& req)
simple_wml::document doc(wml.c_str(), simple_wml::INIT_STATIC);
doc.compress();

async_send_doc(req.sock, doc, std::bind(&server::handle_new_client, this, std::placeholders::_1));
async_send_doc_queued(req.sock, doc);
}

void server::handle_request_campaign(const server::request& req)
Expand Down Expand Up @@ -1071,7 +1070,9 @@ void server::handle_request_campaign(const server::request& req)

LOG_CS << req << "Sending add-on '" << name << "' version: " << from << " -> " << to << " (delta))\n";

async_send_doc(req.sock, doc, std::bind(&server::handle_new_client, this, std::placeholders::_1), null_handler);
boost::system::error_code ec;
coro_send_doc(req.sock, doc, req.yield[ec]);
if(check_error(ec, req.sock)) return;

full_pack_path.clear();
}
Expand All @@ -1087,7 +1088,9 @@ void server::handle_request_campaign(const server::request& req)
}

LOG_CS << req << "Sending add-on '" << name << "' version: " << to << " size: " << full_pack_size / 1024 << " KiB\n";
async_send_file(req.sock, full_pack_path, std::bind(&server::handle_new_client, this, std::placeholders::_1), null_handler);
boost::system::error_code ec;
coro_send_file(req.sock, full_pack_path, req.yield[ec]);
if(check_error(ec, req.sock)) return;
}

// Clients doing upgrades or some other specific thing shouldn't bump
Expand Down Expand Up @@ -1139,7 +1142,9 @@ void server::handle_request_campaign_hash(const server::request& req)
}

LOG_CS << req << "Sending add-on hash index for '" << req.cfg["name"] << "' size: " << file_size / 1024 << " KiB\n";
async_send_file(req.sock, path, std::bind(&server::handle_new_client, this, std::placeholders::_1), null_handler);
boost::system::error_code ec;
coro_send_file(req.sock, path, req.yield[ec]);
if(check_error(ec, req.sock)) return;
}
}

Expand Down
Loading

0 comments on commit 3933eba

Please sign in to comment.