From 41e5a068b0b595be86797fd12035dabb87c21f36 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 3 Sep 2007 09:58:51 +0000 Subject: Simplified TCP socket write of strings. Cleaned up debug output. --- server/src/server.cc | 17 +++++++---------- server/src/tcpsocket.cc | 6 ++++++ server/src/tcpsocket.h | 1 + server/src/xmlparser.cc | 14 ++++++-------- 4 files changed, 20 insertions(+), 18 deletions(-) (limited to 'server') diff --git a/server/src/server.cc b/server/src/server.cc index f6c811b..288dbe1 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -79,19 +79,15 @@ static void connection(TCPSocket &socket) Transaction transaction; parse(socket, transaction); - std::string xml_version = "\n"; - socket.write((char*)xml_version.c_str(), xml_version.length()); - - std::string header = "\n"; - socket.write((char*)header.c_str(), header.length()); + socket.write("\n"); + socket.write("\n"); // Handle requests Requests::iterator i = transaction.requests.begin(); while(i != transaction.requests.end()) { Request request = *i; - printf("Request [%s]...\n", request.macro.c_str()); - + printf("Handling request for \"%s\"...", request.macro.c_str()); // Now handle the request. char outbuf[3]; @@ -109,6 +105,8 @@ static void connection(TCPSocket &socket) socket.write(outbuf, bytes); } close(fd); + + printf("done.\n"); i++; } @@ -120,10 +118,9 @@ static void connection(TCPSocket &socket) j++; } - std::string footer = "\n"; - socket.write((char*)footer.c_str(), footer.length()); + socket.write("\n"); - printf("done\n"); + printf("Done with connection.\n"); } void server() diff --git a/server/src/tcpsocket.cc b/server/src/tcpsocket.cc index 6fc521f..90f71a5 100644 --- a/server/src/tcpsocket.cc +++ b/server/src/tcpsocket.cc @@ -260,6 +260,12 @@ int TCPSocket::write(char *data, int size) return res; } +int TCPSocket::write(std::string data) + throw(TCPWriteException) +{ + return write((char*)data.c_str(), data.length()); +} + std::string TCPSocket::srcaddr() throw(TCPNameException) { diff --git a/server/src/tcpsocket.h b/server/src/tcpsocket.h index 45d94ee..393d40b 100644 --- a/server/src/tcpsocket.h +++ b/server/src/tcpsocket.h @@ -158,6 +158,7 @@ public: * @return The actual number of bytes written. */ int write(char *data, int size) throw(TCPWriteException); + int write(std::string data) throw(TCPWriteException); /** * Get the source address of the socket (IP address not DNS name). diff --git a/server/src/xmlparser.cc b/server/src/xmlparser.cc index 8020a80..7e5fb14 100644 --- a/server/src/xmlparser.cc +++ b/server/src/xmlparser.cc @@ -39,9 +39,7 @@ void start_hndl(void *p, const char *el, const char **attr) { Transaction *transaction = (Transaction*)XML_GetUserData(p); - printf("Data %p\n", transaction); - - printf("Start tag [%s]\n", el); + // printf("Start tag [%s]\n", el); // Convert to comfy C++ values... std::string name = el; @@ -67,7 +65,7 @@ void start_hndl(void *p, const char *el, const char **attr) if(name == "request") { Request r; r.macro = attributes["macro"]; - printf("%s\n", r.macro.c_str()); + // printf("%s\n", r.macro.c_str()); transaction->requests.push_back(r); } @@ -75,7 +73,7 @@ void start_hndl(void *p, const char *el, const char **attr) void end_hndl(void *p, const char *el) { - printf("End tag [%s]\n", el); + // printf("End tag [%s]\n", el); if(!strcmp(el, "pracro")) done = true; } @@ -85,7 +83,8 @@ void parse(TCPSocket &socket, Transaction &transaction) XML_Parser p = XML_ParserCreate(NULL); if (! p) { fprintf(stderr, "Couldn't allocate memory for parser\n"); - exit(-1); + // throw Exception(...); + return; } XML_SetUserData(p, &transaction); @@ -105,12 +104,11 @@ void parse(TCPSocket &socket, Transaction &transaction) fprintf(stderr, "Parse error at line %d:\n%s\n", XML_GetCurrentLineNumber(p), XML_ErrorString(XML_GetErrorCode(p))); - // exit(-1); // throw Exception(...); return; } } - printf("%d requests\n", transaction.requests.size()); + // printf("%d requests\n", transaction.requests.size()); } -- cgit v1.2.3