1
/* $Id: pjsip-perf.c 4370 2013-02-26 05:30:00Z nanang $ */
3
* Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
4
* Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
* \page page_pjsip_perf_c Samples: SIP Performance Benchmark
25
* <b>pjsip-perf</b> is a complete program to measure the
26
* performance of PJSIP or other SIP endpoints. It consists of two
28
* - the server, to respond incoming requests, and
29
* - the client, who actively submits requests and measure the
30
* performance of the server.
32
* Both server and client part can run simultaneously, to measure the
33
* performance when both endpoints are co-located in a single program.
35
* The server accepts both INVITE and non-INVITE requests.
36
* The server exports several different types of URL, which would
37
* control how the request would be handled by the server:
38
* - URL with "0" as the user part will be handled statelessly.
39
* It should not be used with INVITE method.
40
* - URL with "1" as the user part will be handled statefully.
41
* If the request is an INVITE request, INVITE transaction will
42
* be created and 200/OK response will be sent, along with a valid
43
* SDP body. However, the SDP is just a static text body, and
44
* is not a proper SDP generated by PJMEDIA.
45
* - URL with "2" as the user part is only meaningful for INVITE
46
* requests, as it would be handled <b>call-statefully</b> by the
47
* server. For this URL, the server also would generate SDP dynamically
48
* and perform a proper SDP negotiation for the incoming call.
49
* Also for every call, server will limit the call duration to
50
* 10 seconds, on which the call will be terminated if the client
51
* doesn't hangup the call.
55
* This file is pjsip-apps/src/samples/pjsip-perf.c
57
* \includelineno pjsip-perf.c
60
/* Include all headers. */
63
#include <pjmedia-codec.h>
65
#include <pjsip_simple.h>
66
#include <pjlib-util.h>
70
#if defined(PJ_WIN32) && PJ_WIN32!=0
74
#define THIS_FILE "pjsip-perf.c"
75
#define DEFAULT_COUNT (pjsip_cfg()->tsx.max_count/2>10000?10000:pjsip_cfg()->tsx.max_count/2)
76
#define JOB_WINDOW 1000
77
#define TERMINATE_TSX(x,c)
80
#ifndef CACHING_POOL_SIZE
81
# define CACHING_POOL_SIZE (256*1024*1024)
85
/* Static message body for INVITE, when stateful processing is
86
* invoked (instead of call-stateful, where SDP is generated
89
static pj_str_t dummy_sdp_str =
92
"o=- 3360842071 3360842071 IN IP4 192.168.0.68\r\n"
94
"c=IN IP4 192.168.0.68\r\n"
96
"m=audio 4000 RTP/AVP 0 8 3 103 102 101\r\n"
97
"a=rtcp:4001 IN IP4 192.168.0.68\r\n"
98
"a=rtpmap:103 speex/16000\r\n"
99
"a=rtpmap:102 speex/8000\r\n"
100
"a=rtpmap:3 GSM/8000\r\n"
101
"a=rtpmap:0 PCMU/8000\r\n"
102
"a=rtpmap:8 PCMA/8000\r\n"
104
"a=rtpmap:101 telephone-event/8000\r\n"
105
"a=fmtp:101 0-15\r\n",
109
static pj_str_t mime_application = { "application", 11};
110
static pj_str_t mime_sdp = {"sdp", 3};
115
unsigned stateless_cnt;
116
unsigned stateful_cnt;
128
pjsip_endpoint *sip_endpt;
129
pjmedia_endpt *med_endpt;
131
pj_str_t local_contact;
133
pjmedia_sock_info skinfo[8];
135
pj_bool_t thread_quit;
136
unsigned thread_count;
137
pj_thread_t *thread[16];
140
pjmedia_sdp_session *dummy_sdp;
153
unsigned stat_max_window;
154
pj_time_val first_request;
155
pj_time_val requests_sent;
156
pj_time_val last_completion;
157
unsigned total_responses;
158
unsigned response_codes[800];
162
pj_bool_t send_trying;
163
pj_bool_t send_ringing;
165
struct srv_state prev_state;
166
struct srv_state cur_state;
174
pjsip_inv_session *inv;
175
pj_timer_entry ans_timer;
179
static void app_perror(const char *sender, const char *title,
182
char errmsg[PJ_ERR_MSG_SIZE];
184
pj_strerror(status, errmsg, sizeof(errmsg));
185
PJ_LOG(1,(sender, "%s: %s [code=%d]", title, errmsg, status));
189
/**************************************************************************
192
static pj_bool_t mod_stateless_on_rx_request(pjsip_rx_data *rdata);
194
/* Module to handle incoming requests statelessly.
196
static pjsip_module mod_stateless_server =
198
NULL, NULL, /* prev, next. */
199
{ "mod-stateless-server", 20 }, /* Name. */
201
PJSIP_MOD_PRIORITY_APPLICATION, /* Priority */
206
&mod_stateless_on_rx_request, /* on_rx_request() */
207
NULL, /* on_rx_response() */
208
NULL, /* on_tx_request. */
209
NULL, /* on_tx_response() */
210
NULL, /* on_tsx_state() */
214
static pj_bool_t mod_stateless_on_rx_request(pjsip_rx_data *rdata)
216
const pj_str_t stateless_user = { "0", 1 };
218
pjsip_sip_uri *sip_uri;
220
uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
222
/* Only want to receive SIP/SIPS scheme */
223
if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))
226
sip_uri = (pjsip_sip_uri*) uri;
228
/* Check for matching user part */
229
if (pj_strcmp(&sip_uri->user, &stateless_user)!=0)
233
* Yes, this is for us.
236
/* Ignore ACK request */
237
if (rdata->msg_info.msg->line.req.method.id == PJSIP_ACK_METHOD)
241
* Respond statelessly with 200/OK.
243
pjsip_endpt_respond_stateless(app.sip_endpt, rdata, 200, NULL,
245
app.server.cur_state.stateless_cnt++;
250
/**************************************************************************
253
static pj_bool_t mod_stateful_on_rx_request(pjsip_rx_data *rdata);
255
/* Module to handle incoming requests statefully.
257
static pjsip_module mod_stateful_server =
259
NULL, NULL, /* prev, next. */
260
{ "mod-stateful-server", 19 }, /* Name. */
262
PJSIP_MOD_PRIORITY_APPLICATION, /* Priority */
267
&mod_stateful_on_rx_request, /* on_rx_request() */
268
NULL, /* on_rx_response() */
269
NULL, /* on_tx_request. */
270
NULL, /* on_tx_response() */
271
NULL, /* on_tsx_state() */
275
static pj_bool_t mod_stateful_on_rx_request(pjsip_rx_data *rdata)
277
const pj_str_t stateful_user = { "1", 1 };
279
pjsip_sip_uri *sip_uri;
281
uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
283
/* Only want to receive SIP/SIPS scheme */
284
if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))
287
sip_uri = (pjsip_sip_uri*) uri;
289
/* Check for matching user part */
290
if (pj_strcmp(&sip_uri->user, &stateful_user)!=0)
294
* Yes, this is for us.
295
* Respond statefully with 200/OK.
297
switch (rdata->msg_info.msg->line.req.method.id) {
298
case PJSIP_INVITE_METHOD:
300
pjsip_msg_body *body;
302
if (dummy_sdp_str.slen == 0)
303
dummy_sdp_str.slen = pj_ansi_strlen(dummy_sdp_str.ptr);
305
body = pjsip_msg_body_create(rdata->tp_info.pool,
306
&mime_application, &mime_sdp,
308
pjsip_endpt_respond(app.sip_endpt, &mod_stateful_server, rdata,
309
200, NULL, NULL, body, NULL);
312
case PJSIP_ACK_METHOD:
315
pjsip_endpt_respond(app.sip_endpt, &mod_stateful_server, rdata,
316
200, NULL, NULL, NULL, NULL);
320
app.server.cur_state.stateful_cnt++;
325
/**************************************************************************
328
static pj_bool_t mod_call_on_rx_request(pjsip_rx_data *rdata);
330
/* Module to handle incoming requests callly.
332
static pjsip_module mod_call_server =
334
NULL, NULL, /* prev, next. */
335
{ "mod-call-server", 15 }, /* Name. */
337
PJSIP_MOD_PRIORITY_APPLICATION, /* Priority */
342
&mod_call_on_rx_request, /* on_rx_request() */
343
NULL, /* on_rx_response() */
344
NULL, /* on_tx_request. */
345
NULL, /* on_tx_response() */
346
NULL, /* on_tsx_state() */
350
static pj_status_t send_response(pjsip_inv_session *inv,
351
pjsip_rx_data *rdata,
353
pj_bool_t *has_initial)
355
pjsip_tx_data *tdata;
359
status = pjsip_inv_answer(inv, code, NULL, NULL, &tdata);
361
status = pjsip_inv_initial_answer(inv, rdata, code,
365
if (status != PJ_SUCCESS) {
367
status = pjsip_inv_answer(inv, PJSIP_SC_NOT_ACCEPTABLE,
370
status = pjsip_inv_initial_answer(inv, rdata,
371
PJSIP_SC_NOT_ACCEPTABLE,
375
if (status == PJ_SUCCESS) {
376
*has_initial = PJ_TRUE;
377
pjsip_inv_send_msg(inv, tdata);
379
pjsip_inv_terminate(inv, 500, PJ_FALSE);
383
*has_initial = PJ_TRUE;
385
status = pjsip_inv_send_msg(inv, tdata);
386
if (status != PJ_SUCCESS) {
387
pjsip_tx_data_dec_ref(tdata);
395
static void answer_timer_cb(pj_timer_heap_t *h, pj_timer_entry *entry)
397
struct call *call = entry->user_data;
398
pj_bool_t has_initial = PJ_TRUE;
403
send_response(call->inv, NULL, 200, &has_initial);
406
static pj_bool_t mod_call_on_rx_request(pjsip_rx_data *rdata)
408
const pj_str_t call_user = { "2", 1 };
410
pjsip_sip_uri *sip_uri;
413
pjmedia_sdp_session *sdp;
414
pjsip_tx_data *tdata;
415
pj_bool_t has_initial = PJ_FALSE;
418
uri = pjsip_uri_get_uri(rdata->msg_info.msg->line.req.uri);
420
/* Only want to receive SIP/SIPS scheme */
421
if (!PJSIP_URI_SCHEME_IS_SIP(uri) && !PJSIP_URI_SCHEME_IS_SIPS(uri))
424
sip_uri = (pjsip_sip_uri*) uri;
426
/* Only want to handle INVITE requests. */
427
if (rdata->msg_info.msg->line.req.method.id != PJSIP_INVITE_METHOD) {
432
/* Check for matching user part. Incoming requests will be handled
433
* call-statefully if:
434
* - user part is "2", or
435
* - user part is not "0" nor "1" and method is INVITE.
437
if (pj_strcmp(&sip_uri->user, &call_user) == 0 ||
438
sip_uri->user.slen != 1 ||
439
(*sip_uri->user.ptr != '0' && *sip_uri->user.ptr != '1'))
448
/* Verify that we can handle the request. */
450
unsigned options = 0;
451
status = pjsip_inv_verify_request(rdata, &options, NULL, NULL,
452
app.sip_endpt, &tdata);
453
if (status != PJ_SUCCESS) {
456
* No we can't handle the incoming INVITE request.
460
pjsip_response_addr res_addr;
462
pjsip_get_response_addr(tdata->pool, rdata, &res_addr);
463
pjsip_endpt_send_response(app.sip_endpt, &res_addr, tdata,
468
/* Respond with 500 (Internal Server Error) */
469
pjsip_endpt_respond_stateless(app.sip_endpt, rdata, 500, NULL,
477
/* Create UAS dialog */
478
status = pjsip_dlg_create_uas( pjsip_ua_instance(), rdata,
479
&app.local_contact, &dlg);
480
if (status != PJ_SUCCESS) {
481
const pj_str_t reason = pj_str("Unable to create dialog");
482
pjsip_endpt_respond_stateless( app.sip_endpt, rdata,
488
/* Alloc call structure. */
489
call = pj_pool_zalloc(dlg->pool, sizeof(struct call));
491
/* Create SDP from PJMEDIA */
493
status = pjmedia_endpt_create_sdp(app.med_endpt, rdata->tp_info.pool,
494
app.skinfo_cnt, app.skinfo,
500
/* Create UAS invite session */
501
status = pjsip_inv_create_uas( dlg, rdata, sdp, 0, &call->inv);
502
if (status != PJ_SUCCESS) {
503
pjsip_dlg_create_response(dlg, rdata, 500, NULL, &tdata);
504
pjsip_dlg_send_response(dlg, pjsip_rdata_get_tsx(rdata), tdata);
508
/* Send 100/Trying if needed */
509
if (app.server.send_trying) {
510
status = send_response(call->inv, rdata, 100, &has_initial);
511
if (status != PJ_SUCCESS)
515
/* Send 180/Ringing if needed */
516
if (app.server.send_ringing) {
517
status = send_response(call->inv, rdata, 180, &has_initial);
518
if (status != PJ_SUCCESS)
522
/* Simulate call processing delay */
523
if (app.server.delay) {
526
call->ans_timer.id = 1;
527
call->ans_timer.user_data = call;
528
call->ans_timer.cb = &answer_timer_cb;
531
delay.msec = app.server.delay;
532
pj_time_val_normalize(&delay);
534
pjsip_endpt_schedule_timer(app.sip_endpt, &call->ans_timer, &delay);
537
/* Send the 200 response immediately . */
538
status = send_response(call->inv, rdata, 200, &has_initial);
539
PJ_ASSERT_ON_FAIL(status == PJ_SUCCESS, return PJ_TRUE);
543
app.server.cur_state.call_cnt++;
550
/**************************************************************************
551
* Default handler when incoming request is not handled by any other
554
static pj_bool_t mod_responder_on_rx_request(pjsip_rx_data *rdata);
556
/* Module to handle incoming requests statelessly.
558
static pjsip_module mod_responder =
560
NULL, NULL, /* prev, next. */
561
{ "mod-responder", 13 }, /* Name. */
563
PJSIP_MOD_PRIORITY_APPLICATION+1, /* Priority */
568
&mod_responder_on_rx_request, /* on_rx_request() */
569
NULL, /* on_rx_response() */
570
NULL, /* on_tx_request. */
571
NULL, /* on_tx_response() */
572
NULL, /* on_tsx_state() */
576
static pj_bool_t mod_responder_on_rx_request(pjsip_rx_data *rdata)
578
const pj_str_t reason = pj_str("Not expecting request at this URI");
581
* Respond any requests (except ACK!) with 500.
583
if (rdata->msg_info.msg->line.req.method.id != PJSIP_ACK_METHOD) {
584
pjsip_endpt_respond_stateless(app.sip_endpt, rdata, 500, &reason,
593
/*****************************************************************************
594
* Below is a simple module to log all incoming and outgoing SIP messages
598
/* Notification on incoming messages */
599
static pj_bool_t logger_on_rx_msg(pjsip_rx_data *rdata)
601
PJ_LOG(3,(THIS_FILE, "RX %d bytes %s from %s %s:%d:\n"
605
pjsip_rx_data_get_info(rdata),
606
rdata->tp_info.transport->type_name,
607
rdata->pkt_info.src_name,
608
rdata->pkt_info.src_port,
609
(int)rdata->msg_info.len,
610
rdata->msg_info.msg_buf));
612
/* Always return false, otherwise messages will not get processed! */
616
/* Notification on outgoing messages */
617
static pj_status_t logger_on_tx_msg(pjsip_tx_data *tdata)
621
* tp_info field is only valid after outgoing messages has passed
622
* transport layer. So don't try to access tp_info when the module
623
* has lower priority than transport layer.
626
PJ_LOG(3,(THIS_FILE, "TX %d bytes %s to %s %s:%d:\n"
629
(tdata->buf.cur - tdata->buf.start),
630
pjsip_tx_data_get_info(tdata),
631
tdata->tp_info.transport->type_name,
632
tdata->tp_info.dst_name,
633
tdata->tp_info.dst_port,
634
(int)(tdata->buf.cur - tdata->buf.start),
637
/* Always return success, otherwise message will not get sent! */
641
/* The module instance. */
642
static pjsip_module msg_logger =
644
NULL, NULL, /* prev, next. */
645
{ "mod-siprtp-log", 14 }, /* Name. */
647
PJSIP_MOD_PRIORITY_TRANSPORT_LAYER-1,/* Priority */
652
&logger_on_rx_msg, /* on_rx_request() */
653
&logger_on_rx_msg, /* on_rx_response() */
654
&logger_on_tx_msg, /* on_tx_request. */
655
&logger_on_tx_msg, /* on_tx_response() */
656
NULL, /* on_tsx_state() */
662
/**************************************************************************
666
static pj_bool_t mod_test_on_rx_response(pjsip_rx_data *rdata);
668
static void call_on_media_update( pjsip_inv_session *inv,
670
static void call_on_state_changed( pjsip_inv_session *inv,
672
static void call_on_forked(pjsip_inv_session *inv, pjsip_event *e);
675
/* Module to handle incoming requests callly.
677
static pjsip_module mod_test =
679
NULL, NULL, /* prev, next. */
680
{ "mod-test", 8 }, /* Name. */
682
PJSIP_MOD_PRIORITY_APPLICATION, /* Priority */
687
NULL, /* on_rx_request() */
688
&mod_test_on_rx_response, /* on_rx_response() */
689
NULL, /* on_tx_request. */
690
NULL, /* on_tx_response() */
691
NULL, /* on_tsx_state() */
695
static void report_completion(int status_code)
697
app.client.job_finished++;
698
if (status_code >= 200 && status_code < 800)
699
app.client.response_codes[status_code]++;
700
app.client.total_responses++;
701
pj_gettimeofday(&app.client.last_completion);
705
/* Handler when response is received. */
706
static pj_bool_t mod_test_on_rx_response(pjsip_rx_data *rdata)
708
if (pjsip_rdata_get_tsx(rdata) == NULL) {
709
report_completion(rdata->msg_info.msg->line.status.code);
719
static pj_status_t create_app(void)
724
if (status != PJ_SUCCESS) {
725
app_perror(THIS_FILE, "Error initializing pjlib", status);
729
/* init PJLIB-UTIL: */
730
status = pjlib_util_init();
731
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
733
/* Must create a pool factory before we can allocate any memory. */
734
pj_caching_pool_init(&app.cp, &pj_pool_factory_default_policy,
737
/* Create application pool for misc. */
738
app.pool = pj_pool_create(&app.cp.factory, "app", 1000, 1000, NULL);
740
/* Create the endpoint: */
741
status = pjsip_endpt_create(&app.cp.factory, pj_gethostname()->ptr,
743
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
753
static pj_status_t init_sip()
755
pj_status_t status = -1;
757
/* Add UDP/TCP transport. */
760
pjsip_host_port addrname;
761
const char *transport_type = NULL;
763
pj_bzero(&addr, sizeof(addr));
764
addr.sin_family = pj_AF_INET();
765
addr.sin_addr.s_addr = 0;
766
addr.sin_port = pj_htons((pj_uint16_t)app.local_port);
768
if (app.local_addr.slen) {
769
addrname.host = app.local_addr;
770
addrname.port = 5060;
772
if (app.local_port != 0)
773
addrname.port = app.local_port;
776
#if defined(PJ_HAS_TCP) && PJ_HAS_TCP!=0
777
} else if (app.use_tcp) {
778
pj_sockaddr_in local_addr;
779
pjsip_tpfactory *tpfactory;
781
transport_type = "tcp";
782
pj_sockaddr_in_init(&local_addr, 0, (pj_uint16_t)app.local_port);
783
status = pjsip_tcp_transport_start(app.sip_endpt, &local_addr,
784
app.thread_count, &tpfactory);
785
if (status == PJ_SUCCESS) {
786
app.local_addr = tpfactory->addr_name.host;
787
app.local_port = tpfactory->addr_name.port;
793
transport_type = "udp";
794
status = pjsip_udp_transport_start(app.sip_endpt, &addr,
795
(app.local_addr.slen ? &addrname:NULL),
796
app.thread_count, &tp);
797
if (status == PJ_SUCCESS) {
798
app.local_addr = tp->local_name.host;
799
app.local_port = tp->local_name.port;
803
if (status != PJ_SUCCESS) {
804
app_perror(THIS_FILE, "Unable to start transport", status);
808
app.local_uri.ptr = pj_pool_alloc(app.pool, 128);
809
app.local_uri.slen = pj_ansi_sprintf(app.local_uri.ptr,
810
"<sip:pjsip-perf@%.*s:%d;transport=%s>",
811
(int)app.local_addr.slen,
816
app.local_contact = app.local_uri;
820
* Init transaction layer.
821
* This will create/initialize transaction hash tables etc.
823
status = pjsip_tsx_layer_init_module(app.sip_endpt);
824
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
826
/* Initialize UA layer. */
827
status = pjsip_ua_init_module( app.sip_endpt, NULL );
828
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
830
/* Initialize 100rel support */
831
status = pjsip_100rel_init_module(app.sip_endpt);
832
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
834
/* Init invite session module. */
836
pjsip_inv_callback inv_cb;
838
/* Init the callback for INVITE session: */
839
pj_bzero(&inv_cb, sizeof(inv_cb));
840
inv_cb.on_state_changed = &call_on_state_changed;
841
inv_cb.on_new_session = &call_on_forked;
842
inv_cb.on_media_update = &call_on_media_update;
844
/* Initialize invite session module: */
845
status = pjsip_inv_usage_init(app.sip_endpt, &inv_cb);
846
PJ_ASSERT_RETURN(status == PJ_SUCCESS, 1);
849
/* Register our module to receive incoming requests. */
850
status = pjsip_endpt_register_module( app.sip_endpt, &mod_test);
851
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
854
/* Register stateless server module */
855
status = pjsip_endpt_register_module( app.sip_endpt, &mod_stateless_server);
856
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
858
/* Register default responder module */
859
status = pjsip_endpt_register_module( app.sip_endpt, &mod_responder);
860
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
862
/* Register stateless server module */
863
status = pjsip_endpt_register_module( app.sip_endpt, &mod_stateful_server);
864
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
867
/* Register call server module */
868
status = pjsip_endpt_register_module( app.sip_endpt, &mod_call_server);
869
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
880
static void destroy_app()
885
for (i=0; i<app.thread_count; ++i) {
887
pj_thread_join(app.thread[i]);
888
pj_thread_destroy(app.thread[i]);
889
app.thread[i] = NULL;
894
pjsip_endpt_destroy(app.sip_endpt);
895
app.sip_endpt = NULL;
899
pj_pool_release(app.pool);
901
PJ_LOG(3,(THIS_FILE, "Peak memory size: %uMB",
902
app.cp.peak_used_size / 1000000));
903
pj_caching_pool_destroy(&app.cp);
914
static pj_status_t init_media()
917
pj_uint16_t rtp_port;
921
/* Initialize media endpoint so that at least error subsystem is properly
924
status = pjmedia_endpt_create(&app.cp.factory,
925
pjsip_endpt_get_ioqueue(app.sip_endpt), 0,
927
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
930
/* Must register all codecs to be supported */
931
pjmedia_codec_register_audio_codecs(app.med_endpt, NULL);
933
/* Init dummy socket addresses */
935
for (i=0, rtp_port=4000; i<PJ_ARRAY_SIZE(app.skinfo); ++i, rtp_port+=2) {
936
pjmedia_sock_info *skinfo;
938
skinfo = &app.skinfo[i];
940
pj_sockaddr_in_init(&skinfo->rtp_addr_name.ipv4, &app.local_addr,
941
(pj_uint16_t)rtp_port);
942
pj_sockaddr_in_init(&skinfo->rtp_addr_name.ipv4, &app.local_addr,
943
(pj_uint16_t)(rtp_port+1));
947
/* Generate dummy SDP */
948
dummy_sdp_str.slen = pj_ansi_strlen(dummy_sdp_str.ptr);
949
status = pjmedia_sdp_parse(app.pool, dummy_sdp_str.ptr, dummy_sdp_str.slen,
951
if (status != PJ_SUCCESS) {
952
app_perror(THIS_FILE, "Error parsing dummy SDP", status);
962
/* This is notification from the call about media negotiation
963
* status. This is called for client calls only.
965
static void call_on_media_update( pjsip_inv_session *inv,
968
if (status != PJ_SUCCESS) {
969
pjsip_tx_data *tdata;
972
status = pjsip_inv_end_session(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE,
974
if (status == PJ_SUCCESS && tdata)
975
status = pjsip_inv_send_msg(inv, tdata);
980
/* This is notification from the call when the call state has changed.
981
* This is called for client calls only.
983
static void call_on_state_changed( pjsip_inv_session *inv,
988
/* Bail out if the session has been counted before */
989
if (inv->mod_data[mod_test.id] != NULL)
992
/* Bail out if this is not an outgoing call */
993
if (inv->role != PJSIP_UAC_ROLE)
996
if (inv->state == PJSIP_INV_STATE_CONFIRMED) {
997
pjsip_tx_data *tdata;
1000
//report_completion(200);
1001
//inv->mod_data[mod_test.id] = (void*)1;
1003
status = pjsip_inv_end_session(inv, PJSIP_SC_OK, NULL, &tdata);
1004
if (status == PJ_SUCCESS && tdata)
1005
status = pjsip_inv_send_msg(inv, tdata);
1007
} else if (inv->state == PJSIP_INV_STATE_DISCONNECTED) {
1008
report_completion(inv->cause);
1009
inv->mod_data[mod_test.id] = (void*)1;
1014
/* Not implemented for now */
1015
static void call_on_forked(pjsip_inv_session *inv, pjsip_event *e)
1024
* Make outgoing call.
1026
static pj_status_t make_call(const pj_str_t *dst_uri)
1030
pjmedia_sdp_session *sdp;
1031
pjsip_tx_data *tdata;
1035
/* Create UAC dialog */
1036
status = pjsip_dlg_create_uac( pjsip_ua_instance(),
1037
&app.local_uri, /* local URI */
1038
&app.local_contact, /* local Contact */
1039
dst_uri, /* remote URI */
1040
dst_uri, /* remote target */
1042
if (status != PJ_SUCCESS) {
1047
call = pj_pool_zalloc(dlg->pool, sizeof(struct call));
1051
status = pjmedia_endpt_create_sdp(app.med_endpt, dlg->pool, 1,
1053
if (status != PJ_SUCCESS) {
1054
pjsip_dlg_terminate(dlg);
1058
sdp = app.dummy_sdp;
1060
/* Create the INVITE session. */
1061
status = pjsip_inv_create_uac( dlg, sdp, 0, &call->inv);
1062
if (status != PJ_SUCCESS) {
1063
pjsip_dlg_terminate(dlg);
1068
/* Create initial INVITE request.
1069
* This INVITE request will contain a perfectly good request and
1070
* an SDP body as well.
1072
status = pjsip_inv_invite(call->inv, &tdata);
1073
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
1076
/* Send initial INVITE request.
1077
* From now on, the invite session's state will be reported to us
1078
* via the invite session callbacks.
1080
status = pjsip_inv_send_msg(call->inv, tdata);
1081
PJ_ASSERT_RETURN(status == PJ_SUCCESS, status);
1089
* Verify that valid SIP url is given.
1091
static pj_status_t verify_sip_url(const char *c_url)
1096
int len = (c_url ? pj_ansi_strlen(c_url) : 0);
1098
if (!len) return -1;
1100
pool = pj_pool_create(&app.cp.factory, "check%p", 1024, 0, NULL);
1101
if (!pool) return PJ_ENOMEM;
1103
url = pj_pool_alloc(pool, len+1);
1104
pj_ansi_strcpy(url, c_url);
1107
p = pjsip_parse_uri(pool, url, len, 0);
1108
if (!p || pj_stricmp2(pjsip_uri_get_scheme(p), "sip") != 0)
1111
pj_pool_release(pool);
1116
static void usage(void)
1120
" pjsip-perf [OPTIONS] -- to start as server\n"
1121
" pjsip-perf [OPTIONS] URL -- to call server (possibly itself)\n"
1124
" URL The SIP URL to be contacted.\n"
1127
" --method=METHOD, -m Set test method (set to INVITE for call benchmark)\n"
1128
" [default: OPTIONS]\n"
1129
" --count=N, -n Set total number of requests to initiate\n"
1131
" --stateless, -s Set to operate in stateless mode\n"
1132
" [default: stateful]\n"
1133
" --timeout=SEC, -t Set client timeout [default=60 sec]\n"
1134
" --window=COUNT, -w Set maximum outstanding job [default: %d]\n"
1136
"SDP options (client and server):\n"
1137
" --real-sdp Generate real SDP from pjmedia, and also perform\n"
1138
" proper SDP negotiation [default: dummy]\n"
1140
"Client and Server options:\n"
1141
" --local-port=PORT, -p Set local port [default: 5060]\n"
1142
" --use-tcp, -T Use TCP instead of UDP. Note that when started as\n"
1143
" client, you must add ;transport=tcp parameter to URL\n"
1145
" --thread-count=N Set number of worker threads [default=1]\n"
1146
" --trying Send 100/Trying response (server, default no)\n"
1147
" --ringing Send 180/Ringing response (server, default no)\n"
1148
" --delay=MS, -d Delay answering call by MS (server, default no)\n"
1151
" --help, -h Display this screen\n"
1152
" --verbose, -v Verbose logging (put more than once for even more)\n"
1154
"When started as server, pjsip-perf can be contacted on the following URIs:\n"
1155
" - sip:0@server-addr To handle requests statelessly.\n"
1156
" - sip:1@server-addr To handle requests statefully.\n"
1157
" - sip:2@server-addr To handle INVITE call.\n",
1158
DEFAULT_COUNT, JOB_WINDOW);
1162
static int my_atoi(const char *s)
1164
pj_str_t ss = pj_str((char*)s);
1165
return pj_strtoul(&ss);
1169
static pj_status_t init_options(int argc, char *argv[])
1171
enum { OPT_THREAD_COUNT = 1, OPT_REAL_SDP, OPT_TRYING, OPT_RINGING };
1172
struct pj_getopt_option long_options[] = {
1173
{ "local-port", 1, 0, 'p' },
1174
{ "count", 1, 0, 'c' },
1175
{ "thread-count", 1, 0, OPT_THREAD_COUNT },
1176
{ "method", 1, 0, 'm' },
1177
{ "help", 0, 0, 'h' },
1178
{ "stateless", 0, 0, 's' },
1179
{ "timeout", 1, 0, 't' },
1180
{ "real-sdp", 0, 0, OPT_REAL_SDP },
1181
{ "verbose", 0, 0, 'v' },
1182
{ "use-tcp", 0, 0, 'T' },
1183
{ "window", 1, 0, 'w' },
1184
{ "delay", 1, 0, 'd' },
1185
{ "trying", 0, 0, OPT_TRYING},
1186
{ "ringing", 0, 0, OPT_RINGING},
1192
/* Init default application configs */
1193
app.local_port = 5060;
1194
app.thread_count = 1;
1195
app.client.job_count = DEFAULT_COUNT;
1196
app.client.method = *pjsip_get_options_method();
1197
app.client.job_window = c = JOB_WINDOW;
1198
app.client.timeout = 60;
1204
while((c=pj_getopt_long(argc,argv, "p:c:m:t:w:d:hsv",
1205
long_options, &option_index))!=-1)
1209
app.local_port = my_atoi(pj_optarg);
1210
if (app.local_port < 0 || app.local_port > 65535) {
1211
PJ_LOG(3,(THIS_FILE, "Invalid --local-port %s", pj_optarg));
1217
app.client.job_count = my_atoi(pj_optarg);
1218
if (app.client.job_count < 0) {
1219
PJ_LOG(3,(THIS_FILE, "Invalid --local-port %s", pj_optarg));
1222
if (app.client.job_count > pjsip_cfg()->tsx.max_count)
1223
PJ_LOG(3,(THIS_FILE,
1224
"Warning: --count value (%d) exceeds maximum "
1225
"transaction count (%d)", app.client.job_count,
1226
pjsip_cfg()->tsx.max_count));
1229
case OPT_THREAD_COUNT:
1230
app.thread_count = my_atoi(pj_optarg);
1231
if (app.thread_count < 1 || app.thread_count > 16) {
1232
PJ_LOG(3,(THIS_FILE, "Invalid --thread-count %s", pj_optarg));
1239
pj_str_t temp = pj_str((char*)pj_optarg);
1240
pjsip_method_init_np(&app.client.method, &temp);
1249
app.client.stateless = PJ_TRUE;
1261
app.client.timeout = my_atoi(pj_optarg);
1262
if (app.client.timeout < 0 || app.client.timeout > 600) {
1263
PJ_LOG(3,(THIS_FILE, "Invalid --timeout %s", pj_optarg));
1269
app.client.job_window = my_atoi(pj_optarg);
1270
if (app.client.job_window <= 0) {
1271
PJ_LOG(3,(THIS_FILE, "Invalid --window %s", pj_optarg));
1277
app.use_tcp = PJ_TRUE;
1281
app.server.delay = my_atoi(pj_optarg);
1282
if (app.server.delay > 3600) {
1283
PJ_LOG(3,(THIS_FILE, "I think --delay %s is too long",
1290
app.server.send_trying = 1;
1294
app.server.send_ringing = 1;
1298
PJ_LOG(1,(THIS_FILE,
1299
"Invalid argument. Use --help to see help"));
1304
if (pj_optind != argc) {
1306
if (verify_sip_url(argv[pj_optind]) != PJ_SUCCESS) {
1307
PJ_LOG(1,(THIS_FILE, "Invalid SIP URI %s", argv[pj_optind]));
1310
app.client.dst_uri = pj_str(argv[pj_optind]);
1316
if (pj_optind != argc) {
1317
PJ_LOG(1,(THIS_FILE, "Error: unknown options %s", argv[pj_optind]));
1325
/* Send one stateless request */
1326
static pj_status_t submit_stateless_job(void)
1328
pjsip_tx_data *tdata;
1331
status = pjsip_endpt_create_request(app.sip_endpt, &app.client.method,
1332
&app.client.dst_uri, &app.local_uri,
1333
&app.client.dst_uri, &app.local_contact,
1334
NULL, -1, NULL, &tdata);
1335
if (status != PJ_SUCCESS) {
1336
app_perror(THIS_FILE, "Error creating request", status);
1337
report_completion(701);
1341
status = pjsip_endpt_send_request_stateless(app.sip_endpt, tdata, NULL,
1343
if (status != PJ_SUCCESS) {
1344
pjsip_tx_data_dec_ref(tdata);
1345
app_perror(THIS_FILE, "Error sending stateless request", status);
1346
report_completion(701);
1354
/* This callback is called when client transaction state has changed */
1355
static void tsx_completion_cb(void *token, pjsip_event *event)
1357
pjsip_transaction *tsx;
1359
PJ_UNUSED_ARG(token);
1361
if (event->type != PJSIP_EVENT_TSX_STATE)
1364
tsx = event->body.tsx_state.tsx;
1366
if (tsx->mod_data[mod_test.id] != NULL) {
1367
/* This transaction has been calculated before */
1371
if (tsx->state==PJSIP_TSX_STATE_TERMINATED) {
1372
report_completion(tsx->status_code);
1373
tsx->mod_data[mod_test.id] = (void*)1;
1375
else if (tsx->method.id == PJSIP_INVITE_METHOD &&
1376
tsx->state == PJSIP_TSX_STATE_CONFIRMED) {
1378
report_completion(tsx->status_code);
1379
tsx->mod_data[mod_test.id] = (void*)1;
1381
} else if (tsx->state == PJSIP_TSX_STATE_COMPLETED) {
1383
report_completion(tsx->status_code);
1384
tsx->mod_data[mod_test.id] = (void*)1;
1386
TERMINATE_TSX(tsx, tsx->status_code);
1391
/* Send one stateful request */
1392
static pj_status_t submit_job(void)
1394
pjsip_tx_data *tdata;
1397
status = pjsip_endpt_create_request(app.sip_endpt, &app.client.method,
1398
&app.client.dst_uri, &app.local_uri,
1399
&app.client.dst_uri, &app.local_contact,
1400
NULL, -1, NULL, &tdata);
1401
if (status != PJ_SUCCESS) {
1402
app_perror(THIS_FILE, "Error creating request", status);
1403
report_completion(701);
1407
status = pjsip_endpt_send_request(app.sip_endpt, tdata, -1, NULL,
1408
&tsx_completion_cb);
1409
if (status != PJ_SUCCESS) {
1410
app_perror(THIS_FILE, "Error sending stateful request", status);
1411
//should have been reported by tsx_completion_cb().
1412
//report_completion(701);
1413
//No longer necessary (r777)
1414
//pjsip_tx_data_dec_ref(tdata);
1420
/* Client worker thread */
1421
static int client_thread(void *arg)
1423
pj_time_val end_time, last_report, now;
1424
unsigned thread_index = (unsigned)(long)arg;
1425
unsigned cycle = 0, last_cycle = 0;
1427
pj_thread_sleep(100);
1429
pj_gettimeofday(&end_time);
1430
end_time.sec += app.client.timeout;
1432
pj_gettimeofday(&last_report);
1434
if (app.client.first_request.sec == 0) {
1435
pj_gettimeofday(&app.client.first_request);
1438
/* Submit all jobs */
1439
while (app.client.job_submitted < app.client.job_count && !app.thread_quit){
1440
pj_time_val timeout = { 0, 1 };
1445
/* Calculate current outstanding job */
1446
outstanding = app.client.job_submitted - app.client.job_finished;
1448
/* Update stats on max outstanding jobs */
1449
if (outstanding > (int)app.client.stat_max_window)
1450
app.client.stat_max_window = outstanding;
1452
/* Wait if there are more pending jobs than allowed in the
1453
* window. But spawn a new job anyway if no events are happening
1454
* after we wait for some time.
1456
for (i=0; outstanding > (int)app.client.job_window && i<1000; ++i) {
1457
pj_time_val wait = { 0, 500 };
1460
pjsip_endpt_handle_events2(app.sip_endpt, &wait, &count);
1461
outstanding = app.client.job_submitted - app.client.job_finished;
1470
/* Submit one job */
1471
if (app.client.method.id == PJSIP_INVITE_METHOD) {
1472
status = make_call(&app.client.dst_uri);
1473
} else if (app.client.stateless) {
1474
status = submit_stateless_job();
1476
status = submit_job();
1479
++app.client.job_submitted;
1483
pjsip_endpt_handle_events2(app.sip_endpt, &timeout, NULL);
1485
/* Check for time out, also print report */
1486
if (cycle - last_cycle >= 500) {
1487
pj_gettimeofday(&now);
1488
if (PJ_TIME_VAL_GTE(now, end_time)) {
1494
if (thread_index == 0 && now.sec-last_report.sec >= 2) {
1495
printf("\r%d jobs started, %d completed... ",
1496
app.client.job_submitted, app.client.job_finished);
1503
if (app.client.requests_sent.sec == 0) {
1504
pj_gettimeofday(&app.client.requests_sent);
1508
if (thread_index == 0) {
1509
printf("\r%d jobs started, %d completed%s\n",
1510
app.client.job_submitted, app.client.job_finished,
1511
(app.client.job_submitted!=app.client.job_finished ?
1512
", waiting..." : ".") );
1516
/* Wait until all jobs completes, or timed out */
1517
pj_gettimeofday(&now);
1518
while (PJ_TIME_VAL_LT(now, end_time) &&
1519
app.client.job_finished < app.client.job_count &&
1522
pj_time_val timeout = { 0, 1 };
1525
for (i=0; i<1000; ++i) {
1528
pjsip_endpt_handle_events2(app.sip_endpt, &timeout, &count);
1533
pj_gettimeofday(&now);
1536
/* Wait couple of seconds to let jobs completes (e.g. ACKs to be sent) */
1537
pj_gettimeofday(&now);
1540
while (PJ_TIME_VAL_LT(now, end_time))
1542
pj_time_val timeout = { 0, 1 };
1545
for (i=0; i<1000; ++i) {
1548
pjsip_endpt_handle_events2(app.sip_endpt, &timeout, &count);
1553
pj_gettimeofday(&now);
1560
static const char *good_number(char *buf, pj_int32_t val)
1563
pj_ansi_sprintf(buf, "%d", val);
1564
} else if (val < 1000000) {
1565
pj_ansi_sprintf(buf, "%d.%dK",
1567
(val % 1000) / 100);
1569
pj_ansi_sprintf(buf, "%d.%02dM",
1571
(val % 1000000) / 10000);
1578
static int server_thread(void *arg)
1580
pj_time_val timeout = { 0, 1 };
1581
unsigned thread_index = (unsigned)(long)arg;
1582
pj_time_val last_report, next_report;
1584
pj_gettimeofday(&last_report);
1585
next_report = last_report;
1588
while (!app.thread_quit) {
1592
for (i=0; i<100; ++i) {
1594
pjsip_endpt_handle_events2(app.sip_endpt, &timeout, &count);
1599
if (thread_index == 0) {
1600
pj_gettimeofday(&now);
1602
if (PJ_TIME_VAL_GTE(now, next_report)) {
1605
unsigned stateless, stateful, call;
1606
char str_stateless[32], str_stateful[32], str_call[32];
1609
PJ_TIME_VAL_SUB(tmp, last_report);
1610
msec = PJ_TIME_VAL_MSEC(tmp);
1613
next_report = last_report;
1616
stateless = app.server.cur_state.stateless_cnt - app.server.prev_state.stateless_cnt;
1617
stateful = app.server.cur_state.stateful_cnt - app.server.prev_state.stateful_cnt;
1618
call = app.server.cur_state.call_cnt - app.server.prev_state.call_cnt;
1620
good_number(str_stateless, app.server.cur_state.stateless_cnt);
1621
good_number(str_stateful, app.server.cur_state.stateful_cnt);
1622
good_number(str_call, app.server.cur_state.call_cnt);
1624
printf("Total(rate): stateless:%s (%d/s), statefull:%s (%d/s), call:%s (%d/s) \r",
1625
str_stateless, stateless*1000/msec,
1626
str_stateful, stateful*1000/msec,
1627
str_call, call*1000/msec);
1630
app.server.prev_state = app.server.cur_state;
1638
static void write_report(const char *msg)
1642
#if defined(PJ_WIN32) && PJ_WIN32!=0
1643
OutputDebugString(msg);
1644
OutputDebugString("\n");
1649
int main(int argc, char *argv[])
1651
static char report[1024];
1653
printf("PJSIP Performance Measurement Tool v%s\n"
1654
"(c)2006 pjsip.org\n\n",
1657
if (create_app() != 0)
1660
if (init_options(argc, argv) != 0)
1663
if (init_sip() != 0)
1666
if (init_media() != 0)
1669
pj_log_set_level(app.log_level);
1671
if (app.log_level > 4) {
1672
pjsip_endpt_register_module(app.sip_endpt, &msg_logger);
1677
if (app.client.dst_uri.slen != 0) {
1678
if (app.client.method.id == PJSIP_INVITE_METHOD) {
1679
if (app.client.stateless) {
1680
PJ_LOG(3,(THIS_FILE,
1681
"Info: --stateless option makes no sense for INVITE,"
1690
if (app.client.dst_uri.slen) {
1694
unsigned msec_req, msec_res;
1697
/* Get the job name */
1698
if (app.client.method.id == PJSIP_INVITE_METHOD) {
1699
pj_ansi_strcpy(test_type, "INVITE calls");
1700
} else if (app.client.stateless) {
1701
pj_ansi_sprintf(test_type, "stateless %.*s requests",
1702
(int)app.client.method.name.slen,
1703
app.client.method.name.ptr);
1705
pj_ansi_sprintf(test_type, "stateful %.*s requests",
1706
(int)app.client.method.name.slen,
1707
app.client.method.name.ptr);
1711
printf("Sending %d %s to '%.*s' with %d maximum outstanding jobs, please wait..\n",
1712
app.client.job_count, test_type,
1713
(int)app.client.dst_uri.slen, app.client.dst_uri.ptr,
1714
app.client.job_window);
1716
for (i=0; i<app.thread_count; ++i) {
1717
status = pj_thread_create(app.pool, NULL, &client_thread,
1718
(void*)(long)i, 0, 0, &app.thread[i]);
1719
if (status != PJ_SUCCESS) {
1720
app_perror(THIS_FILE, "Unable to create thread", status);
1725
for (i=0; i<app.thread_count; ++i) {
1726
pj_thread_join(app.thread[i]);
1727
app.thread[i] = NULL;
1730
if (app.client.last_completion.sec) {
1731
pj_time_val duration;
1732
duration = app.client.last_completion;
1733
PJ_TIME_VAL_SUB(duration, app.client.first_request);
1734
msec_res = PJ_TIME_VAL_MSEC(duration);
1736
msec_res = app.client.timeout * 1000;
1739
if (msec_res == 0) msec_res = 1;
1741
if (app.client.requests_sent.sec) {
1742
pj_time_val duration;
1743
duration = app.client.requests_sent;
1744
PJ_TIME_VAL_SUB(duration, app.client.first_request);
1745
msec_req = PJ_TIME_VAL_MSEC(duration);
1747
msec_req = app.client.timeout * 1000;
1750
if (msec_req == 0) msec_req = 1;
1752
if (app.client.job_submitted < app.client.job_count)
1753
puts("\ntimed-out!\n");
1758
report, sizeof(report),
1759
"Total %d %s sent in %d ms at rate of %d/sec\n"
1760
"Total %d responses receieved in %d ms at rate of %d/sec:",
1761
app.client.job_submitted, test_type, msec_req,
1762
app.client.job_submitted * 1000 / msec_req,
1763
app.client.total_responses, msec_res,
1764
app.client.total_responses*1000/msec_res);
1765
write_report(report);
1767
/* Print detailed response code received */
1768
pj_ansi_sprintf(report, "\nDetailed responses received:");
1769
write_report(report);
1771
for (i=0; i<PJ_ARRAY_SIZE(app.client.response_codes); ++i) {
1772
const pj_str_t *reason;
1774
if (app.client.response_codes[i] == 0)
1777
reason = pjsip_get_status_text(i);
1778
pj_ansi_snprintf( report, sizeof(report),
1779
" - %d responses: %7d (%.*s)",
1780
i, app.client.response_codes[i],
1781
(int)reason->slen, reason->ptr);
1782
write_report(report);
1785
/* Total responses and rate */
1786
pj_ansi_snprintf( report, sizeof(report),
1788
" TOTAL responses: %7d (rate=%d/sec)\n",
1789
app.client.total_responses,
1790
app.client.total_responses*1000/msec_res);
1792
write_report(report);
1794
pj_ansi_sprintf(report, "Maximum outstanding job: %d",
1795
app.client.stat_max_window);
1796
write_report(report);
1801
char s[10], *unused;
1805
puts("pjsip-perf started in server-mode");
1807
printf("Receiving requests on the following URIs:\n"
1808
" sip:0@%.*s:%d%s for stateless handling\n"
1809
" sip:1@%.*s:%d%s for stateful handling\n"
1810
" sip:2@%.*s:%d%s for call handling\n",
1811
(int)app.local_addr.slen,
1814
(app.use_tcp ? ";transport=tcp" : ""),
1815
(int)app.local_addr.slen,
1818
(app.use_tcp ? ";transport=tcp" : ""),
1819
(int)app.local_addr.slen,
1822
(app.use_tcp ? ";transport=tcp" : ""));
1823
printf("INVITE with non-matching user part will be handled call-statefully\n");
1825
for (i=0; i<app.thread_count; ++i) {
1826
status = pj_thread_create(app.pool, NULL, &server_thread,
1827
(void*)(long)i, 0, 0, &app.thread[i]);
1828
if (status != PJ_SUCCESS) {
1829
app_perror(THIS_FILE, "Unable to create thread", status);
1834
puts("\nPress <ENTER> to quit\n");
1836
unused = fgets(s, sizeof(s), stdin);
1837
PJ_UNUSED_ARG(unused);
1839
app.thread_quit = PJ_TRUE;
1840
for (i=0; i<app.thread_count; ++i) {
1841
pj_thread_join(app.thread[i]);
1842
app.thread[i] = NULL;