summaryrefslogtreecommitdiff
path: root/lib/test-blocking.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordu.net>2010-09-03 00:58:55 +0200
committerLinus Nordberg <linus@nordu.net>2010-09-03 00:58:55 +0200
commit8455dc9801730e599510c92cdb3e05da351aa7a5 (patch)
treebb3b8fca4cdda6ace2d632ab8df5b9b0c72172e3 /lib/test-blocking.c
parent5f3d7c31ce76cac39449f1603d09dfadcfcfcc70 (diff)
Low level connect and read working, kind of. At least TCP.
Next: serializing.
Diffstat (limited to 'lib/test-blocking.c')
-rw-r--r--lib/test-blocking.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/lib/test-blocking.c b/lib/test-blocking.c
new file mode 100644
index 0000000..641a34f
--- /dev/null
+++ b/lib/test-blocking.c
@@ -0,0 +1,62 @@
+#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 };
+ 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);
+}