--- l2_test.c 2001/09/04 14:56:25 1.10
+++ l2_test.c 2001/09/04 19:35:20 1.11
@@ -28,6 +28,12 @@
*/
#include <stdio.h>
+
+#include <sys/types.h> /* following group of includes are for */
+#include <sys/socket.h> /* socket testing only */
+#include <netinet/in.h>
+#include <netdb.h>
+
#include "l2.h"
static void die(char *fmt, ...)
@@ -58,21 +64,45 @@
{
l2_channel_t *chBuf;
l2_channel_t *chFile;
+ l2_channel_t *chSock;
l2_stream_t *st;
/*
* Typical steps to use a buffered file logging stream
*/
- if ((chBuf = l2_channel_create(&l2_handler_buffer)) == NULL)
- die("failed to create buffer channel");
+ if ((st = l2_stream_create()) == NULL)
+ die("failed to create stream");
- if ((chFile = l2_channel_create(&l2_handler_file)) == NULL)
- die("failed to create file channel");
+/* Atenzione! Before doing any socket testing, make sure you have a valid */
+/* end point listening, or else you will only get an error message when */
+/* the thing tries to connect. */
+/* if ((chSock = l2_channel_create(&l2_handler_socket)) == NULL)
+ die("failed to create socket channel");
+
+ if (l2_channel_configure(chSock, "ipversion,host,port", AF_INET,\
+ "localhost", 2002) != L2_OK)
+ die("failed to configure socket ipv4 channel");
+
+ if (l2_channel_configure(chSock, "ipversion,host,port", AF_INET6,\
+ "0123:4567:4455:6677:8899:AABB:9876:5432", 2002) != L2_OK)
+ die("failed to configure socket ipv6 channel");
+
+ if (l2_channel_open(chSock) != L2_OK)
+ die("failed to open socket channel");
+
+ if (l2_stream_channel(st, chSock, L2_LEVEL_UPTO(L2_LEVEL_WARNING)) != L2_OK)
+ die("failed to attach first channel into stream");
+*/
+ if ((chBuf = l2_channel_create(&l2_handler_buffer)) == NULL) /* Buffer */
+ die("failed to create buffer channel");
if (l2_channel_configure(chBuf, "size", 100) != L2_OK)
die("failed to configure buffer channel");
+ if ((chFile = l2_channel_create(&l2_handler_file)) == NULL) /* File */
+ die("failed to create file channel");
+
if (l2_channel_configure(chFile, "path,append,perm", "l2_test.log", TRUE, 0644) != L2_OK)
die("failed to configure file channel");
@@ -82,11 +112,8 @@
if (l2_channel_open(chBuf) != L2_OK)
die("failed to open buffer channel");
- if ((st = l2_stream_create()) == NULL)
- die("failed to create stream");
-
if (l2_stream_channel(st, chBuf, L2_LEVEL_UPTO(L2_LEVEL_WARNING)) != L2_OK)
- die("failed to attach channel into stream");
+ die("failed to attach second channel into stream");
if (l2_stream_levels(st, L2_LEVEL_UPTO(L2_LEVEL_WARNING)) != L2_OK)
die("failed to set global logging level");
@@ -94,7 +121,7 @@
if (l2_stream_formatter(st, 'k', formatter, NULL) != L2_OK)
die("failed to configure formatter for %%x");
- if (l2_stream_log(st, L2_LEVEL_PANIC, "test %s %{foo}k", "foo", 12345) != L2_OK)
+ if (l2_stream_log(st, L2_LEVEL_PANIC, "Checking localhost %s %{myparm}k\n", "foo", 12345) != L2_OK)
die("failed to log message to stream");
if (l2_stream_destroy(st) != L2_OK)
|