From b7be78948cad7629427fd19769ddcfdfea3fb666 Mon Sep 17 00:00:00 2001 From: deva Date: Fri, 8 Aug 2008 09:23:03 +0000 Subject: Added print debug configurable. --- server/src/journal_commit.cc | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'server/src/journal_commit.cc') diff --git a/server/src/journal_commit.cc b/server/src/journal_commit.cc index b1ae866..c10e8c7 100644 --- a/server/src/journal_commit.cc +++ b/server/src/journal_commit.cc @@ -26,6 +26,8 @@ */ #include "journal_commit.h" +#include + // for gethostbyname #include @@ -48,18 +50,22 @@ static int mwrite(int sock, const char *fmt, ...) va_list args; char *buffer; - buffer = (char*)malloc(64*1024); + buffer = (char*)calloc(64*1024, 1); va_start(args, fmt); l = vsnprintf(buffer, 64*1024, fmt, args); va_end(args); - if(write(sock, buffer, l) != l) { + if(sock != -1 && write(sock, buffer, l) != l) { fprintf(stderr, "write did not write all the bytes in the buffer.\n"); } free(buffer); +#ifdef WITH_DEBUG + printf(buffer); +#endif/*WITH_DEBUG*/ + return l; } @@ -67,7 +73,7 @@ int journal_commit(const char *cpr, const char *user, const char *addr, unsigned short int port, const char *buf, size_t size) { - int sock = 1; + int sock = -1; #ifndef WITHOUT_UPLOADSERVER struct sockaddr_in sin; @@ -116,9 +122,12 @@ int journal_commit(const char *cpr, const char *user, mwrite(sock, "\r\n"); // send body - if(write(sock, buf, size) != (ssize_t)size) { + if(sock != -1 && write(sock, buf, size) != (ssize_t)size) { fprintf(stderr, "write did not write all the bytes in the buffer.\n"); } +#ifdef WITH_DEBUG + printf(buf); +#endif/*WITH_DEBUG*/ #ifndef WITHOUT_UPLOADSERVER // close socket -- cgit v1.2.3