From 440f65ec5cfd11e079871433c0b3ddb7fd59a79e Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Thu, 18 Oct 2012 01:29:08 +0000 Subject: [PATCH] Now loading the UDP transport --- tests/Makefile | 4 +-- tests/project.conf | 4 +-- tests/udp.c | 71 ++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 72 insertions(+), 7 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 3b1b336..7edfdf9 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -5,9 +5,9 @@ BINDIR = $(PREFIX)/bin CC ?= cc CPPFLAGSF?= CPPFLAGS= -I ../include -CFLAGSF = -W +CFLAGSF = -W `pkg-config --cflags libSystem` CFLAGS = -Wall -g -O2 -LDFLAGSF= -lApp +LDFLAGSF= `pkg-config --libs libSystem` -lApp LDFLAGS = -L../src -Wl,-rpath,../src RM ?= rm -f LN ?= ln -f diff --git a/tests/project.conf b/tests/project.conf index a46dc62..544740e 100644 --- a/tests/project.conf +++ b/tests/project.conf @@ -1,8 +1,8 @@ targets=tests.log,udp cppflags=-I ../include -cflags_force=-W +cflags_force=-W `pkg-config --cflags libSystem` cflags=-Wall -g -O2 -ldflags_force=-lApp +ldflags_force=`pkg-config --libs libSystem` -lApp ldflags=-L../src -Wl,-rpath,../src dist=Makefile,tests.sh diff --git a/tests/udp.c b/tests/udp.c index 320dded..f1e82c4 100644 --- a/tests/udp.c +++ b/tests/udp.c @@ -15,16 +15,68 @@ +#include +#include +#include +#include +#include +#include #include "App.h" /* private */ +/* prototypes */ +static int _udp(char const * name); + +static int _usage(void); + + /* functions */ /* udp */ -static int _udp(void) +static int _udp(char const * name) { + char * cwd; + Plugin * plugin; + AppTransportPluginDefinition * plugind; + AppTransportPlugin * server; + AppTransportPlugin * client; + + /* load the transport plug-in */ + if((cwd = getcwd(NULL, 0)) == NULL) + return error_set_print("udp", 2, "%s", strerror(errno)); + /* XXX rather ugly but does the trick */ + plugin = plugin_new(cwd, "../src", "transport", "udp"); + free(cwd); + if(plugin == NULL) + return error_print("udp"); + if((plugind = plugin_lookup(plugin, "transport")) == NULL) + { + plugin_delete(plugin); + return error_print("udp"); + } + /* create a server and a client */ + server = plugind->init(NULL, ATM_SERVER, name); + client = plugind->init(NULL, ATM_CLIENT, name); + if(server == NULL || client == NULL) + { + if(client != NULL) + plugind->destroy(client); + if(server != NULL) + plugind->destroy(server); + plugin_delete(plugin); + return error_print("udp"); + } /* FIXME really implement */ - return -1; + plugin_delete(plugin); + return 0; +} + + +/* usage */ +static int _usage(void) +{ + fputs("Usage: udp name\n", stderr); + return 1; } @@ -33,5 +85,18 @@ static int _udp(void) /* main */ int main(int argc, char * argv[]) { - return (_udp() == 0) ? 0 : 2; + char const * name = "127.0.0.1:4242"; + int o; + + while((o = getopt(argc, argv, "")) != -1) + switch(o) + { + default: + return _usage(); + } + if(optind == argc - 1) + name = argv[optind]; + else if(optind != argc) + return _usage(); + return (_udp(name) == 0) ? 0 : 2; }