Commit d4ecec29 authored by Legodev's avatar Legodev

improved debug output and fixed but with double return of pointer

parent 42c85466
......@@ -22,7 +22,7 @@ extern "C"
void RVExtension(char *output, int outputSize, const char *function)
{
#ifdef DEBUG
testfile << "REQUEST " << function << std::endl;
testfile << "\t\t ARMAIO-REQUEST " << function << std::endl;
testfile.flush();
#endif
std::string errstr = "[\"" + std::string(PROTOCOL_MESSAGE_TYPE_ERROR) + "\", \"";
......@@ -30,7 +30,7 @@ extern "C"
errstr += "\"]";
strncpy(output, errstr.c_str(), outputSize);
#ifdef DEBUG
testfile << "ERROR " << errstr << std::endl;
testfile << "\t\t ARMAIO-ERROR " << errstr << std::endl;
testfile.flush();
#endif
}
......@@ -42,22 +42,23 @@ extern "C"
{
try {
#ifdef DEBUG
testfile << "REQUEST " << function << std::endl;
testfile << "\t\t ARMAIO-REQUEST " << function << std::endl;
testfile.flush();
for (int i = 0; i < argsCnt; i++) {
testfile << "Argument " << i << ": " << args[i] << " - Escaped: " << escapeChars(args[i]) << std::endl;
testfile << "\t\t ARMAIO-Argument " << i << ": " << args[i] << std::endl;
testfile.flush();
}
#endif
std::string returnString = extension->processCallExtension(function, args, argsCnt, outputSize);
#ifdef DEBUG
testfile << "RETURN " << returnString << std::endl;
testfile << "\t\t ARMAIO-RETURN " << returnString << std::endl;
testfile.flush();
#endif
strncpy(output, returnString.c_str(), outputSize);
return;
} catch (std::exception const& e) {
std::string error = e.what();
int i = 0;
while ((i = error.find("\"", i)) != std::string::npos) {
error.insert(i, "\"");
......@@ -68,7 +69,7 @@ extern "C"
errstr += "\"]";
strncpy(output, errstr.c_str(), outputSize);
#ifdef DEBUG
testfile << "ERROR " << errstr << std::endl;
testfile << "\t\t ARMAIO-ERROR " << errstr << std::endl;
testfile.flush();
#endif
}
......
......@@ -50,23 +50,8 @@ redex * extension = 0;
#ifdef DEBUG
std::mutex ThreadMutex;
int attachedThreadCount = 0;
extern std::ofstream testfile;
std::ofstream testfile("LibRedExLogFile.txt", std::ios::out | std::ios::trunc);
std::string escapeChars(std::string input) {
std::stringstream outputstream;
for (unsigned int i = 0; i < input.length(); i++) {
switch(input[i]) {
case '-': if (input[i+1] > '0' && input[i+1] < '9') { outputstream << "-"; }; break;
case ';': break;
case '#': break;
case '"': if (i > 0 && i < input.length() - 1) { outputstream << "\\\""; }; break;
case '\\': outputstream << "\\\\"; break;
default: outputstream << input[i]; break;
}
}
return outputstream.str();
}
#endif
static void init(void)
......
......@@ -30,6 +30,13 @@
#include "mysql/datacache/charactermysql.hpp"
#include "mysql/datacache/objectmysql.hpp"
#ifdef DEBUG
#include <fstream>
#include <iostream>
#include <sstream>
extern std::ofstream testfile;
#endif
extern std::map<std::string, unsigned int> * objectvariablemap;
std::map<std::string, unsigned int> * objectvariablemap = 0;
extern std::map<std::string, unsigned int> * charactervariablemap;
......@@ -266,8 +273,12 @@ std::string mysql_db_handler::spawnHandler(std::string &extFunction, ext_argumen
/* for the beginning we want to have some spare pool handlers */
connectionpool.reserve(poolsize + 3);
for (i = 0; i < poolsize; i++) {
for (i = 0; i <= poolsize; i++) {
MYSQL * connection = connect();
#ifdef DEBUG
testfile << "CREATED NEW DB POINTER " << static_cast<void*>(connection) << std::endl;
testfile.flush();
#endif
connectionpool.bounded_push((intptr_t) connection);
......@@ -327,14 +338,15 @@ MYSQL * mysql_db_handler::getconnection() {
// try to get an db connection
while (!connectionpool.pop(connectionpointer));
connection = (MYSQL *) connectionpointer;
try {
connection = (MYSQL *) connectionpointer;
} catch (std::exception const& e) {
// always return the connection
connectionpool.bounded_push(connectionpointer);
connection = 0;
throw std::runtime_error(e.what());
#ifdef DEBUG
testfile << "GOT DB POINTER " << static_cast<void*>(connection) << std::endl;
testfile.flush();
#endif
if (connection == 0) {
std::runtime_error("connection problem while getting mysql_db_handler: got a NULLPOINTER");
}
return connection;
......@@ -344,6 +356,11 @@ void mysql_db_handler::returnconnection(MYSQL * connection) {
intptr_t connectionpointer = (intptr_t) connection;
connectionpool.bounded_push(connectionpointer);
#ifdef DEBUG
testfile << "RETURNED DB POINTER " << static_cast<void*>(connection) << std::endl;
testfile.flush();
#endif
return;
}
......@@ -524,7 +541,6 @@ std::string mysql_db_handler::interkillChar(std::string &extFunction, ext_argume
std::string mysql_db_handler::interloadObject(std::string &extFunction, ext_arguments &extArgument) {
std::string result = loadObject(extArgument);
returnconnection(connection);
return "[\"" + std::string(PROTOCOL_MESSAGE_TYPE_MESSAGE) + "\"," + result + "]";
}
......@@ -535,7 +551,7 @@ std::string mysql_db_handler::intercreateObject(std::string &extFunction, ext_ar
}
std::string mysql_db_handler::interqcreateObject(std::string &extFunction, ext_arguments &extArgument) {
std::string result = this->createObject(extArgument);
std::string result = createObject(extArgument);
return "[\"" + std::string(PROTOCOL_MESSAGE_TYPE_MESSAGE) + "\",\"" + result + "\"]";
}
......@@ -576,7 +592,6 @@ std::string mysql_db_handler::interdumpObjects(std::string &extFunction, ext_arg
}
matrix += "]";
returnconnection(connection);
return "[\"" + std::string(PROTOCOL_MESSAGE_TYPE_MESSAGE) + "\"," + matrix + "]";
}
......
......@@ -33,6 +33,10 @@
#include "redex.hpp"
#include "utils/uuid.hpp"
#ifdef DEBUG
extern std::ofstream testfile;
#endif
redex::redex() {
extFunctions.insert(
std::make_pair(
......@@ -221,6 +225,10 @@ void redex::asyncCallProcessor(EXT_FUNCTION_INFO funcinfo, ext_arguments extArgu
returnString = this->syncCall(funcinfo, extArgument);
} catch (std::exception const& e) {
std::string error = e.what();
#ifdef DEBUG
testfile << "INTERNAL ERROR " << error << std::endl;
testfile.flush();
#endif
int i = 0;
while ((i = error.find("\"", i)) != std::string::npos) {
error.insert(i, "\"");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment