#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
#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){
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;
#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
#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){
//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");
}
/* 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;