summaryrefslogtreecommitdiff
path: root/pjlib/src/pjlib-test/udp_echo_srv_sync.c
diff options
context:
space:
mode:
Diffstat (limited to 'pjlib/src/pjlib-test/udp_echo_srv_sync.c')
-rw-r--r--pjlib/src/pjlib-test/udp_echo_srv_sync.c56
1 files changed, 32 insertions, 24 deletions
diff --git a/pjlib/src/pjlib-test/udp_echo_srv_sync.c b/pjlib/src/pjlib-test/udp_echo_srv_sync.c
index 0e73b134..19ee702c 100644
--- a/pjlib/src/pjlib-test/udp_echo_srv_sync.c
+++ b/pjlib/src/pjlib-test/udp_echo_srv_sync.c
@@ -8,7 +8,7 @@ static pj_atomic_t *total_bytes;
static int worker_thread(void *arg)
{
pj_sock_t sock = (pj_sock_t)arg;
- char buf[1516];
+ char buf[512];
pj_status_t last_recv_err = PJ_SUCCESS, last_write_err = PJ_SUCCESS;
for (;;) {
@@ -48,9 +48,6 @@ int echo_srv_sync(void)
pj_sock_t sock;
pj_thread_t *thread[ECHO_SERVER_MAX_THREADS];
pj_status_t rc;
- pj_highprec_t last_received, avg_bw, highest_bw;
- pj_time_val last_print;
- unsigned count;
int i;
pool = pj_pool_create(mem, NULL, 4000, 4000, NULL);
@@ -83,25 +80,36 @@ int echo_srv_sync(void)
ECHO_SERVER_MAX_THREADS, ECHO_SERVER_START_PORT));
PJ_LOG(3,("", "...Press Ctrl-C to abort"));
+ echo_srv_common_loop(total_bytes);
+ return 0;
+}
+
+
+int echo_srv_common_loop(pj_atomic_t *bytes_counter)
+{
+ pj_highprec_t last_received, avg_bw, highest_bw;
+ pj_time_val last_print;
+ unsigned count;
+
last_received = 0;
pj_gettimeofday(&last_print);
avg_bw = highest_bw = 0;
- count = 0;
-
+ count = 0;
+
for (;;) {
- pj_highprec_t received, cur_received, bw;
+ pj_highprec_t received, cur_received, bw;
unsigned msec;
pj_time_val now, duration;
pj_thread_sleep(1000);
-
- received = cur_received = pj_atomic_get(total_bytes);
+
+ received = cur_received = pj_atomic_get(bytes_counter);
cur_received = cur_received - last_received;
-
+
pj_gettimeofday(&now);
duration = now;
PJ_TIME_VAL_SUB(duration, last_print);
- msec = PJ_TIME_VAL_MSEC(duration);
+ msec = PJ_TIME_VAL_MSEC(duration);
bw = cur_received;
pj_highprec_mul(bw, 1000);
@@ -113,13 +121,13 @@ int echo_srv_sync(void)
avg_bw = avg_bw + bw;
count++;
- PJ_LOG(3,("", "Synchronous UDP (%d threads): %u KB/s (avg=%u KB/s) %s",
- ECHO_SERVER_MAX_THREADS,
- (unsigned)(bw / 1000),
- (unsigned)(avg_bw / count / 1000),
- (count==20 ? "<ses avg>" : "")));
-
- if (count==20) {
+ PJ_LOG(3,("", "Synchronous UDP (%d threads): %u KB/s (avg=%u KB/s) %s",
+ ECHO_SERVER_MAX_THREADS,
+ (unsigned)(bw / 1000),
+ (unsigned)(avg_bw / count / 1000),
+ (count==20 ? "<ses avg>" : "")));
+
+ if (count==20) {
if (avg_bw/count > highest_bw)
highest_bw = avg_bw/count;
@@ -127,9 +135,9 @@ int echo_srv_sync(void)
avg_bw = 0;
PJ_LOG(3,("", "Highest average bandwidth=%u KB/s",
- (unsigned)(highest_bw/1000)));
- }
- }
-}
-
-
+ (unsigned)(highest_bw/1000)));
+ }
+ }
+}
+
+