]> git.seodisparate.com - UDPConnection/commitdiff
Bug fixes
authorStephen Seo <seo.disparate@gmail.com>
Tue, 17 Dec 2019 11:58:44 +0000 (20:58 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Tue, 17 Dec 2019 11:58:44 +0000 (20:58 +0900)
Fixed not setting output int to 0 to specify zero connections when
returning connection IDs.

src/UDPConnection.cpp
src/test/UDPC_NetworkTest.c

index b3e0e7b5a8efb9a5e695e53d3b559ffeee248ed3..ca419cba82db4a2dc2613f9de12c42e8667fe0bc 100644 (file)
@@ -1490,7 +1490,8 @@ void UDPC::Context::update_impl() {
         ntohs(receivedData.sin6_port),
         ", packet id = ", seqID,
         ", good mode = ", iter->second.flags.test(1) ? "yes" : "no",
-        isPing ? ", ping" : "");
+        isPing && !isConnect ? ", ping"
+            : (isPing && isConnect ? ", disc" : ""));
 
     // check if is delete
     if(isConnect && isPing) {
@@ -2167,6 +2168,9 @@ UDPC_ConnectionId* UDPC_get_list_connected(UDPC_HContext ctx, unsigned int *size
     std::lock_guard<std::mutex> lock(c->mutex);
 
     if(c->conMap.empty()) {
+        if(size) {
+            *size = 0;
+        }
         return nullptr;
     }
     if(size) {
index 2a8348e6ff76a90ecb27e84dfc98c15e120ab1c0..83dd5390823a1799de7c55cf740afb11f4ed996e 100644 (file)
@@ -308,11 +308,12 @@ int main(int argc, char **argv) {
     UDPC_set_accept_new_connections(context, 0);
 
     puts("Dropping all connections...");
-    UDPC_ConnectionId *ids = UDPC_get_list_connected(context, NULL);
+    UDPC_ConnectionId *ids = UDPC_get_list_connected(context, &temp);
     UDPC_ConnectionId *current = ids;
-    while(current->scope_id != 0 && current->port != 0) {
+    while(temp > 0) {
         UDPC_drop_connection(context, *current, 0);
         ++current;
+        --temp;
     }
     UDPC_free_list_connected(ids);