mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-14 19:00:43 +02:00
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.
43 lines
783 B
C++
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
|