@@ -86,7 +86,10 @@ void MacAddress::SetFromBytes(const uint8_t mb[6]) noexcept
86
86
// Network members
87
87
Network::Network (Platform& p) noexcept : platform(p)
88
88
#if HAS_RESPONDERS
89
- , responders(nullptr ), clients(nullptr ), nextResponderToPoll(nullptr )
89
+ , responders(nullptr ), nextResponderToPoll(nullptr )
90
+ #endif
91
+ #if HAS_CLIENTS
92
+ , clients(nullptr )
90
93
#endif
91
94
{
92
95
#if HAS_NETWORKING
@@ -239,6 +242,7 @@ GCodeResult Network::EnableProtocol(unsigned int interface, NetworkProtocol prot
239
242
#if HAS_NETWORKING
240
243
if (interface < GetNumNetworkInterfaces ())
241
244
{
245
+ # if HAS_CLIENTS
242
246
bool hasFree = false ;
243
247
bool client = false ;
244
248
// Check if there are enough clients to accomodate enabling the protocol. Check if
@@ -262,7 +266,7 @@ GCodeResult Network::EnableProtocol(unsigned int interface, NetworkProtocol prot
262
266
reply.printf (" No more instances for client protocol.\n " );
263
267
return GCodeResult::error;
264
268
}
265
-
269
+ # endif
266
270
return interfaces[interface]->EnableProtocol (protocol, port, ip, secure, reply);
267
271
}
268
272
@@ -281,6 +285,7 @@ GCodeResult Network::DisableProtocol(unsigned int interface, NetworkProtocol pro
281
285
{
282
286
bool client = false ;
283
287
288
+ # if HAS_CLIENTS
284
289
// Check if a client handles the protocol. If so, termination is handled
285
290
// by the client itself, after attempting to disconnect gracefully.
286
291
for (NetworkClient *c = clients; c != nullptr ; c = c->GetNext ())
@@ -291,57 +296,58 @@ GCodeResult Network::DisableProtocol(unsigned int interface, NetworkProtocol pro
291
296
break ;
292
297
}
293
298
}
299
+ # endif
294
300
295
301
NetworkInterface * const iface = interfaces[interface];
296
302
const GCodeResult ret = iface->DisableProtocol (protocol, reply, !client);
297
303
298
304
if (ret == GCodeResult::ok)
299
305
{
300
- #if HAS_RESPONDERS
306
+ # if HAS_RESPONDERS
301
307
if (!client)
302
308
{
303
309
TerminateResponders (iface, protocol);
304
310
}
305
311
306
312
switch (protocol)
307
313
{
308
- #if SUPPORT_HTTP
314
+ # if SUPPORT_HTTP
309
315
case HttpProtocol:
310
316
HttpResponder::DisableInterface (iface); // free up output buffers etc.
311
317
break ;
312
- #endif
318
+ # endif
313
319
314
- #if SUPPORT_FTP
320
+ # if SUPPORT_FTP
315
321
case FtpProtocol:
316
322
// TODO the following isn't quite right, because we shouldn't free up output buffers if another network interface is still serving this protocol.
317
323
FtpResponder::Disable ();
318
324
break ;
319
- #endif
325
+ # endif
320
326
321
- #if SUPPORT_TELNET
327
+ # if SUPPORT_TELNET
322
328
case TelnetProtocol:
323
329
// TODO the following isn't quite right, because we shouldn't free up output buffers if another network interface is still serving this protocol.
324
330
TelnetResponder::Disable ();
325
331
break ;
326
- #endif
332
+ # endif
327
333
328
- #if SUPPORT_MULTICAST_DISCOVERY
334
+ # if SUPPORT_MULTICAST_DISCOVERY
329
335
// TODO the following isn't quite right, because we shouldn't free up output buffers if another network interface is still serving this protocol.
330
336
case MulticastDiscoveryProtocol:
331
337
break ;
332
- #endif
338
+ # endif
333
339
334
- #if SUPPORT_MQTT
340
+ # if SUPPORT_MQTT
335
341
case MqttProtocol:
336
342
// TODO the following isn't quite right, because we shouldn't free up output buffers if another network interface is still serving this protocol.
337
343
MqttClient::Disable ();
338
344
break ;
339
- #endif
345
+ # endif
340
346
341
347
default :
342
348
break ;
343
349
}
344
- #endif // HAS_RESPONDERS
350
+ # endif // HAS_RESPONDERS
345
351
}
346
352
return ret;
347
353
}
@@ -740,11 +746,8 @@ bool Network::UsingDhcp(unsigned int interface) const noexcept
740
746
return interface < GetNumNetworkInterfaces () && interfaces[interface]->UsingDhcp ();
741
747
}
742
748
743
- #endif
744
-
745
749
void Network::SetHostname (const char *name) noexcept
746
750
{
747
- #if HAS_NETWORKING
748
751
size_t i = 0 ;
749
752
while (*name && i < ARRAY_UPB (hostname))
750
753
{
@@ -776,11 +779,8 @@ void Network::SetHostname(const char *name) noexcept
776
779
iface->UpdateHostname (hostname);
777
780
}
778
781
}
779
- #endif
780
782
}
781
783
782
- #if HAS_NETWORKING
783
-
784
784
// Net the MAC address. Pass -1 as the interface number to set the default MAC address for interfaces that don't have one.
785
785
GCodeResult Network::SetMacAddress (unsigned int interface, const MacAddress& mac, const StringRef& reply) noexcept
786
786
{
@@ -820,7 +820,7 @@ bool Network::FindResponder(Socket *skt, NetworkProtocol protocol) noexcept
820
820
821
821
bool Network::StartClient (NetworkInterface *interface, NetworkProtocol protocol) noexcept
822
822
{
823
- #if HAS_RESPONDERS
823
+ #if HAS_CLIENTS
824
824
for (NetworkClient *c = clients; c != nullptr ; c = c->GetNext ())
825
825
{
826
826
if (c->Start (protocol, interface))
@@ -834,7 +834,7 @@ bool Network::StartClient(NetworkInterface *interface, NetworkProtocol protocol)
834
834
835
835
void Network::StopClient (NetworkInterface *interface, NetworkProtocol protocol) noexcept
836
836
{
837
- #if HAS_RESPONDERS
837
+ #if HAS_CLIENTS
838
838
for (NetworkClient *c = clients; c != nullptr ; c = c->GetNext ())
839
839
{
840
840
c->Stop (protocol, interface);
0 commit comments