Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Dherse/TRTP2
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien d'Herbais de Thun committed Oct 31, 2019
2 parents e1db981 + 770718b commit 76929dd
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions affinity.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
0,4,8,12
1,2,3,5,6,7,8,10,11,13,14,15
0,2
1,3
2 changes: 1 addition & 1 deletion headers/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ typedef struct client {
struct timespec connection_time;

/** The time the client was set as inactive */
struct timespec end_time;
struct timespec *end_time;

/** Total bytes transferred */
uint64_t transferred;
Expand Down
5 changes: 5 additions & 0 deletions src/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ int initialize_client(
client->last_timestamp = 0;
client->id = id;
client->active = true;
client->end_time = NULL;

client->lock = (pthread_mutex_t *) malloc(sizeof(pthread_mutex_t));
if(client->lock == NULL) {
Expand Down Expand Up @@ -160,5 +161,9 @@ void deallocate_client(client_t *client, bool dealloc_addr, bool close_file) {
deallocate_buffer(client->window);
}

if (client->end_time) {
free(client->end_time);
}

free(client);
}
13 changes: 9 additions & 4 deletions src/handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ inline __attribute__((always_inline)) void hd_run_once(
offset += pak->length;

remove = false;
} else {
} else if (pak->length == 0 && !remove) {
remove = true;
}

Expand Down Expand Up @@ -267,9 +267,14 @@ inline __attribute__((always_inline)) void hd_run_once(

bytes_to_unit(client->transferred, size, &sizem);

clock_gettime(CLOCK_MONOTONIC, &client->end_time);
client->end_time = malloc(sizeof(struct timespec));
if (!client->end_time) {
LOG("MAIN][ERROR", "Failed to allocate timespec\n");
}

clock_gettime(CLOCK_MONOTONIC, client->end_time);

double time = ((double)client->end_time.tv_sec + 1.0e-9*client->end_time.tv_nsec) -
double time = ((double)client->end_time->tv_sec + 1.0e-9*client->end_time->tv_nsec) -
((double)client->connection_time.tv_sec + 1.0e-9*client->connection_time.tv_nsec);

bytes_to_unit(client->transferred / time, speed, &speedm);
Expand Down Expand Up @@ -302,7 +307,7 @@ inline __attribute__((always_inline)) void hd_run_once(

int retval = sendmmsg(cfg->sockfd, msg, len_to_send, 0);
if (retval == -1) {
LOG("TX", "sendmmsg failed\n ");
LOG("TX", "sendmmsg failed (fd: %d, len_to_send: %d)\n ", cfg->sockfd, len_to_send);
perror("sendmmsg()");
}

Expand Down
18 changes: 11 additions & 7 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -785,9 +785,9 @@ int main(int argc, char *argv[]) {

for (i = 0; i < clients->size; i++) {
client_t *client = clients->items[i].value;
if (clients->items[i].used && !client->active) {
if (clients->items[i].used && client->end_time != NULL && !client->active) {
double time_inactive = ((double) time.tv_sec + 1.0e-9 * time.tv_nsec) -
((double) client->end_time.tv_sec + 1.0e-9 * client->end_time.tv_nsec);
((double) client->end_time->tv_sec + 1.0e-9 * client->end_time->tv_nsec);
if (time_inactive > 30.0) {
client_to_remove[len_to_remove++] = client;
}
Expand Down Expand Up @@ -834,10 +834,10 @@ int main(int argc, char *argv[]) {

for (i = 0; i < clients->size; i++) {
client_t *client = clients->items[i].value;
if (clients->items[i].used && !client->active) {
if (clients->items[i].used && client->end_time != NULL && client->active == false) {
double time_inactive = ((double) time.tv_sec + 1.0e-9 * time.tv_nsec) -
((double) client->end_time.tv_sec + 1.0e-9 * client->end_time.tv_nsec);
if (time_inactive > 30.0) {
((double) client->end_time->tv_sec + 1.0e-9 * client->end_time->tv_nsec);
if (time_inactive >= 30.0) {
client_to_remove[len_to_remove++] = client;
}
}
Expand All @@ -846,13 +846,17 @@ int main(int argc, char *argv[]) {
pthread_mutex_unlock(clients->lock);

for (i = 0; i < len_to_remove; i++) {
ht_remove(
client_t* removed = ht_remove(
clients,
client_to_remove[i]->address->sin6_port,
client_to_remove[i]->address->sin6_addr.__in6_u.__u6_addr8
);

LOG("MAIN", "Client #%d removed\n", client_to_remove[i]->id);
LOG(
"MAIN", "Client #%d removed (ok: %s)\n",
client_to_remove[i]->id,
removed ? "yes" : "no"
);

deallocate_client(client_to_remove[i], true, true);
}
Expand Down
6 changes: 2 additions & 4 deletions streams.cfg
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
0:0,1,2
1:3,4,5
2:6,7,8
3:9,10,11
0:0
1:1

0 comments on commit 76929dd

Please sign in to comment.