5#ifdef FASTLED_HAS_NETWORKING
9 #include "platforms/win/socket_win.h"
11 #include "platforms/posix/socket_posix.h"
26NativeHttpClient::NativeHttpClient(
const string& host, u16 port,
const ConnectionConfig& config)
47 mConnection.connect();
50 if (platformConnect()) {
51 mConnection.onConnected(0);
56 mConnection.onDisconnected();
61 if (mSocket.is_open()) {
63 mConnection.disconnect();
73 return mConnection.isConnected() && isSocketConnected();
77 return mConnection.getState();
80int NativeHttpClient::send(fl::span<const u8> data)
FL_NO_EXCEPT {
86 size_t n = mSocket.write_some(data, ec);
92 mConnection.onDisconnected();
96 return static_cast<int>(n);
99int NativeHttpClient::recv(fl::span<u8> buffer)
FL_NO_EXCEPT {
105 size_t n = mSocket.read_some(buffer, ec);
112 mConnection.onDisconnected();
117 mConnection.onHeartbeatReceived();
119 return static_cast<int>(n);
122void NativeHttpClient::update(u32 currentTimeMs)
FL_NO_EXCEPT {
124 mConnection.update(currentTimeMs);
127 if (mConnection.shouldReconnect()) {
138bool NativeHttpClient::shouldSendHeartbeat(u32 currentTimeMs)
const FL_NO_EXCEPT {
139 return mConnection.shouldSendHeartbeat(currentTimeMs);
143 mConnection.onHeartbeatSent();
146void NativeHttpClient::onHeartbeatReceived()
FL_NO_EXCEPT {
147 mConnection.onHeartbeatReceived();
150u32 NativeHttpClient::getReconnectDelayMs() const
FL_NO_EXCEPT {
151 return mConnection.getReconnectDelayMs();
154u32 NativeHttpClient::getReconnectAttempts() const
FL_NO_EXCEPT {
155 return mConnection.getReconnectAttempts();
160 if (mSocket.is_open()) {
161 platformDisconnect();
168void NativeHttpClient::platformDisconnect()
FL_NO_EXCEPT {
172bool NativeHttpClient::isSocketConnected() const
FL_NO_EXCEPT {
173 if (!mSocket.is_open()) {
179 socklen_t len =
sizeof(error);
180 int ret = getsockopt(mSocket.native_handle(), SOL_SOCKET, SO_ERROR, (
char*)&error, &len);
182 if (ret != 0 || error != 0) {
bool isConnected() FL_NO_EXCEPT
True when the station interface has an IP.
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Base definition for an LED controller.
bool ok() const FL_NO_EXCEPT
Convenience: true if no error.
Asio-compatible error code: numeric code + optional human-readable message.
Asio-compatible endpoint type: bundles host address + port.