summaryrefslogtreecommitdiff
path: root/src/tools/cbr
diff options
context:
space:
mode:
authordimitri staessens <[email protected]>2017-03-30 20:33:22 +0200
committerdimitri staessens <[email protected]>2017-03-31 11:51:33 +0200
commit7ba0fd0ce19244745c8d2512ce8a003783d914a7 (patch)
treee33ed7dae832ef96cd1997ec038764fac5d95d4c /src/tools/cbr
parentbce97d70ce43290f8351f34c763b30bfd73e6b99 (diff)
downloadouroboros-7ba0fd0ce19244745c8d2512ce8a003783d914a7.tar.gz
ouroboros-7ba0fd0ce19244745c8d2512ce8a003783d914a7.zip
lib: Revise flow allocation API
The flow_alloc_res and flow_alloc_resp calls have been removed. The flow_alloc and flow_accept calls are now both blocking and take an additional timeout argument.
Diffstat (limited to 'src/tools/cbr')
-rw-r--r--src/tools/cbr/cbr_client.c10
-rw-r--r--src/tools/cbr/cbr_server.c38
2 files changed, 19 insertions, 29 deletions
diff --git a/src/tools/cbr/cbr_client.c b/src/tools/cbr/cbr_client.c
index 16ade13d..5ec1d560 100644
--- a/src/tools/cbr/cbr_client.c
+++ b/src/tools/cbr/cbr_client.c
@@ -63,7 +63,6 @@ int client_main(char * server,
struct sigaction sig_act;
int fd = 0;
- int result = 0;
char buf[size];
long seqnr = 0;
long gap = size * 8.0 * (BILLION / (double) rate);
@@ -90,19 +89,12 @@ int client_main(char * server,
printf("Client started, duration %d, rate %lu b/s, size %d B.\n",
duration, rate, size);
- fd = flow_alloc(server, NULL);
+ fd = flow_alloc(server, NULL, NULL);
if (fd < 0) {
printf("Failed to allocate flow.\n");
return -1;
}
- result = flow_alloc_res(fd);
- if (result < 0) {
- printf("Flow allocation refused.\n");
- flow_dealloc(fd);
- return -1;
- }
-
clock_gettime(CLOCK_REALTIME, &start);
if (!flood) {
while (!stop) {
diff --git a/src/tools/cbr/cbr_server.c b/src/tools/cbr/cbr_server.c
index 9198858c..1a963a64 100644
--- a/src/tools/cbr/cbr_server.c
+++ b/src/tools/cbr/cbr_server.c
@@ -146,6 +146,8 @@ static void * worker(void * o)
pthread_mutex_lock(&fds_lock);
fds_count--;
+
+ pthread_cond_signal(&fds_signal);
pthread_mutex_unlock(&fds_lock);
}
@@ -154,8 +156,7 @@ static void * worker(void * o)
static void * listener(void * o)
{
- int client_fd = 0;
- int response = 0;
+ int fd = 0;
qosspec_t qs;
(void) o;
@@ -164,8 +165,19 @@ static void * listener(void * o)
server_settings.interval, server_settings.timeout);
while (true) {
- client_fd = flow_accept(&qs);
- if (client_fd < 0) {
+ pthread_mutex_lock(&fds_lock);
+ pthread_cleanup_push((void(*)(void *)) pthread_mutex_unlock,
+ (void *) &fds_lock);
+
+ while (fds_count == THREADS_SIZE) {
+ printf("Can't accept any more flows, waiting.\n");
+ pthread_cond_wait(&fds_signal, &fds_lock);
+ }
+
+ pthread_cleanup_pop(true);
+
+ fd = flow_accept(&qs, NULL);
+ if (fd < 0) {
printf("Failed to accept flow.\n");
break;
}
@@ -174,26 +186,12 @@ static void * listener(void * o)
pthread_mutex_lock(&fds_lock);
- response = (fds_count < THREADS_SIZE) ? 0 : -1;
-
- if (flow_alloc_resp(client_fd, response)) {
- printf("Failed to give an allocate response.\n");
- flow_dealloc(client_fd);
- pthread_mutex_unlock(&fds_lock);
- continue;
- }
-
- if (response) {
- printf("Can't accept any more flows, denying.\n");
- continue;
- }
-
fds_count++;
fds_index = (fds_index + 1) % THREADS_SIZE;
- fds[fds_index] = client_fd;
+ fds[fds_index] = fd;
- pthread_mutex_unlock(&fds_lock);
pthread_cond_signal(&fds_signal);
+ pthread_mutex_unlock(&fds_lock);
}
return 0;