From 1823322ac0a440303c65f21de535724f213f480d Mon Sep 17 00:00:00 2001 From: Nanang Izzuddin Date: Mon, 13 Apr 2015 12:14:02 +0000 Subject: Re #1842: Updated pjsua app to avoid stdout buffering, and also adjusted python tests accordingly. git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@5065 74dad513-b988-da41-8d7b-12977e46ad98 --- pjsip-apps/src/pjsua/pjsua_app_config.c | 7 +++++++ pjsip-apps/src/pjsua/pjsua_app_legacy.c | 23 +++++++++++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) (limited to 'pjsip-apps/src') diff --git a/pjsip-apps/src/pjsua/pjsua_app_config.c b/pjsip-apps/src/pjsua/pjsua_app_config.c index 4256de95..740be6f2 100644 --- a/pjsip-apps/src/pjsua/pjsua_app_config.c +++ b/pjsip-apps/src/pjsua/pjsua_app_config.c @@ -214,6 +214,12 @@ static void usage(void) fflush(stdout); } +static void log_writer_nobuf(int level, const char *buffer, int len) +{ + pj_log_write(level, buffer, len); + fflush(stdout); +} + /* * Read command arguments from config file. */ @@ -1251,6 +1257,7 @@ static pj_status_t parse_args(int argc, char *argv[], #ifdef _IONBF case OPT_STDOUT_NO_BUF: setvbuf(stdout, NULL, _IONBF, 0); + cfg->log_cfg.cb = &log_writer_nobuf; break; #endif diff --git a/pjsip-apps/src/pjsua/pjsua_app_legacy.c b/pjsip-apps/src/pjsua/pjsua_app_legacy.c index ed960e30..d687aded 100644 --- a/pjsip-apps/src/pjsua/pjsua_app_legacy.c +++ b/pjsip-apps/src/pjsua/pjsua_app_legacy.c @@ -23,6 +23,20 @@ #define THIS_FILE "pjsua_app_legacy.c" + +/* An attempt to avoid stdout buffering for python tests: + * - call 'fflush(stdout)' after each call to 'printf()/puts()' + * - apply 'setbuf(stdout, 0)', but it is not guaranteed by the standard: + * http://stackoverflow.com/questions/1716296 + */ +#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ + (defined (_MSC_VER) && _MSC_VER >= 1400) +/* Variadic macro is introduced in C99; MSVC supports it in since 2005. */ +# define printf(...) {printf(__VA_ARGS__);fflush(stdout);} +# define puts(s) {puts(s);fflush(stdout);} +#endif + + static pj_bool_t cmd_echo; /* @@ -38,9 +52,9 @@ static void print_buddy_list() pjsua_enum_buddies(ids, &count); - if (count == 0) + if (count == 0) { puts(" -none-"); - else { + } else { for (i=0; i<(int)count; ++i) { pjsua_buddy_info info; @@ -1088,9 +1102,9 @@ static void ui_call_transfer(pj_bool_t no_refersub) pj_list_push_back(&msg_data.hdr_list, &refer_sub); } if (result.nb_result != PJSUA_APP_NO_NB) { - if (result.nb_result == -1 || result.nb_result == 0) + if (result.nb_result == -1 || result.nb_result == 0) { puts("You can't do that with transfer call!"); - else { + } else { pjsua_buddy_info binfo; pjsua_buddy_get_info(result.nb_result-1, &binfo); pjsua_call_xfer( current_call, &binfo.uri, &msg_data); @@ -1669,6 +1683,7 @@ static void ui_call_redirect(char menuin[]) } } + /* * Main "user interface" loop. */ -- cgit v1.2.3