From 62ac6e779f8d961133fd5af9bfa8e10c6396e251 Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Tue, 17 Dec 2019 20:58:44 +0900 Subject: [PATCH] Bug fixes Fixed not setting output int to 0 to specify zero connections when returning connection IDs. --- src/UDPConnection.cpp | 6 +++++- src/test/UDPC_NetworkTest.c | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/UDPConnection.cpp b/src/UDPConnection.cpp index b3e0e7b..ca419cb 100644 --- a/src/UDPConnection.cpp +++ b/src/UDPConnection.cpp @@ -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 lock(c->mutex); if(c->conMap.empty()) { + if(size) { + *size = 0; + } return nullptr; } if(size) { diff --git a/src/test/UDPC_NetworkTest.c b/src/test/UDPC_NetworkTest.c index 2a8348e..83dd539 100644 --- a/src/test/UDPC_NetworkTest.c +++ b/src/test/UDPC_NetworkTest.c @@ -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);