summaryrefslogtreecommitdiff
path: root/sysdep/unix/main.c
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1998-05-24 14:50:18 +0000
committerMartin Mares <mj@ucw.cz>1998-05-24 14:50:18 +0000
commitb5d9ee5c878b41ffbc138be171d700992e9d78c7 (patch)
treee7f923e948e2a7ed84745dff90e36d409e4c3aad /sysdep/unix/main.c
parent6d45cf21be3f979ba4e8a1a5f557663618fadfb3 (diff)
Added UNIX implementation of both timers and sockets. Timers should work,
sockets were tested only in TCP mode. main.c now contains some test cases for socket code.
Diffstat (limited to 'sysdep/unix/main.c')
-rw-r--r--sysdep/unix/main.c89
1 files changed, 87 insertions, 2 deletions
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index 076a872c..b6b783b2 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -7,11 +7,72 @@
*/
#include <stdio.h>
+#include <sys/signal.h>
#include "nest/bird.h"
#include "lib/lists.h"
#include "lib/resource.h"
+#include "lib/socket.h"
#include "nest/route.h"
+#include "nest/protocol.h"
+
+#include "unix.h"
+
+/*
+ * Debugging
+ */
+
+static void
+handle_sigusr(int sig)
+{
+ debug("SIGUSR1: Debugging dump...\n\n");
+
+ sk_dump_all();
+ tm_dump_all();
+ rta_dump_all();
+ rt_dump_all();
+
+ debug("\n");
+}
+
+static void
+signal_init(void)
+{
+ static struct sigaction sa;
+
+ sa.sa_handler = handle_sigusr;
+ sa.sa_flags = SA_RESTART;
+ if (sigaction(SIGUSR1, &sa, NULL) < 0)
+ die("sigaction: %m");
+ signal(SIGPIPE, SIG_IGN);
+}
+
+/*
+ * Hic Est main()
+ */
+
+void erro(sock *s, int e)
+{
+ debug("errrr e=%d\n", e);
+ rfree(s);
+}
+
+void bla(sock *s)
+{
+ puts("W");
+ strcpy(s->tbuf, "RAM!\r\n");
+ sk_send(s, 6);
+}
+
+int xxx(sock *s, int h)
+{
+ puts("R");
+ do {
+ strcpy(s->tbuf, "Hello, world!\r\n");
+ }
+ while (sk_send(s, 15) > 0);
+ return 1;
+}
int
main(void)
@@ -20,8 +81,32 @@ main(void)
log_init_debug(NULL);
resource_init();
+ io_init();
rt_init();
- proto_init();
+ protos_init();
+ signal_init();
+
+ {
+ sock *s = sk_new(&root_pool);
+
+ if (!s)
+ die("no socket");
+ s->type = SK_UDP_MC;
+ s->sport = 7899;
+ s->saddr = _MI(0x3ea80015);
+ s->daddr = _MI(0xe0000001);
+ s->dport = 7890;
+ s->rx_hook = xxx;
+ s->tx_hook = bla;
+ s->err_hook = erro;
+ s->rbsize = 1024;
+ s->tbsize = 1024;
+ s->ttl = 1;
+ if (sk_open(s))
+ die("open failed");
+ bla(s);
+ }
- return 0;
+ io_loop();
+ die("I/O loop died");
}