diff options
author | Sander Vrijders <[email protected]> | 2016-06-14 14:55:39 +0200 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2016-06-14 14:55:39 +0200 |
commit | 6271d09bdd17114c3095b7e819a7bcded14f26a5 (patch) | |
tree | a1c2a7bd200eb0343557524ddc80b0af6df4ec9e /src/tools/echo | |
parent | ddfc7091d2698d36c1cfec49eaaad96b278bb37b (diff) | |
parent | 95124310f647913a678060fc10155a0ad9311dba (diff) | |
download | ouroboros-6271d09bdd17114c3095b7e819a7bcded14f26a5.tar.gz ouroboros-6271d09bdd17114c3095b7e819a7bcded14f26a5.zip |
Merged in dstaesse/ouroboros/be-api (pull request #122)
lib, irmd, tools, ipcpd: updates to dev API.
Diffstat (limited to 'src/tools/echo')
-rw-r--r-- | src/tools/echo/echo.c | 19 | ||||
-rw-r--r-- | src/tools/echo/echo_client.c | 11 | ||||
-rw-r--r-- | src/tools/echo/echo_server.c | 32 |
3 files changed, 18 insertions, 44 deletions
diff --git a/src/tools/echo/echo.c b/src/tools/echo/echo.c index 849c0ca8..4484dc71 100644 --- a/src/tools/echo/echo.c +++ b/src/tools/echo/echo.c @@ -23,7 +23,6 @@ #include <stdio.h> #include <string.h> -#define SERVER_AP_NAME "echo-server" #define BUF_SIZE 256 #include "echo_client.c" @@ -37,14 +36,22 @@ static void usage() " --help Display this help text and exit\n"); } -int main(int argc, char ** argv) { +int main(int argc, char ** argv) +{ + int ret = -1; + if (ap_init(argv[0])) { + printf("Failed to init AP.\n"); + return -1; + } argc--; argv++; while (argc > 0) { if (strcmp(*argv, "-l") == 0 || strcmp(*argv, "--listen") == 0) { - return server_main(); + ret = server_main(); + ap_fini(); + return ret; } else { usage(); return 0; @@ -53,5 +60,9 @@ int main(int argc, char ** argv) { argv++; } - return client_main(); + ret = client_main(); + + ap_fini(); + + return ret; } diff --git a/src/tools/echo/echo_client.c b/src/tools/echo/echo_client.c index 5c613817..499e36ee 100644 --- a/src/tools/echo/echo_client.c +++ b/src/tools/echo/echo_client.c @@ -20,8 +20,6 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#define CLIENT_AP_NAME "echo-client" - #include <ouroboros/dev.h> #include <stdlib.h> @@ -33,12 +31,7 @@ int client_main() char * message = "Client says hi!"; ssize_t count = 0; - if (ap_init(CLIENT_AP_NAME)) { - printf("Failed to init AP.\n"); - return -1; - } - - fd = flow_alloc(SERVER_AP_NAME, NULL, NULL); + fd = flow_alloc("echo", NULL, NULL); if (fd < 0) { printf("Failed to allocate flow.\n"); ap_fini(); @@ -72,7 +65,5 @@ int client_main() flow_dealloc(fd); - ap_fini(); - return 0; } diff --git a/src/tools/echo/echo_server.c b/src/tools/echo/echo_server.c index b72da319..c5e9f807 100644 --- a/src/tools/echo/echo_server.c +++ b/src/tools/echo/echo_server.c @@ -27,28 +27,15 @@ #include <ouroboros/dev.h> -#define DIF_NAME "*" - void shutdown_server(int signo) { - char * dif = DIF_NAME; - - if (ap_unreg(&dif, 1)) { - printf("Failed to unregister application.\n"); - ap_fini(); - exit(EXIT_FAILURE); - } - ap_fini(); exit(EXIT_SUCCESS); } int server_main() { - int server_fd = 0; int client_fd = 0; - char * dif = DIF_NAME; - char * client_name = NULL; char buf[BUF_SIZE]; ssize_t count = 0; @@ -60,27 +47,14 @@ int server_main() return -1; } - if (ap_init(SERVER_AP_NAME)) { - printf("Failed to init AP.\n"); - return -1; - } - - server_fd = ap_reg(&dif, 1); - if (server_fd < 0) { - printf("Failed to register application.\n"); - ap_fini(); - return -1; - } - while (true) { - client_fd = flow_accept(server_fd, - &client_name, NULL); + client_fd = flow_accept(NULL); if (client_fd < 0) { printf("Failed to accept flow.\n"); break; } - printf("New flow from %s.\n", client_name); + printf("New flow.\n"); if (flow_alloc_resp(client_fd, 0)) { printf("Failed to give an allocate response.\n"); @@ -106,7 +80,5 @@ int server_main() flow_dealloc(client_fd); } - ap_fini(); - return 0; } |