11#include <promeki/config.h>
12#if PROMEKI_ENABLE_NETWORK
18PROMEKI_NAMESPACE_BEGIN
49class LocalSocket :
public IODevice {
50 PROMEKI_OBJECT(LocalSocket, IODevice)
53 using UPtr = UniquePtr<LocalSocket>;
56 static constexpr unsigned int DefaultReceiveTimeoutMs = 5000;
59 static constexpr unsigned int DefaultSendTimeoutMs = 5000;
62 static bool isSupported();
68 LocalSocket(ObjectBase *parent =
nullptr);
71 ~LocalSocket()
override;
83 Error open(OpenMode mode)
override;
86 Error close()
override;
100 Error connectTo(
const String &path,
unsigned int timeoutMs = 0);
103 bool isOpen()
const override {
return _fd >= 0; }
106 bool isConnected()
const {
return _fd >= 0 && _connected; }
114 int64_t read(
void *data, int64_t maxSize)
override;
122 int64_t write(
const void *data, int64_t maxSize)
override;
125 int64_t bytesAvailable()
const override;
128 bool isSequential()
const override {
return true; }
131 int socketDescriptor()
const {
return _fd; }
143 void setSocketDescriptor(
int fd,
const String &peerPath = String());
146 const String &peerPath()
const {
return _peerPath; }
152 Error setReceiveTimeout(
unsigned int timeoutMs);
158 Error setSendTimeout(
unsigned int timeoutMs);
161 PROMEKI_SIGNAL(connected);
164 PROMEKI_SIGNAL(disconnected);
168 bool _connected =
false;