From f441b186b5fbb551efaed39d329f310e82126cfd Mon Sep 17 00:00:00 2001 From: Sean Date: Thu, 14 Aug 2025 17:32:16 -0400 Subject: [PATCH] Enhancements --- common/utility.hpp | 21 +++++++---- sstp/main.cpp | 63 ++++++++++++++++++++----------- sstp/socketconnectionreceiver.cpp | 10 ++--- 3 files changed, 58 insertions(+), 36 deletions(-) diff --git a/common/utility.hpp b/common/utility.hpp index 91bf5f8..575272e 100644 --- a/common/utility.hpp +++ b/common/utility.hpp @@ -15,7 +15,7 @@ class Utility static String formatCurrency(double number,int places=2); static bool fmod(double dividend,double divisor); static bool fmod(double dividend, double divisor,double epsilon); - static String bytesTransferredToString(double bytesTransferred); + static String byteCountToString(double bytesTransferred, bool perSecond = true); private: static String pad(String theString,char padChar,int toLength); static String addCommas(String& theString); @@ -34,30 +34,35 @@ Utility::~Utility() } inline -String Utility::bytesTransferredToString(double bytesTransferred) +String Utility::byteCountToString(double bytesTransferred, bool perSecond) { double roundedValue = std::round(bytesTransferred * 100.00)/100.00; + String strBytesTransferrred; if(roundedValue >= 1E+15) { - return Utility::formatNumber(roundedValue/1E+15,2) + "Pb/s"; + strBytesTransferrred = Utility::formatNumber(roundedValue/1E+15,2) + "Pb"; } else if(roundedValue >= 1000000000000) { - return Utility::formatNumber(roundedValue/1000000000000,2) + "Tb/s"; + strBytesTransferrred = Utility::formatNumber(roundedValue/1000000000000,2) + "Tb"; } else if(roundedValue >= 1073741824) { - return Utility::formatNumber(roundedValue/1073741824,2) + "Gbb/s"; + strBytesTransferrred = Utility::formatNumber(roundedValue/1073741824,2) + "Gb"; } else if(roundedValue >= 1000000) { - return Utility::formatNumber(roundedValue/1000000,2) + "Mb/s"; + strBytesTransferrred = Utility::formatNumber(roundedValue/1000000,2) + "Mb"; } else if(roundedValue >= 1000) { - return Utility::formatNumber(roundedValue/1000,2) + "Kb/s"; + strBytesTransferrred = Utility::formatNumber(roundedValue/1000,2) + "Kb"; } - return Utility::formatNumber(roundedValue,2) + "B/s"; + else strBytesTransferrred = Utility::formatNumber(roundedValue,2) + "B"; + + if(perSecond)strBytesTransferrred+="/s"; + + return strBytesTransferrred; } inline diff --git a/sstp/main.cpp b/sstp/main.cpp index d2bcd44..4f577bb 100644 --- a/sstp/main.cpp +++ b/sstp/main.cpp @@ -26,38 +26,55 @@ void handleClient(Block &commands); /// @return int main(int argc, char **argv) { + int returnCode(0); Profiler profiler; + String version = "1.00"; - if(argc<2) + std::cout << "sstp version " << version.str() << std::endl; + try { - std::cout << "sstp SERVERMODE {port} | CLIENTMODE {serveripaddress} {serverport} {pathfileName}." << std::endl; - std::cout << "SERVERMODE will listen on the specified port for a connection and receive the specified file." << std::endl; - std::cout << "CLIENTMODE willl connect to the specified address and port and send the specfied file." << std::endl; - return 1; - } - Block arguments; - for(int index=0;index arguments; + for(int index=0;index &commands) { double elapsedTimeSeconds = profiler.elapsed()/1000.00; double bytesPerSecond = totalBytesRead / elapsedTimeSeconds; - String strBytesPerSecond = Utility::bytesTransferredToString(bytesPerSecond); - std::cout << "Transferred " << Utility::formatNumber(totalBytesRead) << " of " << Utility::formatNumber(fileLength) << " " << percent << " percent " << strBytesPerSecond << std::endl; + String strBytesPerSecond = Utility::byteCountToString(bytesPerSecond); + std::cout << "Transferred " << Utility::byteCountToString(totalBytesRead,false) << " of " << Utility::byteCountToString(fileLength,false) << " " << percent << " percent " << strBytesPerSecond << std::endl; } } std::cout << "Transfer complete" << std::endl; - std::cout << "Received " << Utility::formatNumber(totalBytesRead) << " in " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; + std::cout << "Received " << Utility::byteCountToString(totalBytesRead,false) << " in " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl; writeFile.close(); return totalBytesRead==fileLength; } @@ -128,7 +128,7 @@ size_t SocketConnectionReceiver::expectPacket(void) sb.append("Received an invalid PCKT command"); String str=sb.toString(); std::cout << str << std::endl; - throw new InvalidOperationException(str); + throw InvalidOperationException(str); } if(!(subCommands[0]=="PCKT")) { @@ -138,7 +138,7 @@ size_t SocketConnectionReceiver::expectPacket(void) sb.append("Expected PCKT but received ").append(subCommands[0]); String str = sb.toString(); std::cout << str << std::endl; - throw new InvalidOperationException(str); + throw InvalidOperationException(str); } size_t bufferLength = subCommands[1].toULong(); return bufferLength;