@@ -163,7 +163,6 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
163163 uint32_t addr = 0 , auth_ts = 0 , cvec_addr = 0 , result_addr = 0 , sync_send_timeout_sec = 0 , sync_read_timeout_sec = 0 , session_timeout_sec = 0 ;
164164 Timer session_timer;
165165 Client *client = nullptr ;
166- bool client_changed = false , network_changed = false ;
167166#if defined(ENABLE_ASYNC_TCP_CLIENT)
168167 AsyncTCPConfig *atcp_config = nullptr ;
169168#else
@@ -188,7 +187,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
188187 if ((!sData ->sse && session_timeout_sec >= FIREBASE_SESSION_TIMEOUT_SEC && session_timer.remaining () == 0 ) || (sse && !sData ->sse ) || (!sse && sData ->sse ) || (sData ->auth_used && sData ->state == astate_undefined) ||
189188 strcmp (this ->host .c_str (), host) != 0 || this ->port != port)
190189 {
191- stop (sData );
190+ stop ();
192191 getResult ()->clear ();
193192 }
194193
@@ -867,7 +866,6 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
867866 sData ->request .file_data .resumable .updateRange ();
868867 }
869868#endif
870-
871869 if (sData ->request .method == reqns::http_delete && sData ->response .httpCode == FIREBASE_ERROR_HTTP_CODE_NO_CONTENT)
872870 setDebugBase (app_debug, FPSTR (" Delete operation complete" ));
873871 }
@@ -885,7 +883,6 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
885883 // the next chunk data is the payload
886884 if (sData ->response .httpCode != FIREBASE_ERROR_HTTP_CODE_NO_CONTENT)
887885 {
888-
889886 if (sData ->response .flags .chunks )
890887 {
891888 // Use temporary String buffer for decodeChunks
@@ -1084,7 +1081,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
10841081 }
10851082
10861083 if (sData ->response .flags .chunks && sData ->auth_used )
1087- stop (sData );
1084+ stop ();
10881085
10891086 // HTTP server error.
10901087 if (sData ->response .httpCode >= FIREBASE_ERROR_HTTP_CODE_BAD_REQUEST)
@@ -1172,7 +1169,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
11721169 void reset (async_data *sData , bool disconnect)
11731170 {
11741171 if (disconnect)
1175- stop (sData );
1172+ stop ();
11761173
11771174 sData ->response .httpCode = 0 ;
11781175 sData ->error .code = 0 ;
@@ -1353,17 +1350,14 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
13531350 inStopAsync = false ;
13541351 }
13551352
1356- void stop (async_data * sData )
1353+ void stop ()
13571354 {
13581355 if (conn.isConnected ())
13591356 setDebugBase (app_debug, FPSTR (" Terminating the server connection..." ));
13601357
13611358 conn.stop ();
1362-
13631359 clear (host);
13641360 this ->port = 0 ;
1365- client_changed = false ;
1366- network_changed = false ;
13671361 }
13681362
13691363 async_data *createSlot (slot_options_t &options)
@@ -1549,9 +1543,9 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
15491543 return exitProcess (false );
15501544
15511545 // Restart connection when authenticate, client or network changed
1552- if ((sData ->sse && sData ->auth_ts != auth_ts) || client_changed || network_changed )
1546+ if ((sData ->sse && sData ->auth_ts != auth_ts) || conn. isChanged () )
15531547 {
1554- stop (sData );
1548+ stop ();
15551549 sData ->state = astate_send_header;
15561550 }
15571551
@@ -1689,16 +1683,14 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
16891683
16901684 ~AsyncClientClass ()
16911685 {
1692- stop (nullptr );
1693-
1686+ stop ();
16941687 for (size_t i = 0 ; i < sVec .size (); i++)
16951688 {
16961689 reset (getData (i), true );
16971690 async_data *sData = getData (i);
16981691 delete sData ;
16991692 sData = nullptr ;
17001693 }
1701-
17021694 addRemoveClientVec (cvec_addr, false );
17031695 }
17041696
@@ -1825,8 +1817,7 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
18251817 void setNetwork (Client &client, network_config_data &net)
18261818 {
18271819 // Check client changes.
1828- client_changed = reinterpret_cast <uint32_t >(&client) != reinterpret_cast <uint32_t >(this ->client );
1829- network_changed = true ;
1820+ bool client_changed = reinterpret_cast <uint32_t >(&client) != reinterpret_cast <uint32_t >(this ->client );
18301821
18311822 // Some changes, stop the current network client.
18321823 if (client_changed && this ->client )
@@ -1838,7 +1829,10 @@ class AsyncClientClass : public ResultBase, RTDBResultBase
18381829
18391830 // Change the client.
18401831 if (client_changed)
1832+ {
18411833 this ->client = &client;
1834+ conn.setClientChange ();
1835+ }
18421836 }
18431837};
18441838
0 commit comments