Bladeren bron

Cleaned up error messages.

Steve Thielemann 3 jaren geleden
bovenliggende
commit
e9c2f8e238
1 gewijzigde bestanden met toevoegingen van 17 en 6 verwijderingen
  1. 17 6
      twproxy.cpp

+ 17 - 6
twproxy.cpp

@@ -57,7 +57,13 @@ public:
       server_read();
     } else {
       // TODO:
-      do_write("Failed to connect to server.\n\r");
+      std::string output = "Failed to connect : ";
+      output += host;
+      output += " : ";
+      output += port;
+      output += "\n\r";
+      do_write(output);
+      
       std::cout << "Failed to connect to server." << std::endl;
       std::cout << "SHUTDOWN..." << std::endl;
       socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
@@ -81,7 +87,7 @@ public:
             }
             server_read();
           } else {
-            std::cout << "read_failed: connection closed" << std::endl;
+            std::cout << "S: read_failed: connection closed" << std::endl;
             socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
             // socket_.async_shutdown(boost::bind(&session::on_shutdown, this,
             // boost::asio::placeholders::error));
@@ -104,7 +110,10 @@ public:
 
     } else {
       // TO DO:
-      do_write("Unable to resolve?\n\r");
+      std::string output = "Unable to resolve: ";
+      output += host;
+      output += "\n\r";
+      do_write(output); 
       std::cout << "Unable to resolve?" << std::endl;
       std::cout << "SHUTDOWN ..." << std::endl;
       socket_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
@@ -154,8 +163,9 @@ public:
             }
             do_read();
           } else {
-            std::cout << "read_failed: connection closed" << std::endl;
-            server_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
+            std::cout << "C: read_failed: connection closed" << std::endl;
+            if (connected)
+              server_.shutdown(boost::asio::ip::tcp::socket::shutdown_both);
             // server_.async_shutdown(boost::bind(&session::on_shutdown, this,
             // boost::asio::placeholders::error));
           }
@@ -275,7 +285,8 @@ int main(int argc, char *argv[]) {
 
   bool config_ok = true;
 
-  for (const char *key : {"server", "host", "port"}) {
+  // for (const char *key : {"server", "host", "port"}) {
+  for (auto key : {"server", "host", "port"}) {
     auto pos = config.find(key);
     if (pos == config.end()) {
       config_ok = false;