1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:14:58 +00:00
serenity/Userland/Services/ChessEngine/main.cpp
Ben Wiederhake bdeccf8844 Chess+ChessEngine: Fix stockfish by setting correct blocking flag
Stockfish apparently cannot handle non-blocking I/O, and it does not
make sense to assume that all chess engines can do so.

Fixes #18946.
2023-05-27 18:44:21 +02:00

29 lines
794 B
C++

/*
* Copyright (c) 2020, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "ChessEngine.h"
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibCore/System.h>
#include <LibMain/Main.h>
ErrorOr<int> serenity_main(Main::Arguments)
{
TRY(Core::System::pledge("stdio recvfd sendfd unix"));
Core::EventLoop loop;
TRY(Core::System::unveil(nullptr, nullptr));
auto infile = TRY(Core::File::standard_input());
TRY(infile->set_blocking(false));
auto outfile = TRY(Core::File::standard_output());
TRY(outfile->set_blocking(false));
auto engine = TRY(ChessEngine::try_create(move(infile), move(outfile)));
engine->on_quit = [&](auto status_code) {
loop.quit(status_code);
};
return loop.exec();
}