libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
localsocket.h
Go to the documentation of this file.
1
8#pragma once
9
10
11#include <promeki/config.h>
12#if PROMEKI_ENABLE_NETWORK
13#include <promeki/iodevice.h>
14#include <promeki/error.h>
15#include <promeki/string.h>
16#include <promeki/uniqueptr.h>
17
18PROMEKI_NAMESPACE_BEGIN
19
49class LocalSocket : public IODevice {
50 PROMEKI_OBJECT(LocalSocket, IODevice)
51 public:
53 using UPtr = UniquePtr<LocalSocket>;
54
56 static constexpr unsigned int DefaultReceiveTimeoutMs = 5000;
57
59 static constexpr unsigned int DefaultSendTimeoutMs = 5000;
60
62 static bool isSupported();
63
68 LocalSocket(ObjectBase *parent = nullptr);
69
71 ~LocalSocket() override;
72
83 Error open(OpenMode mode) override;
84
86 Error close() override;
87
100 Error connectTo(const String &path, unsigned int timeoutMs = 0);
101
103 bool isOpen() const override { return _fd >= 0; }
104
106 bool isConnected() const { return _fd >= 0 && _connected; }
107
114 int64_t read(void *data, int64_t maxSize) override;
115
122 int64_t write(const void *data, int64_t maxSize) override;
123
125 int64_t bytesAvailable() const override;
126
128 bool isSequential() const override { return true; }
129
131 int socketDescriptor() const { return _fd; }
132
143 void setSocketDescriptor(int fd, const String &peerPath = String());
144
146 const String &peerPath() const { return _peerPath; }
147
152 Error setReceiveTimeout(unsigned int timeoutMs);
153
158 Error setSendTimeout(unsigned int timeoutMs);
159
161 PROMEKI_SIGNAL(connected);
162
164 PROMEKI_SIGNAL(disconnected);
165
166 private:
167 int _fd = -1;
168 bool _connected = false;
169 String _peerPath;
170};
171
172PROMEKI_NAMESPACE_END
173
174#endif // PROMEKI_ENABLE_NETWORK