Move the JSON initialization/finalization insode the API.
Этот коммит содержится в:
родитель
a5621dd908
Коммит
e96ab74093
@ -235,7 +235,7 @@ iperf_set_test_role(struct iperf_test *ipt, char role)
|
|||||||
void
|
void
|
||||||
iperf_set_test_server_hostname(struct iperf_test *ipt, char *server_hostname)
|
iperf_set_test_server_hostname(struct iperf_test *ipt, char *server_hostname)
|
||||||
{
|
{
|
||||||
ipt->server_hostname = server_hostname;
|
ipt->server_hostname = strdup( server_hostname );
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <setjmp.h>
|
#include <setjmp.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@ -20,6 +21,7 @@
|
|||||||
#include "iperf.h"
|
#include "iperf.h"
|
||||||
#include "iperf_api.h"
|
#include "iperf_api.h"
|
||||||
#include "iperf_util.h"
|
#include "iperf_util.h"
|
||||||
|
#include "locale.h"
|
||||||
#include "net.h"
|
#include "net.h"
|
||||||
#include "timer.h"
|
#include "timer.h"
|
||||||
|
|
||||||
@ -186,6 +188,18 @@ iperf_run_client(struct iperf_test * test)
|
|||||||
fd_set read_set, write_set;
|
fd_set read_set, write_set;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
|
||||||
|
if (test->json_output)
|
||||||
|
if (iperf_json_start(test) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (test->json_output) {
|
||||||
|
cJSON_AddItemToObject(test->json_start, "version", cJSON_CreateString(version));
|
||||||
|
cJSON_AddItemToObject(test->json_start, "system_info", cJSON_CreateString(get_system_info()));
|
||||||
|
} else if (test->verbose) {
|
||||||
|
printf("%s\n", version);
|
||||||
|
system("uname -a");
|
||||||
|
}
|
||||||
|
|
||||||
/* Start the client and connect to the server */
|
/* Start the client and connect to the server */
|
||||||
if (iperf_connect(test) < 0) {
|
if (iperf_connect(test) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -250,5 +264,11 @@ iperf_run_client(struct iperf_test * test)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (test->json_output) {
|
||||||
|
if (iperf_json_finish(test) < 0)
|
||||||
|
return -1;
|
||||||
|
} else
|
||||||
|
printf("\niperf Done.\n");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -282,6 +282,18 @@ iperf_run_server(struct iperf_test *test)
|
|||||||
struct iperf_stream *sp;
|
struct iperf_stream *sp;
|
||||||
struct timeval now;
|
struct timeval now;
|
||||||
|
|
||||||
|
if (test->json_output)
|
||||||
|
if (iperf_json_start(test) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (test->json_output) {
|
||||||
|
cJSON_AddItemToObject(test->json_start, "version", cJSON_CreateString(version));
|
||||||
|
cJSON_AddItemToObject(test->json_start, "system_info", cJSON_CreateString(get_system_info()));
|
||||||
|
} else if (test->verbose) {
|
||||||
|
printf("%s\n", version);
|
||||||
|
system("uname -a");
|
||||||
|
}
|
||||||
|
|
||||||
// Open socket and listen
|
// Open socket and listen
|
||||||
if (iperf_server_listen(test) < 0) {
|
if (iperf_server_listen(test) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -396,5 +408,10 @@ iperf_run_server(struct iperf_test *test)
|
|||||||
close(test->ctrl_sck);
|
close(test->ctrl_sck);
|
||||||
close(test->listener);
|
close(test->listener);
|
||||||
|
|
||||||
|
if (test->json_output) {
|
||||||
|
if (iperf_json_finish(test) < 0)
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -180,6 +180,21 @@ cpu_util(double *pcpu)
|
|||||||
*pcpu = ((ctemp - clast) / timediff) * 100;
|
*pcpu = ((ctemp - clast) / timediff) * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char*
|
||||||
|
get_system_info(void)
|
||||||
|
{
|
||||||
|
FILE* fp;
|
||||||
|
static char buf[1000];
|
||||||
|
|
||||||
|
fp = popen("uname -a", "r");
|
||||||
|
if (fp == NULL)
|
||||||
|
return NULL;
|
||||||
|
fgets(buf, sizeof(buf), fp);
|
||||||
|
pclose(fp);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Helper routine for building cJSON objects in a printf-like manner.
|
/* Helper routine for building cJSON objects in a printf-like manner.
|
||||||
**
|
**
|
||||||
** Sample call:
|
** Sample call:
|
||||||
|
@ -26,6 +26,8 @@ int delay(int64_t ns);
|
|||||||
|
|
||||||
void cpu_util(double *);
|
void cpu_util(double *);
|
||||||
|
|
||||||
|
char* get_system_info(void);
|
||||||
|
|
||||||
cJSON* iperf_json_printf(const char *format, ...);
|
cJSON* iperf_json_printf(const char *format, ...);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
33
src/main.c
33
src/main.c
@ -106,36 +106,10 @@ main(int argc, char **argv)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static char*
|
|
||||||
get_system_info(void)
|
|
||||||
{
|
|
||||||
FILE* fp;
|
|
||||||
static char buf[1000];
|
|
||||||
|
|
||||||
fp = popen("uname -a", "r");
|
|
||||||
if (fp == NULL)
|
|
||||||
return NULL;
|
|
||||||
fgets(buf, sizeof(buf), fp);
|
|
||||||
pclose(fp);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
int
|
int
|
||||||
iperf_run(struct iperf_test * test)
|
iperf_run(struct iperf_test * test)
|
||||||
{
|
{
|
||||||
if (test->json_output)
|
|
||||||
if (iperf_json_start(test) < 0)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (test->json_output) {
|
|
||||||
cJSON_AddItemToObject(test->json_start, "version", cJSON_CreateString(version));
|
|
||||||
cJSON_AddItemToObject(test->json_start, "system_info", cJSON_CreateString(get_system_info()));
|
|
||||||
} else if (test->verbose) {
|
|
||||||
printf("%s\n", version);
|
|
||||||
system("uname -a");
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (test->role) {
|
switch (test->role) {
|
||||||
case 's':
|
case 's':
|
||||||
for (;;) {
|
for (;;) {
|
||||||
@ -155,12 +129,5 @@ iperf_run(struct iperf_test * test)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (test->json_output) {
|
|
||||||
if (iperf_json_finish(test) < 0)
|
|
||||||
return -1;
|
|
||||||
} else
|
|
||||||
printf("\niperf Done.\n");
|
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -8,4 +8,4 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#define IPERF_VERSION "3.0-BETA5"
|
#define IPERF_VERSION "3.0-BETA5"
|
||||||
#define IPERF_VERSION_DATE "01 Feb 2013"
|
#define IPERF_VERSION_DATE "01 March 2013"
|
||||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user