summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordeva <deva>2007-09-03 09:58:51 +0000
committerdeva <deva>2007-09-03 09:58:51 +0000
commit41e5a068b0b595be86797fd12035dabb87c21f36 (patch)
tree7d9dd21b54d5d8075b220e5aa06526387ca53d20
parentf49186b63888caedd5e0dad4a52a680fb28834a4 (diff)
Simplified TCP socket write of strings. Cleaned up debug output.
-rw-r--r--server/src/server.cc17
-rw-r--r--server/src/tcpsocket.cc6
-rw-r--r--server/src/tcpsocket.h1
-rw-r--r--server/src/xmlparser.cc14
4 files changed, 20 insertions, 18 deletions
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 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
- socket.write((char*)xml_version.c_str(), xml_version.length());
-
- std::string header = "<pracro version=\"1.0\">\n";
- socket.write((char*)header.c_str(), header.length());
+ socket.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ socket.write("<pracro version=\"1.0\">\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 = "</pracro>\n";
- socket.write((char*)footer.c_str(), footer.length());
+ socket.write("</pracro>\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());
}