mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 17:28:11 +00:00
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.
This commit is contained in:
parent
62ebb78433
commit
bdeccf8844
2 changed files with 10 additions and 3 deletions
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
#include "Engine.h"
|
#include "Engine.h"
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
|
#include <LibCore/System.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <spawn.h>
|
#include <spawn.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -27,12 +28,12 @@ void Engine::connect_to_engine_service()
|
||||||
{
|
{
|
||||||
int wpipefds[2];
|
int wpipefds[2];
|
||||||
int rpipefds[2];
|
int rpipefds[2];
|
||||||
if (pipe2(wpipefds, O_CLOEXEC | O_NONBLOCK) < 0) {
|
if (pipe2(wpipefds, O_CLOEXEC) < 0) {
|
||||||
perror("pipe2");
|
perror("pipe2");
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pipe2(rpipefds, O_CLOEXEC | O_NONBLOCK) < 0) {
|
if (pipe2(rpipefds, O_CLOEXEC) < 0) {
|
||||||
perror("pipe2");
|
perror("pipe2");
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -55,9 +56,11 @@ void Engine::connect_to_engine_service()
|
||||||
close(rpipefds[1]);
|
close(rpipefds[1]);
|
||||||
|
|
||||||
auto infile = Core::File::adopt_fd(rpipefds[0], Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
|
auto infile = Core::File::adopt_fd(rpipefds[0], Core::File::OpenMode::Read).release_value_but_fixme_should_propagate_errors();
|
||||||
|
infile->set_blocking(false).release_value_but_fixme_should_propagate_errors();
|
||||||
set_in(move(infile)).release_value_but_fixme_should_propagate_errors();
|
set_in(move(infile)).release_value_but_fixme_should_propagate_errors();
|
||||||
|
|
||||||
auto outfile = Core::File::adopt_fd(wpipefds[1], Core::File::OpenMode::Write).release_value_but_fixme_should_propagate_errors();
|
auto outfile = Core::File::adopt_fd(wpipefds[1], Core::File::OpenMode::Write).release_value_but_fixme_should_propagate_errors();
|
||||||
|
outfile->set_blocking(false).release_value_but_fixme_should_propagate_errors();
|
||||||
set_out(move(outfile));
|
set_out(move(outfile));
|
||||||
|
|
||||||
send_command(Chess::UCI::UCICommand());
|
send_command(Chess::UCI::UCICommand());
|
||||||
|
|
|
@ -16,7 +16,11 @@ ErrorOr<int> serenity_main(Main::Arguments)
|
||||||
Core::EventLoop loop;
|
Core::EventLoop loop;
|
||||||
TRY(Core::System::unveil(nullptr, nullptr));
|
TRY(Core::System::unveil(nullptr, nullptr));
|
||||||
|
|
||||||
auto engine = TRY(ChessEngine::try_create(TRY(Core::File::standard_input()), TRY(Core::File::standard_output())));
|
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) {
|
engine->on_quit = [&](auto status_code) {
|
||||||
loop.quit(status_code);
|
loop.quit(status_code);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue