From e2120257dda4d91b48bb031a96edda810ce30dfb Mon Sep 17 00:00:00 2001 From: deva Date: Tue, 30 Sep 2008 12:49:34 +0000 Subject: Changed SAXParser parse method to take a buffer and a size instead of a c++ string. Made the queryhandler use a read loop, parsing on-the-fly to determine when the entire document has been read. --- server/src/server.cc | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) (limited to 'server/src/server.cc') diff --git a/server/src/server.cc b/server/src/server.cc index e4a470e..64ee709 100644 --- a/server/src/server.cc +++ b/server/src/server.cc @@ -173,21 +173,9 @@ static std::string handleTransaction(Transaction &transaction) s.connect(Conf::pentominos_addr, Conf::pentominos_port); #endif/*WITHOUT_PENTOMINOS*/ QueryHandler qh(&s, transaction.cpr); - /////////////////////////////// - - qh.addQuery(*qi); - - std::string result = qh.exec(); - printf("Got result: [%s]\n", result.c_str()); - ///////////////////////// - ///////////////////////// - // Parse the result from the queries to pentominos - QueryParser qp(result); - qp.parse(); - // Map the results - lqm.addQueryResult(qp.result); - //////////////////////// + QueryResult queryresult = qh.exec(*qi); + lqm.addQueryResult(queryresult); qi++; } @@ -269,17 +257,11 @@ static void handleConnection(TCPSocket *socket) } printf("Got %d bytes in read loop\n", size); - size = 0; - if(parser->parse(buf)) { + if(parser->parse(buf, size)) { printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n" "!! Got complete XML document %d bytes used, %d bytes in current buffer.\n" "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n", parser->usedBytes(), strlen(buf)); - if(parser->usedBytes() < strlen(buf)) { - size = strlen(buf) - parser->usedBytes(); - strcpy(buf, buf + parser->usedBytes()); - } - socket->write(handleTransaction(*transaction)); delete transaction; @@ -288,6 +270,9 @@ static void handleConnection(TCPSocket *socket) delete parser; parser = NULL; } + + size = size - parser->usedBytes(); + if(size) memcpy(buf, buf + parser->usedBytes(), size); } memset(buf, 0, bufsize); } -- cgit v1.2.3