@@ -67,17 +67,19 @@ class BridgeUDP final: public UDP {
6767 explicit BridgeUDP (BridgeClass& bridge): bridge(&bridge) {}
6868
6969 uint8_t begin (uint16_t port) override {
70-
7170 if (!init ()) {
7271 return 0 ;
7372 }
7473
7574 k_mutex_lock (&udp_mutex, K_FOREVER);
7675
77- String hostname = " 0.0.0.0" ;
78- const bool ok = _connected || bridge->call (UDP_CONNECT_METHOD, hostname, port).result (connection_id);
79- _connected = ok;
80- if (_connected) _port = port;
76+ bool ok = false ;
77+ if (!_connected) {
78+ String hostname = " 0.0.0.0" ;
79+ ok = bridge->call (UDP_CONNECT_METHOD, hostname, port).result (connection_id);
80+ _connected = ok;
81+ if (_connected) _port = port;
82+ }
8183
8284 k_mutex_unlock (&udp_mutex);
8385
@@ -91,17 +93,19 @@ class BridgeUDP final: public UDP {
9193 }
9294
9395 uint8_t beginMulticast (IPAddress ip, uint16_t port) override {
94-
9596 if (!init ()) {
9697 return 0 ;
9798 }
9899
99100 k_mutex_lock (&udp_mutex, K_FOREVER);
100101
101- String hostname = ip.toString ();
102- const bool ok = _connected || bridge->call (UDP_CONNECT_MULTI_METHOD, hostname, port).result (connection_id);
103- _connected = ok;
104- if (_connected) _port = port;
102+ bool ok = false ;
103+ if (!_connected) {
104+ String hostname = " 0.0.0.0" ;
105+ ok = bridge->call (UDP_CONNECT_METHOD, hostname, port).result (connection_id);
106+ _connected = ok;
107+ if (_connected) _port = port;
108+ }
105109
106110 k_mutex_unlock (&udp_mutex);
107111
@@ -124,7 +128,6 @@ class BridgeUDP final: public UDP {
124128 }
125129
126130 int beginPacket (const char *host, uint16_t port) override {
127-
128131 k_mutex_lock (&udp_mutex, K_FOREVER);
129132
130133 _targetHost = host;
@@ -150,7 +153,6 @@ class BridgeUDP final: public UDP {
150153 }
151154
152155 size_t write (const uint8_t *buffer, size_t size) override {
153-
154156 if (!connected ()) return 0 ;
155157
156158 MsgPack::arr_t <uint8_t > payload;
@@ -282,7 +284,6 @@ class BridgeUDP final: public UDP {
282284 }
283285
284286 void _read (size_t size) {
285-
286287 if (size == 0 ) return ;
287288
288289 k_mutex_lock (&udp_mutex, K_FOREVER);
0 commit comments