/* $Id$ */ /* * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com) * Copyright (C) 2003-2008 Benny Prijono * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "test.h" #include static pj_atomic_t *total_bytes; static pj_bool_t thread_quit_flag = 0; static int worker_thread(void *arg) { pj_sock_t sock = (pj_sock_t)arg; char buf[512]; pj_status_t last_recv_err = PJ_SUCCESS, last_write_err = PJ_SUCCESS; while (!thread_quit_flag) { pj_ssize_t len; pj_status_t rc; pj_sockaddr_in addr; int addrlen; len = sizeof(buf); addrlen = sizeof(addr); rc = pj_sock_recvfrom(sock, buf, &len, 0, &addr, &addrlen); if (rc != 0) { if (rc != last_recv_err) { app_perror("...recv error", rc); last_recv_err = rc; } continue; } pj_atomic_add(total_bytes, (pj_atomic_value_t)len); rc = pj_sock_sendto(sock, buf, &len, 0, &addr, addrlen); if (rc != PJ_SUCCESS) { if (rc != last_write_err) { app_perror("...send error", rc); last_write_err = rc; } continue; } } return 0; } int echo_srv_sync(void) { pj_pool_t *pool; pj_sock_t sock; pj_thread_t *thread[ECHO_SERVER_MAX_THREADS]; pj_status_t rc; int i; pool = pj_pool_create(mem, NULL, 4000, 4000, NULL); if (!pool) return -5; rc = pj_atomic_create(pool, 0, &total_bytes); if (rc != PJ_SUCCESS) { app_perror("...unable to create atomic_var", rc); return -6; } rc = app_socket(pj_AF_INET(), pj_SOCK_DGRAM(),0, ECHO_SERVER_START_PORT, &sock); if (rc != PJ_SUCCESS) { app_perror("...socket error", rc); return -10; } for (i=0; i" : ""))); if (count==20) { if (avg_bw/count > highest_bw) highest_bw = avg_bw/count; count = 0; avg_bw = 0; PJ_LOG(3,("", "Highest average bandwidth=%u KB/s", (unsigned)(highest_bw/1000))); } } PJ_UNREACHED(return 0;) }