diff --git a/src/UDPConnection.c b/src/UDPConnection.c index 969e4c3..7278486 100644 --- a/src/UDPConnection.c +++ b/src/UDPConnection.c @@ -452,6 +452,28 @@ void UDPC_set_accept_new_connections(UDPC_Context *ctx, int isAccepting) if(ctx->isThreaded != 0) { mtx_unlock(&ctx->tCVMtx); } } +int UDPC_drop_connection(UDPC_Context *ctx, uint32_t addr) +{ + int wasDropped = 0; + + if(ctx->isThreaded != 0) { mtx_lock(&ctx->tCVMtx); } + + UDPC_INTERNAL_ConnectionData *cd = UDPC_HashMap_get(ctx->conMap, addr); + if(cd) + { + if((cd->flags & 0x10) != 0) + { + UDPC_HashMap_remove(ctx->idMap, cd->id); + } + UDPC_HashMap_remove(ctx->conMap, addr); + wasDropped = 1; + } + + if(ctx->isThreaded != 0) { mtx_unlock(&ctx->tCVMtx); } + + return wasDropped; +} + uint32_t UDPC_get_protocol_id(UDPC_Context *ctx) { if(ctx->isThreaded != 0) { mtx_lock(&ctx->tCVMtx); } diff --git a/src/UDPConnection.h b/src/UDPConnection.h index eafb066..1f7a941 100644 --- a/src/UDPConnection.h +++ b/src/UDPConnection.h @@ -123,6 +123,7 @@ typedef struct { mtx_t tflagsMtx; cnd_t threadCV; UDPC_HashMap *conMap; + // Clients intentionally do not use idMap at all UDPC_HashMap *idMap; struct timespec lastUpdated; char atostrBuf[UDPC_ATOSTR_BUF_SIZE]; @@ -227,6 +228,12 @@ int UDPC_get_accept_new_connections(UDPC_Context *ctx); */ void UDPC_set_accept_new_connections(UDPC_Context *ctx, int isAccepting); +/// Drops a connection specified by addr +/*! + * \return non-zero if the connection existed and was dropped + */ +int UDPC_drop_connection(UDPC_Context *ctx, uint32_t addr); + /// Gets the currently set protocol id uint32_t UDPC_get_protocol_id(UDPC_Context *ctx);