From: Marcel Poul Date: Mon, 14 Nov 2011 16:13:59 +0000 (+0000) Subject: samle server and client command line opts added X-Git-Tag: merge_30_head_take2_dst~30 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=bd86fe245e140b8655856a82dc82e2cbb5248c04;p=jra1mw.git samle server and client command line opts added --- diff --git a/emi.canl.canl-c/src/canl_sample_client.c b/emi.canl.canl-c/src/canl_sample_client.c index 349569e..540ac76 100644 --- a/emi.canl.canl-c/src/canl_sample_client.c +++ b/emi.canl.canl-c/src/canl_sample_client.c @@ -1,15 +1,42 @@ #include +#include +#include #include "canl.h" #define BUF_LEN 1000 -int main() +int main(int argc, char *argv[]) { canl_ctx my_ctx; canl_io_handler my_io_h; int err = 0; char *err_msg = NULL; char buf[BUF_LEN]; + char *p_server = NULL; + char *def_server = "www.linuxfoundation.org"; + int opt, port = 80; + + while ((opt = getopt(argc, argv, "hp:s:")) != -1) { + switch (opt) { + case 'h': + fprintf(stderr, "Usage: %s [-p port]" + "[-s server] [-h] \n", argv[0]); + break; + case 'p': + port = atoi(optarg); + break; + case 's': + p_server = optarg; + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-p port]" + "[-s server] [-h] \n", argv[0]); + exit(-1); + } + } + + if (!p_server) + p_server = def_server; my_ctx = canl_create_ctx(); if (!my_ctx){ @@ -23,7 +50,7 @@ int main() goto end; } - err = canl_io_connect(my_ctx, my_io_h, "www.seznam.cz", 80, 0, NULL, NULL); + err = canl_io_connect(my_ctx, my_io_h, p_server, port, 0, NULL, NULL); if (err) { printf("connection cannot be established\n"); goto end; diff --git a/emi.canl.canl-c/src/canl_sample_server.c b/emi.canl.canl-c/src/canl_sample_server.c index 96ff765..44b60ad 100644 --- a/emi.canl.canl-c/src/canl_sample_server.c +++ b/emi.canl.canl-c/src/canl_sample_server.c @@ -1,13 +1,30 @@ #include +#include +#include #include "canl.h" -int main() +int main(int argc, char *argv[]) { canl_ctx my_ctx; canl_io_handler my_io_h; canl_io_handler my_new_io_h; int err = 0; char *err_msg = NULL; + int opt, port = 4321; + + while ((opt = getopt(argc, argv, "hp:")) != -1) { + switch (opt) { + case 'h': + fprintf(stderr, "Usage: %s [-p port] [-h] \n", argv[0]); + break; + case 'p': + port = atoi(optarg); + break; + default: /* '?' */ + fprintf(stderr, "Usage: %s [-p port] [-h] \n", argv[0]); + exit(-1); + } + } my_ctx = canl_create_ctx(); if (!my_ctx){ @@ -20,7 +37,7 @@ int main() //set_error("io handler cannot be created\n"); goto end; } - + my_new_io_h = canl_create_io_handler(my_ctx); if (!my_new_io_h) { //set_error("io handler cannot be created\n"); @@ -28,7 +45,7 @@ int main() } /* canl_create_io_handler has to be called for my_new_io_h and my_io_h*/ - err = canl_io_accept(my_ctx, my_io_h, 4321, 0, NULL, NULL, &my_new_io_h); + err = canl_io_accept(my_ctx, my_io_h, port, 0, NULL, NULL, &my_new_io_h); if (err) { //set_error("cannot make a connection"); goto end;