5 #include <Poco/AutoPtr.h>
6 #include <Poco/Buffer.h>
7 #include <Poco/Clock.h>
8 #include <Poco/Net/SocketNotification.h>
9 #include <Poco/Net/WebSocket.h>
11 #include "core/GatewayInfo.h"
12 #include "loop/StoppableRunnable.h"
13 #include "loop/StopControl.h"
14 #include "server/AbstractGWSConnector.h"
15 #include "ssl/SSLClient.h"
37 void setHost(
const std::string &host);
38 void setPort(
int port);
39 void setMaxMessageSize(
int size);
40 void setSSLConfig(SSLClient::Ptr config);
41 void setReceiveTimeout(
const Poco::Timespan &timeout);
42 void setSendTimeout(
const Poco::Timespan &timeout);
43 void setReconnectDelay(
const Poco::Timespan &delay);
44 void setKeepAliveTimeout(
const Poco::Timespan &timeout);
45 void setMaxFailedReceives(
int count);
46 void setGatewayInfo(GatewayInfo::Ptr info);
52 void waitBeforeReconnect();
54 Poco::SharedPtr<Poco::Net::WebSocket> connect(
55 const std::string &host,
57 void performRegister(Poco::Net::WebSocket &socket)
const;
58 bool performOutput(Poco::Net::WebSocket &socket);
59 void performPing(Poco::Net::WebSocket &socket);
60 void checkPingTimeout()
const;
63 Poco::Net::WebSocket &socket);
78 void onReadable(
const Poco::AutoPtr<Poco::Net::ReadableNotification> &n);
81 Poco::Net::WebSocket &socket,
84 Poco::Net::WebSocket &socket,
85 const std::string &payload,
86 const int flags)
const;
88 GWMessage::Ptr receiveMessage(Poco::Net::WebSocket &socket)
const;
90 Poco::Net::WebSocket &socket,
91 Poco::Buffer<char> &buffer,
97 size_t m_maxMessageSize;
98 SSLClient::Ptr m_sslConfig;
99 Poco::Timespan m_receiveTimeout;
100 Poco::Timespan m_sendTimeout;
101 Poco::Timespan m_reconnectDelay;
102 Poco::Timespan m_keepAliveTimeout;
103 int m_maxFailedReceives;
104 GatewayInfo::Ptr m_gatewayInfo;
106 mutable Poco::FastMutex m_sendLock;
107 mutable Poco::FastMutex m_receiveLock;
110 mutable Poco::Clock m_lastActivity;
111 mutable Poco::FastMutex m_lock;
113 Poco::Clock m_lastPing;
114 Poco::AtomicCounter m_receiveFailed;
Helper class for managing a common stoppable loop situation:
Definition: StopControl.h:35
Implements the communication via WebSockets with the remote server. Outgoing messages are prioritized...
Definition: GWSConnectorImpl.h:31
The GWMessage is abstract class representing messages (including their contents), that are being sent...
Definition: GWMessage.h:21
Most GWSConnector implementations would solve the issue of sending prioritization and asynchronous qu...
Definition: AbstractGWSConnector.h:38
const Poco::Timespan keepAliveRemaining() const
Definition: GWSConnectorImpl.cpp:254
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
void stop()
Definition: GWSConnectorImpl.cpp:188
Definition: StoppableRunnable.h:8
bool waitOutputs()
Wait while the output queues are empty. The waiting delay is driver by the keepAliveTimeout.
Definition: GWSConnectorImpl.cpp:225