added timestamp to debug output

This commit is contained in:
Olaf Bergmann committed 2010-07-14 15:31:40 +02:00
1 parent 0569c6f4a8
commit 4ce4ae7fc6
4 files changed
+51 -34

No files matched your search

+9 -6
View File
@@ -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) $@ $^
+27
View File
@@ -0,0 +1,27 @@
/* debug.c -- debug utilities
*
* (c) 2010 Olaf Bergmann <bergmann@tzi.org>
*/
#include <stdarg.h>
#include <stdio.h>
#include <time.h>
#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);
}
+11 -17
View File
@@ -3,26 +3,20 @@
* (c) 2010 Olaf Bergmann <bergmann@tzi.org>
*/
#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_ */
+4 -11
View File
@@ -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 <stdarg.h>
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,