From 4ce4ae7fc60ed9945b0b7f769cef6fb93a35412e Mon Sep 17 00:00:00 2001 From: Olaf Bergmann Date: Wed, 14 Jul 2010 15:31:40 +0200 Subject: [PATCH] added timestamp to debug output --- Makefile | 15 +++++++++------ debug.c | 27 +++++++++++++++++++++++++++ debug.h | 28 +++++++++++----------------- net.c | 15 ++++----------- 4 files changed, 51 insertions(+), 34 deletions(-) create mode 100644 debug.c diff --git a/Makefile b/Makefile index 5514e4b0..7927cf06 100644 --- a/Makefile +++ b/Makefile @@ -1,11 +1,14 @@ PROGRAM:=coap-server -VERSION:=0.03 +VERSION:=0.04 -SOURCES:= pdu.c net.c encode.c uri.c list.c +prg_sources = main.c +prg_objects:= $(patsubst %.c, %.o, $(prg_sources)) +prg_headers = +SOURCES:= pdu.c net.c debug.c encode.c uri.c list.c subscribe.c OBJECTS:= $(patsubst %.c, %.o, $(SOURCES)) -HEADERS:=coap.h debug.h pdu.h net.h encode.h uri.h list.h mem.h +HEADERS:=coap.h debug.h pdu.h net.h encode.h uri.h list.h mem.h subscribe.h $(prg_headers) CFLAGS:=-g -Wall -ansi -pedantic -DISTDIR=$(PROGRAM)-$(VERSION) +DISTDIR=coap-$(VERSION) FILES:=main.c Makefile $(SOURCES) $(HEADERS) LIB:=libcoap.a LDFLAGS:=-L. -l$(patsubst lib%.a,%,$(LIB)) @@ -17,8 +20,8 @@ examples:=examples .PHONY: clean distclean .gitignore -$(PROGRAM): main.o $(LIB) - $(CC) -o $@ $< $(LDFLAGS) +$(PROGRAM): $(prg_objects) $(LIB) + $(CC) -o $@ $(prg_objects) $(LDFLAGS) $(LIB): $(OBJECTS) $(AR) $(ARFLAGS) $@ $^ diff --git a/debug.c b/debug.c new file mode 100644 index 00000000..52dc4458 --- /dev/null +++ b/debug.c @@ -0,0 +1,27 @@ +/* debug.c -- debug utilities + * + * (c) 2010 Olaf Bergmann + */ + +#include +#include +#include + +#include "debug.h" + +void debug(char *format, ...) { + static char timebuf[32]; + struct tm *tmp; + time_t now; + va_list ap; + + time(&now); + tmp = localtime(&now); + + if ( strftime(timebuf,sizeof(timebuf), "%b %d %H:%M:%S", tmp) ) + printf("%s ", timebuf); + + va_start(ap, format); + vprintf(format, ap); + va_end(ap); +} diff --git a/debug.h b/debug.h index a998be0a..e3085231 100644 --- a/debug.h +++ b/debug.h @@ -3,26 +3,20 @@ * (c) 2010 Olaf Bergmann */ +#ifndef _COAP_DEBUG_H_ +#define _COAP_DEBUG_H_ + #ifndef VERSION -# define VERSION "0.03" +# define VERSION "0.04" #endif -#ifndef debug -# ifndef NDEBUG -# ifdef __STRICT_ANSI__ -extern void debug(char *,...); -# else -# define debug(...) fprintf(stdout, __VA_ARGS__) -# endif -# else -# define debug(...) -# endif -#endif - -#include "pdu.h" - #ifndef NDEBUG -extern void coap_show_pdu( coap_pdu_t *); + +void debug(char *,...); + +#include "pdu.h" +extern void coap_show_pdu(coap_pdu_t *); + #endif - +#endif /* _COAP_DEBUG_H_ */ diff --git a/net.c b/net.c index ce58852b..dd66c08f 100644 --- a/net.c +++ b/net.c @@ -14,6 +14,7 @@ #include "debug.h" #include "mem.h" +#include "subscribe.h" #include "net.h" #define options_start(p) ((coap_opt_t *) ( (unsigned char *)p->hdr + sizeof ( coap_hdr_t ) )) @@ -260,22 +261,14 @@ coap_free_context( coap_context_t *context ) { if ( !context ) return; + coap_delete_all(context->recvqueue); coap_delete_all(context->sendqueue); + coap_delete_list(context->resources); + coap_delete_list(context->subscriptions); close( context->sockfd ); coap_free( context ); } -#ifdef __STRICT_ANSI__ -#include -void debug(char *format, ...) { - va_list ap; - - va_start(ap, format); /* bf being the last argument before '...' */ - vprintf(format, ap); - va_end(ap); -} -#endif - /* releases space allocated by PDU if free_pdu is set */ coap_tid_t coap_send_impl( coap_context_t *context, const struct sockaddr_in6 *dst, coap_pdu_t *pdu,