Files
FEX-Emu--FEX/Source/Tools/LinuxEmulation/LinuxSyscalls/NetStream.h
T
Ryan Houdek 02d93782ba GdbServer: Implement new netstream that can be interrupted
A major limitation of iostream is that you can't have reads or writes
with a safe interrupt. Instead rewrite the interface with Linux ppoll so
that these can be safely interrupted with a signal and return early.
2025-02-03 11:54:12 -08:00

43 lines
783 B
C++

// SPDX-License-Identifier: MIT
#pragma once
#include <FEXCore/Utils/CompilerDefs.h>
#include <FEXCore/fextl/string.h>
#include <FEXCore/fextl/vector.h>
#include <optional>
namespace FEX::Utils {
class NetStream final {
public:
NetStream()
: receive_buffer(1500) {}
void OpenSocket(int _socketfd) {
socketfd = _socketfd;
}
void InvalidateSocket() {
socketfd = -1;
}
bool HasSocket() const {
return socketfd != -1;
}
struct ReturnGet {
char data;
bool Hangup;
};
std::optional<ReturnGet> get();
size_t read(char* buf, size_t size);
bool SendPacket(const fextl::string& packet);
private:
int socketfd {-1};
size_t read_offset {};
size_t receive_offset {};
fextl::vector<char> receive_buffer;
};
} // namespace FEX::Utils