Add way to get connection queued size

Requires locking the mutex for access to conMap.
This commit is contained in:
Stephen Seo 2019-12-18 13:47:46 +09:00
parent 62ac6e779f
commit 5ec344b733
3 changed files with 50 additions and 15 deletions

View file

@ -2129,6 +2129,30 @@ unsigned long UDPC_get_queue_send_current_size(UDPC_HContext ctx) {
return c->cSendPkts.size();
}
unsigned long UDPC_get_queued_size(UDPC_HContext ctx, UDPC_ConnectionId id, int *exists) {
UDPC::Context *c = UDPC::verifyContext(ctx);
if(!c) {
return 0;
}
std::lock_guard<std::mutex> lock(c->mutex);
auto iter = c->conMap.find(id);
if(iter != c->conMap.end()) {
if(exists) {
*exists = 1;
}
return iter->second.sendPkts.size();
}
if(exists) {
*exists = 0;
}
return 0;
}
unsigned long UDPC_get_max_queued_size() {
return UDPC_QUEUED_PKTS_MAX_SIZE;
}
int UDPC_set_accept_new_connections(UDPC_HContext ctx, int isAccepting) {
UDPC::Context *c = UDPC::verifyContext(ctx);
if(!c) {

View file

@ -455,6 +455,10 @@ void UDPC_queue_send(UDPC_HContext ctx, UDPC_ConnectionId destinationId,
*/
unsigned long UDPC_get_queue_send_current_size(UDPC_HContext ctx);
unsigned long UDPC_get_queued_size(UDPC_HContext ctx, UDPC_ConnectionId id, int *exists);
unsigned long UDPC_get_max_queued_size();
int UDPC_set_accept_new_connections(UDPC_HContext ctx, int isAccepting);
void UDPC_drop_connection(UDPC_HContext ctx, UDPC_ConnectionId connectionId, int dropAllWithAddr);

View file

@ -225,6 +225,7 @@ int main(int argc, char **argv) {
unsigned int tick = 0;
unsigned int temp = 0;
unsigned int temp2, temp3;
int temp4;
unsigned long size;
UDPC_ConnectionId *list = NULL;
unsigned int sendIds[SEND_IDS_SIZE];
@ -242,24 +243,30 @@ int main(int argc, char **argv) {
}
if(!noPayload) {
list = UDPC_get_list_connected(context, &temp);
if(list) {
if(sendIdsSize < temp) {
while(sendIdsSize < temp) {
if(sendIdsSize == SEND_IDS_SIZE) {
temp = SEND_IDS_SIZE;
break;
}
sendIds[sendIdsSize++] = 0;
if(sendIdsSize < temp) {
while(sendIdsSize < temp) {
if(sendIdsSize == SEND_IDS_SIZE) {
temp = SEND_IDS_SIZE;
break;
}
} else if(sendIdsSize > temp) {
sendIdsSize = temp;
sendIds[sendIdsSize++] = 0;
}
size = UDPC_get_queue_send_current_size(context);
temp2 = size < QUEUED_MAX_SIZE ? QUEUED_MAX_SIZE - size : 0;
for(unsigned int i = 0; i < temp2; ++i) {
temp3 = htonl(sendIds[i % temp]++);
UDPC_queue_send(context, list[i % temp], 0, &temp3, sizeof(unsigned int));
} else if(sendIdsSize > temp) {
sendIdsSize = temp;
}
for(unsigned int i = 0; i < temp; ++i) {
size = UDPC_get_max_queued_size() - UDPC_get_queued_size(context, list[i], &temp4);
if(temp4 == 0) {
continue;
}
for(unsigned int j = 0; j < size; ++j) {
temp2 = htonl(sendIds[i]++);
UDPC_queue_send(context, list[i], 0, &temp2, sizeof(unsigned int));
}
}
if(list) {
UDPC_free_list_connected(list);
}
do {