@@ -697,6 +697,12 @@ iperf_set_test_json_stream(struct iperf_test *ipt, int json_stream)
697
697
ipt -> json_stream = json_stream ;
698
698
}
699
699
700
+ void
701
+ iperf_set_test_json_callback (struct iperf_test * ipt , void (* callback )(struct iperf_test * , char * ))
702
+ {
703
+ ipt -> json_callback = callback ;
704
+ }
705
+
700
706
int
701
707
iperf_has_zerocopy ( void )
702
708
{
@@ -2864,12 +2870,16 @@ JSONStream_Output(struct iperf_test * test, const char * event_name, cJSON * obj
2864
2870
char * str = cJSON_PrintUnformatted (event );
2865
2871
if (str == NULL )
2866
2872
return -1 ;
2867
- if (pthread_mutex_lock (& (test -> print_mutex )) != 0 ) {
2868
- perror ("iperf_json_finish: pthread_mutex_lock" );
2869
- }
2870
- fprintf (test -> outfile , "%s\n" , str );
2871
- if (pthread_mutex_unlock (& (test -> print_mutex )) != 0 ) {
2872
- perror ("iperf_json_finish: pthread_mutex_unlock" );
2873
+ if (test -> json_callback != NULL ) {
2874
+ (test -> json_callback )(test , str );
2875
+ } else {
2876
+ if (pthread_mutex_lock (& (test -> print_mutex )) != 0 ) {
2877
+ perror ("iperf_json_finish: pthread_mutex_lock" );
2878
+ }
2879
+ fprintf (test -> outfile , "%s\n" , str );
2880
+ if (pthread_mutex_unlock (& (test -> print_mutex )) != 0 ) {
2881
+ perror ("iperf_json_finish: pthread_mutex_unlock" );
2882
+ }
2873
2883
}
2874
2884
iflush (test );
2875
2885
cJSON_free (str );
@@ -3060,6 +3070,8 @@ iperf_defaults(struct iperf_test *testp)
3060
3070
testp -> settings -> rcv_timeout .usecs = (DEFAULT_NO_MSG_RCVD_TIMEOUT % SEC_TO_mS ) * mS_TO_US ;
3061
3071
testp -> zerocopy = 0 ;
3062
3072
3073
+ testp -> json_callback = NULL ;
3074
+
3063
3075
memset (testp -> cookie , 0 , COOKIE_SIZE );
3064
3076
3065
3077
testp -> multisend = 10 ; /* arbitrary */
@@ -5035,14 +5047,18 @@ iperf_json_finish(struct iperf_test *test)
5035
5047
if (test -> json_output_string == NULL ) {
5036
5048
return -1 ;
5037
5049
}
5038
- if (pthread_mutex_lock (& (test -> print_mutex )) != 0 ) {
5039
- perror ("iperf_json_finish: pthread_mutex_lock" );
5040
- }
5041
- fprintf (test -> outfile , "%s\n" , test -> json_output_string );
5042
- if (pthread_mutex_unlock (& (test -> print_mutex )) != 0 ) {
5043
- perror ("iperf_json_finish: pthread_mutex_unlock" );
5050
+ if (test -> json_callback != NULL ) {
5051
+ (test -> json_callback )(test , test -> json_output_string );
5052
+ } else {
5053
+ if (pthread_mutex_lock (& (test -> print_mutex )) != 0 ) {
5054
+ perror ("iperf_json_finish: pthread_mutex_lock" );
5055
+ }
5056
+ fprintf (test -> outfile , "%s\n" , test -> json_output_string );
5057
+ if (pthread_mutex_unlock (& (test -> print_mutex )) != 0 ) {
5058
+ perror ("iperf_json_finish: pthread_mutex_unlock" );
5059
+ }
5060
+ iflush (test );
5044
5061
}
5045
- iflush (test );
5046
5062
}
5047
5063
cJSON_Delete (test -> json_top );
5048
5064
}
0 commit comments