aboutsummaryrefslogtreecommitdiff
path: root/src/zenhorde/hordetransport.h
blob: 1b178dc0f27c13d21ed83e89493665db22a3868d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright Epic Games, Inc. All Rights Reserved.

#pragma once

#include <zenhorde/hordeclient.h>

#include <zencore/logbase.h>

#include <cstddef>
#include <cstdint>
#include <memory>

#if ZEN_PLATFORM_WINDOWS
#	undef SendMessage
#endif

namespace zen::horde {

/** Abstract base interface for compute transports.
 *
 *  Matches the UE FComputeTransport pattern. Concrete implementations handle
 *  the underlying I/O (TCP, AES-wrapped, etc.) while this interface provides
 *  blocking message helpers on top.
 */
class ComputeTransport
{
public:
	virtual ~ComputeTransport() = default;

	virtual bool   IsValid() const					   = 0;
	virtual size_t Send(const void* Data, size_t Size) = 0;
	virtual size_t Recv(void* Data, size_t Size)	   = 0;
	virtual void   MarkComplete()					   = 0;
	virtual void   Close()							   = 0;

	/** Blocking send that loops until all bytes are transferred. Returns false on error. */
	bool SendMessage(const void* Data, size_t Size);

	/** Blocking receive that loops until all bytes are transferred. Returns false on error. */
	bool RecvMessage(void* Data, size_t Size);
};

/** TCP socket transport using ASIO.
 *
 *  Connects to the Horde compute endpoint specified by MachineInfo and provides
 *  raw TCP send/receive. ASIO internals are hidden behind a pimpl to keep the
 *  header clean.
 */
class TcpComputeTransport final : public ComputeTransport
{
public:
	explicit TcpComputeTransport(const MachineInfo& Info);
	~TcpComputeTransport() override;

	bool   IsValid() const override;
	size_t Send(const void* Data, size_t Size) override;
	size_t Recv(void* Data, size_t Size) override;
	void   MarkComplete() override;
	void   Close() override;

private:
	LoggerRef Log() { return m_Log; }

	struct Impl;
	std::unique_ptr<Impl> m_Impl;
	LoggerRef			  m_Log;
	bool				  m_IsClosed  = false;
	bool				  m_HasErrors = false;
};

}  // namespace zen::horde