소스 검색

Trying various things to locate the leak.

It seems that it is in the logging.
First call is where it shows the leaks are.  It isn't
the yaml, or strings I get from it.
Steve Thielemann 3 년 전
부모
커밋
0ed09838cd
3개의 변경된 파일152개의 추가작업 그리고 16개의 파일을 삭제
  1. 128 9
      session.cpp
  2. 9 2
      session.h
  3. 15 5
      twproxy.cpp

+ 128 - 9
session.cpp

@@ -11,6 +11,8 @@
 #include "logging.h"
 #include "session.h"
 
+#include "galaxy.h"
+
 #include <string>
 
 // #include <boost/log/attributes/named_scope.hpp>
@@ -144,6 +146,8 @@ void Session::on_connect(const boost::system::error_code error) {
   // We've connected to the server!  WOOT WOOT!
   // BOOST_LOG_NAMED_SCOPE("Session");
 
+  SL_parser = nullptr;
+
   if (!error) {
     BUGZ_LOG(info) << "Connected to " << host;
     to_client("Connected...\n\r");
@@ -188,13 +192,24 @@ void Session::on_server_line(const std::string &line) {
     // reset "active game" -- we're back at the menu
   }
 
-  // additional analysis needed here
-  // state :  where are we, what is this line?
-  // collect all data we can from the server.  (P1)
+  /*
+     ____                             _     _
+    / ___|  ___ _ ____   _____ _ __  | |   (_)_ __   ___
+    \___ \ / _ \ '__\ \ / / _ \ '__| | |   | | '_ \ / _ \
+     ___) |  __/ |   \ V /  __/ |    | |___| | | | |  __/
+    |____/ \___|_|    \_/ \___|_|    |_____|_|_| |_|\___|
+
+     ____                _
+    |  _ \ __ _ _ __ ___(_)_ __   __ _
+    | |_) / _` | '__/ __| | '_ \ / _` |
+    |  __/ (_| | |  \__ \ | | | | (_| |
+    |_|   \__,_|_|  |___/_|_| |_|\__, |
+                                 |___/
+
+  This is where all of the server lines are gleaned for all the
+  information that we can get out of them.
 
-  // "Selection (? for menu): ?"
-  // This gives us the current game that we're in.
-  // (excluding ?, #, ! and Q)
+   */
 
   if (line.find("Selection (? for menu): ") != std::string::npos) {
     char ch = line[line.length() - 1];
@@ -207,6 +222,44 @@ void Session::on_server_line(const std::string &line) {
       game = 0;
   }
 
+  // Do I need to run through the tests (below) before calling the parser here?
+  // Or will the parsers know when they are done processing, and clear?
+
+  if (SL_parser) {
+    SL_parser(line);
+  }
+
+  // ok, maybe that was the end of parsing?
+
+  if (!SL_parser) {
+    if ((line.substr(0, 19) == "The shortest path (") ||
+        (line.substr(0, 7) == "  TO > ")) {
+      SL_parser = [this](const std::string s) { this->SL_warpline(s); };
+      SL_warpline(line);
+    } else {
+      if (line.substr(0, 43) == " Items     Status  Trading % of max OnBoard") {
+        SL_parser = [this](const std::string s) { this->SL_portline(s); };
+        SL_parser(line);
+      } else {
+        if (line.substr(0, 10) == "<Thievery>") {
+          SL_parser = [this](const std::string s) { this->SL_thiefline(s); };
+          SL_parser(line);
+        } else {
+          if (line == ": ") {
+            SL_parser = [this](const std::string s) { this->SL_cimline(s); };
+          } else {
+            if (line.substr(0, 1) == "Sector  : ") {
+              SL_parser = [this](const std::string s) {
+                this->SL_sectorline(s);
+              };
+              SL_parser(line);
+            }
+          }
+        }
+      }
+    }
+  }
+
   // should I have an internal emit_server_line for parsing sections?
   // rather then having a weird state machine to track where we are?
 
@@ -214,6 +267,69 @@ void Session::on_server_line(const std::string &line) {
     emit_server_line(line);
 }
 
+void Session::SL_cimline(const std::string &line) {
+  if (line == ": ENDINTERROG") {
+    SL_parser = nullptr;
+    return;
+  }
+  if (line == ": ") {
+    // do I need to do anything special here for this?
+    return;
+  }
+  if (line.empty()) {
+    SL_parser = nullptr;
+    return;
+  }
+
+  // parse cimline
+  size_t pos = line.find('%');
+  std::string work = line;
+
+  if (pos == line.npos) {
+    // warpcim
+
+  } else {
+    // portcim
+  }
+}
+void Session::SL_thiefline(const std::string &line) {
+  size_t pos = line.find("Suddenly you're Busted!");
+  bool busted = pos != line.npos;
+  if (busted) {
+    BUGZ_LOG(fatal) << "set bust";
+    SL_parser = nullptr;
+  } else {
+    pos = line.find("(You realize the guards saw you last time!)");
+    if (pos != line.npos)
+      SL_parser = nullptr;
+  }
+
+  // Are those the two ways to exit from this state?
+}
+void Session::SL_sectorline(const std::string &line) {}
+void Session::SL_portline(const std::string &line) {
+  if (line.empty()) {
+    SL_parser = nullptr;
+    return;
+  }
+  BUGZ_LOG(info) << "portline : " << line;
+  size_t pos = line.find('%');
+  if (pos != line.npos) {
+    // Ok, this is a valid portline
+    std::string work = line;
+    replace(work, "Fuel Ore", "Fuel");
+    BUGZ_LOG(fatal) << "re.split? : [" << work << "]";
+  }
+}
+
+void Session::SL_warpline(const std::string &line) {
+  if (line.empty()) {
+    SL_parser = nullptr;
+    return;
+  }
+
+  // process warp line
+}
 /**
  * Split server input into lines.
  *
@@ -686,8 +802,8 @@ void Session::stayin_alive(const boost::system::error_code error) {
 }
 
 Server::Server(boost::asio::io_service &io_service,
-               const boost::asio::ip::tcp::endpoint &endpoint, std::string host,
-               std::string port)
+               const boost::asio::ip::tcp::endpoint &endpoint,
+               const std::string &host, const std::string &port)
     : io_service_{io_service}, acceptor_{io_service_, endpoint},
       signal_{io_service, SIGUSR1, SIGTERM}, host_{host}, port_{port} {
   keep_accepting = true;
@@ -709,7 +825,10 @@ void Server::on_signal(const boost::system::error_code &ec, int signal) {
   BUGZ_LOG(info) << "close: " << error;
 }
 
-Server::~Server() { BUGZ_LOG(info) << "Server::~Server()"; }
+Server::~Server() {
+  CONFIG = YAML::Node();
+  BUGZ_LOG(info) << "Server::~Server()";
+}
 /**
  * setup async connect accept
  *

+ 9 - 2
session.h

@@ -65,6 +65,13 @@ private:
   void process_lines(std::string &received);
 
 private:
+  StringFunc SL_parser;
+  void SL_cimline(const std::string &line);
+  void SL_thiefline(const std::string &line);
+  void SL_sectorline(const std::string &line);
+  void SL_portline(const std::string &line);
+  void SL_warpline(const std::string &line);
+
   void set_prompt_timer(void);
   void reset_prompt_timer(void);
   void on_prompt_timeout(const boost::system::error_code error);
@@ -180,8 +187,8 @@ class Server {
 
 public:
   Server(boost::asio::io_service &io_service,
-         const boost::asio::ip::tcp::endpoint &endpoint, std::string host,
-         std::string port);
+         const boost::asio::ip::tcp::endpoint &endpoint,
+         const std::string &host, const std::string &port);
   ~Server();
 
 private:

+ 15 - 5
twproxy.cpp

@@ -46,7 +46,7 @@ https://github.com/boostorg/log/issues/46
 
 void init_logging(void) {
   // because TimeStamp is missing by default.
-  boost::log::add_common_attributes();
+  // boost::log::add_common_attributes();
 
   // "proxy-%Y-%m-%d.log"
   std::string log_filename = "proxy.log";
@@ -112,7 +112,8 @@ int main(int argc, char *argv[]) {
     return EXIT_FAILURE;
   }
 
-  CONFIG = YAML::LoadFile(argv[1]); // yaml_parse(argv[1]);
+
+  CONFIG = YAML::LoadFile(argv[1]); 
 
   init_logging();
 
@@ -125,8 +126,14 @@ int main(int argc, char *argv[]) {
       std::cout << "Config file missing: " << key << std::endl;
       BUGZ_LOG(fatal) << "Config file missing: " << key;
     }
-    BUGZ_LOG(info) << "Config: " << key << " : " << CONFIG[key];
+
+    // The leaks are reported here, because this is the first usage of the BOOST_LOG_TRIVIAL()!
+    // Comment these out, and the leaks are reported at the next logging usage instance.
+    std::string value = CONFIG[key].as<std::string>();
+    BUGZ_LOG(info) << "Config: " << key << " : " << value;
+    
   }
+
   if (!config_ok)
     return EXIT_FAILURE;
 
@@ -140,8 +147,11 @@ int main(int argc, char *argv[]) {
     boost::asio::ip::tcp::endpoint endpoint(boost::asio::ip::tcp::v4(),
                                             port); // std::atoi(argv[i]));
     // connect to the game server
-    Server s(io_service, endpoint, CONFIG["host"].as<std::string>(),
-             CONFIG["port"].as<std::string>());
+    std::string host = CONFIG["host"].as<std::string>();
+    std::string port = CONFIG["port"].as<std::string>();
+    BUGZ_LOG(fatal) << "host: " << host << " port: " << port;
+
+    Server serve(io_service, endpoint, host, port );
 
     io_service.run();
   } catch (std::exception &e) {