예제 소스
바둑 on-policy 학습: 대국 로그를 KataGo 라벨로 바꾸기 · 파일 169개
tcpboardechoclient.h
#pragma once
#include <QAtomicInt>
#include <QByteArray>
#include <QImage>
#include <QObject>
#include <QString>
class QTcpSocket;
/**
* 보드 시각화 서버(BRD1/RTXT) 전용 TCP 클라이언트.
* VLM 수 요청(GO19) 소켓과 분리된 전용 워커에서 동작합니다.
*
* 프로토콜 (BRD1):
* 요청: "BRD1" | u32_be body_len | u8 size | u8 reserved(0) |
* u32_be png_len | png | size*size board (0/1/2)
* 응답: "RTXT" | u8 ok
* ok=1: u32_be utf8_len | utf8 text
* ok=0: u16_be utf8_len | utf8 err
* PING/PONG: 4바이트.
*/
namespace TcpBoardEchoClient {
class Worker : public QObject {
Q_OBJECT
public:
explicit Worker(QObject *parent = nullptr);
~Worker() override;
bool isBusy() const;
public slots:
void doPing(QString host, quint16 port, int timeoutMs);
void requestBoardEcho(QImage boardImage, QByteArray boardPacked, int boardSize,
QString host, quint16 port, int timeoutMs);
void cancel();
/// 앱 종료 시 MainWindow 소멸자에서 BlockingQueuedConnection 으로 호출.
void shutdownForAppExit();
signals:
void pingReady(bool success, QString errorMessage);
void echoReady(bool success, QString textOrError);
private:
bool ensureConnected(const QString &host, quint16 port, int timeoutMs, QString *errorOut);
bool readBytes(QByteArray *dst, qint64 nbytes, int deadlineMs);
bool writeAll(const QByteArray &data, int timeoutMs);
void closeSocketLocked(const QString &reason);
QTcpSocket *m_socket = nullptr;
QString m_curHost;
quint16 m_curPort = 0;
QAtomicInt m_cancel{0};
QAtomicInt m_busy{0};
};
} // namespace TcpBoardEchoClient