Add function to drop connection to specific addr

Also added minor note about ctx->idMap
This commit is contained in:
Stephen Seo 2019-04-17 15:15:19 +09:00
parent 537fef9e8a
commit a33004a4c9
2 changed files with 29 additions and 0 deletions

View file

@ -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); }

View file

@ -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);