Add way to get connection queued size
Requires locking the mutex for access to conMap.
This commit is contained in:
parent
62ac6e779f
commit
5ec344b733
3 changed files with 50 additions and 15 deletions
|
@ -2129,6 +2129,30 @@ unsigned long UDPC_get_queue_send_current_size(UDPC_HContext ctx) {
|
||||||
return c->cSendPkts.size();
|
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) {
|
int UDPC_set_accept_new_connections(UDPC_HContext ctx, int isAccepting) {
|
||||||
UDPC::Context *c = UDPC::verifyContext(ctx);
|
UDPC::Context *c = UDPC::verifyContext(ctx);
|
||||||
if(!c) {
|
if(!c) {
|
||||||
|
|
|
@ -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_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);
|
int UDPC_set_accept_new_connections(UDPC_HContext ctx, int isAccepting);
|
||||||
|
|
||||||
void UDPC_drop_connection(UDPC_HContext ctx, UDPC_ConnectionId connectionId, int dropAllWithAddr);
|
void UDPC_drop_connection(UDPC_HContext ctx, UDPC_ConnectionId connectionId, int dropAllWithAddr);
|
||||||
|
|
|
@ -225,6 +225,7 @@ int main(int argc, char **argv) {
|
||||||
unsigned int tick = 0;
|
unsigned int tick = 0;
|
||||||
unsigned int temp = 0;
|
unsigned int temp = 0;
|
||||||
unsigned int temp2, temp3;
|
unsigned int temp2, temp3;
|
||||||
|
int temp4;
|
||||||
unsigned long size;
|
unsigned long size;
|
||||||
UDPC_ConnectionId *list = NULL;
|
UDPC_ConnectionId *list = NULL;
|
||||||
unsigned int sendIds[SEND_IDS_SIZE];
|
unsigned int sendIds[SEND_IDS_SIZE];
|
||||||
|
@ -242,7 +243,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
if(!noPayload) {
|
if(!noPayload) {
|
||||||
list = UDPC_get_list_connected(context, &temp);
|
list = UDPC_get_list_connected(context, &temp);
|
||||||
if(list) {
|
|
||||||
if(sendIdsSize < temp) {
|
if(sendIdsSize < temp) {
|
||||||
while(sendIdsSize < temp) {
|
while(sendIdsSize < temp) {
|
||||||
if(sendIdsSize == SEND_IDS_SIZE) {
|
if(sendIdsSize == SEND_IDS_SIZE) {
|
||||||
|
@ -254,12 +255,18 @@ int main(int argc, char **argv) {
|
||||||
} else if(sendIdsSize > temp) {
|
} else if(sendIdsSize > temp) {
|
||||||
sendIdsSize = temp;
|
sendIdsSize = temp;
|
||||||
}
|
}
|
||||||
size = UDPC_get_queue_send_current_size(context);
|
|
||||||
temp2 = size < QUEUED_MAX_SIZE ? QUEUED_MAX_SIZE - size : 0;
|
for(unsigned int i = 0; i < temp; ++i) {
|
||||||
for(unsigned int i = 0; i < temp2; ++i) {
|
size = UDPC_get_max_queued_size() - UDPC_get_queued_size(context, list[i], &temp4);
|
||||||
temp3 = htonl(sendIds[i % temp]++);
|
if(temp4 == 0) {
|
||||||
UDPC_queue_send(context, list[i % temp], 0, &temp3, sizeof(unsigned int));
|
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);
|
UDPC_free_list_connected(list);
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
|
|
Loading…
Reference in a new issue