summaryrefslogtreecommitdiff
path: root/src/tools/echo
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/echo')
-rw-r--r--src/tools/echo/echo.c24
-rw-r--r--src/tools/echo/echo_server.c5
2 files changed, 16 insertions, 13 deletions
diff --git a/src/tools/echo/echo.c b/src/tools/echo/echo.c
index ab7d5557..28ae4c1a 100644
--- a/src/tools/echo/echo.c
+++ b/src/tools/echo/echo.c
@@ -41,19 +41,15 @@ static void usage()
int main(int argc, char ** argv)
{
int ret = -1;
- if (ap_init(argv[0])) {
- printf("Failed to init AP.\n");
- return -1;
- }
+ char ** argv_dup = argv;
+ bool server = false;
argc--;
argv++;
while (argc > 0) {
if (strcmp(*argv, "-l") == 0 ||
strcmp(*argv, "--listen") == 0) {
- ret = server_main();
- ap_fini();
- return ret;
+ server = true;
} else {
usage();
return 0;
@@ -62,7 +58,19 @@ int main(int argc, char ** argv)
argv++;
}
- ret = client_main();
+ if (server) {
+ if (ap_init(argv_dup[0])) {
+ printf("Failed to init AP.\n");
+ return -1;
+ }
+ ret = server_main();
+ } else {
+ if (ap_init(NULL)) {
+ printf("Failed to init AP.\n");
+ return -1;
+ }
+ ret = client_main();
+ }
ap_fini();
diff --git a/src/tools/echo/echo_server.c b/src/tools/echo/echo_server.c
index 3106ee35..e6ab9cfd 100644
--- a/src/tools/echo/echo_server.c
+++ b/src/tools/echo/echo_server.c
@@ -39,11 +39,6 @@ int server_main()
char buf[BUF_SIZE];
ssize_t count = 0;
- if (api_bind(NULL) < 0) {
- printf("Failed to bind the server api.");
- return -1;
- }
-
printf("Starting the server.\n");
/* Manual cleanup is required for now */