Enhancements
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -26,38 +26,55 @@ void handleClient(Block<String> &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<String> arguments;
|
||||
for(int index=0;index<argc;index++)
|
||||
{
|
||||
String item(argv[index]);
|
||||
arguments.insert(item);
|
||||
}
|
||||
if(argc<2)
|
||||
{
|
||||
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<String> arguments;
|
||||
for(int index=0;index<argc;index++)
|
||||
{
|
||||
String item(argv[index]);
|
||||
arguments.insert(item);
|
||||
}
|
||||
|
||||
std::cout << argv[1] << std::endl;
|
||||
if(arguments[1]=="SERVERMODE")
|
||||
{
|
||||
handleServer(arguments);
|
||||
std::cout << argv[1] << std::endl;
|
||||
if(arguments[1]=="SERVERMODE")
|
||||
{
|
||||
handleServer(arguments);
|
||||
}
|
||||
else if(arguments[1]=="CLIENTMODE")
|
||||
{
|
||||
handleClient(arguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Unknown command " << arguments[1] << std::endl;
|
||||
returnCode=-1;
|
||||
}
|
||||
}
|
||||
else if(arguments[1]=="CLIENTMODE")
|
||||
catch(Exception& exception)
|
||||
{
|
||||
handleClient(arguments);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Unknown command " << arguments[1] << std::endl;
|
||||
std::cout << exception.toString() << std::endl;
|
||||
returnCode=-1;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
std::cout << "An unhandled exception was encountered" << std::endl;
|
||||
returnCode=-1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
/// @brief [0]=program [1]=SERVERMODE [2]={port}
|
||||
|
||||
@@ -105,13 +105,13 @@ bool SocketConnectionReceiver::handlePut(Block<String> &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;
|
||||
|
||||
Reference in New Issue
Block a user