diff options
author | Linus Nordberg <linus@nordu.net> | 2010-09-13 17:27:40 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2010-09-13 17:27:40 +0200 |
commit | 23dfea91ef5e921da0b09d91004436a7d8715c42 (patch) | |
tree | 3ef5ba7681bbe664efb51064f29adc5cec2778b7 /lib/tests | |
parent | 8455dc9801730e599510c92cdb3e05da351aa7a5 (diff) |
First stab at a working blocking example.
Diffstat (limited to 'lib/tests')
-rw-r--r-- | lib/tests/Makefile | 10 | ||||
-rw-r--r-- | lib/tests/test-blocking.c | 64 |
2 files changed, 74 insertions, 0 deletions
diff --git a/lib/tests/Makefile b/lib/tests/Makefile new file mode 100644 index 0000000..13316fc --- /dev/null +++ b/lib/tests/Makefile @@ -0,0 +1,10 @@ +CFLAGS = -Wall -g + +all: test-blocking + +test-blocking: test-blocking.c ../examples/blocking.o ../base.o ../../list.o ../../tlv11.o + $(CC) $(CFLAGS) -I .. -I ../examples -o $@ $^ + +clean: + -rm *.o test-blocking + diff --git a/lib/tests/test-blocking.c b/lib/tests/test-blocking.c new file mode 100644 index 0000000..aab76e3 --- /dev/null +++ b/lib/tests/test-blocking.c @@ -0,0 +1,64 @@ +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> +#include <netdb.h> +#include <stdio.h> +#include <stdlib.h> +#include "blocking.h" + +int +f (const struct sockaddr *addr, + socklen_t addrlen, + int out_fd) +{ + int fd = -1; + //struct rs_alloc_scheme as = { calloc, malloc, free, realloc }; + struct rs_config ctx = { RS_CONN_TYPE_TCP, + { RS_CRED_NONE, NULL, NULL }, + { NULL, NULL, NULL, NULL } }; + struct rs_packet *p = NULL; + + fd = rs_connect (&ctx, addr, addrlen); + if (fd < 0) + { + perror ("rs_connect"); + return -1; + } + + p = next_packet (&ctx, fd); + if (p == NULL) + { + perror ("next_packet"); + rs_disconnect (&ctx, fd); + return -1; + } + rs_disconnect (&ctx, fd); + + if (send_packet (&ctx, out_fd, p)) + { + rs_packet_free (&ctx, &p); + perror ("send_packet"); + return -1; + } + + return 0; +} + +int +main (int argc, char *argv[]) +{ + struct addrinfo *ai; + int rc; + + rc = getaddrinfo (argv[1], argv[2], NULL, &ai); + if (rc) + { + if (rc == EAI_SYSTEM) + perror ("getaddrinfo"); + else + fprintf (stderr, "getaddrinfo: %s\n", gai_strerror (rc)); + return -1; + } + + return f (ai->ai_addr, ai->ai_addrlen, 1); +} |