Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f441b186b5 |
@@ -15,7 +15,7 @@ class Utility
|
|||||||
static String formatCurrency(double number,int places=2);
|
static String formatCurrency(double number,int places=2);
|
||||||
static bool fmod(double dividend,double divisor);
|
static bool fmod(double dividend,double divisor);
|
||||||
static bool fmod(double dividend, double divisor,double epsilon);
|
static bool fmod(double dividend, double divisor,double epsilon);
|
||||||
static String bytesTransferredToString(double bytesTransferred);
|
static String byteCountToString(double bytesTransferred, bool perSecond = true);
|
||||||
private:
|
private:
|
||||||
static String pad(String theString,char padChar,int toLength);
|
static String pad(String theString,char padChar,int toLength);
|
||||||
static String addCommas(String& theString);
|
static String addCommas(String& theString);
|
||||||
@@ -34,30 +34,35 @@ Utility::~Utility()
|
|||||||
}
|
}
|
||||||
|
|
||||||
inline
|
inline
|
||||||
String Utility::bytesTransferredToString(double bytesTransferred)
|
String Utility::byteCountToString(double bytesTransferred, bool perSecond)
|
||||||
{
|
{
|
||||||
double roundedValue = std::round(bytesTransferred * 100.00)/100.00;
|
double roundedValue = std::round(bytesTransferred * 100.00)/100.00;
|
||||||
|
String strBytesTransferrred;
|
||||||
if(roundedValue >= 1E+15)
|
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)
|
else if(roundedValue >= 1000000000000)
|
||||||
{
|
{
|
||||||
return Utility::formatNumber(roundedValue/1000000000000,2) + "Tb/s";
|
strBytesTransferrred = Utility::formatNumber(roundedValue/1000000000000,2) + "Tb";
|
||||||
}
|
}
|
||||||
else if(roundedValue >= 1073741824)
|
else if(roundedValue >= 1073741824)
|
||||||
{
|
{
|
||||||
return Utility::formatNumber(roundedValue/1073741824,2) + "Gbb/s";
|
strBytesTransferrred = Utility::formatNumber(roundedValue/1073741824,2) + "Gb";
|
||||||
}
|
}
|
||||||
else if(roundedValue >= 1000000)
|
else if(roundedValue >= 1000000)
|
||||||
{
|
{
|
||||||
return Utility::formatNumber(roundedValue/1000000,2) + "Mb/s";
|
strBytesTransferrred = Utility::formatNumber(roundedValue/1000000,2) + "Mb";
|
||||||
}
|
}
|
||||||
else if(roundedValue >= 1000)
|
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
|
inline
|
||||||
|
|||||||
@@ -26,38 +26,55 @@ void handleClient(Block<String> &commands);
|
|||||||
/// @return
|
/// @return
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
int returnCode(0);
|
||||||
Profiler profiler;
|
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;
|
if(argc<2)
|
||||||
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;
|
std::cout << "sstp SERVERMODE {port} | CLIENTMODE {serveripaddress} {serverport} {pathfileName}." << std::endl;
|
||||||
return 1;
|
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;
|
||||||
Block<String> arguments;
|
return 1;
|
||||||
for(int index=0;index<argc;index++)
|
}
|
||||||
{
|
Block<String> arguments;
|
||||||
String item(argv[index]);
|
for(int index=0;index<argc;index++)
|
||||||
arguments.insert(item);
|
{
|
||||||
}
|
String item(argv[index]);
|
||||||
|
arguments.insert(item);
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << argv[1] << std::endl;
|
std::cout << argv[1] << std::endl;
|
||||||
if(arguments[1]=="SERVERMODE")
|
if(arguments[1]=="SERVERMODE")
|
||||||
{
|
{
|
||||||
handleServer(arguments);
|
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);
|
std::cout << exception.toString() << std::endl;
|
||||||
}
|
returnCode=-1;
|
||||||
else
|
}
|
||||||
{
|
catch(...)
|
||||||
std::cout << "Unknown command " << arguments[1] << std::endl;
|
{
|
||||||
|
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;
|
std::cout << "Done, total took " << Utility::formatNumber(profiler.end()) << "(ms)" << std::endl;
|
||||||
|
return returnCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// @brief [0]=program [1]=SERVERMODE [2]={port}
|
/// @brief [0]=program [1]=SERVERMODE [2]={port}
|
||||||
|
|||||||
@@ -105,13 +105,13 @@ bool SocketConnectionReceiver::handlePut(Block<String> &commands)
|
|||||||
{
|
{
|
||||||
double elapsedTimeSeconds = profiler.elapsed()/1000.00;
|
double elapsedTimeSeconds = profiler.elapsed()/1000.00;
|
||||||
double bytesPerSecond = totalBytesRead / elapsedTimeSeconds;
|
double bytesPerSecond = totalBytesRead / elapsedTimeSeconds;
|
||||||
String strBytesPerSecond = Utility::bytesTransferredToString(bytesPerSecond);
|
String strBytesPerSecond = Utility::byteCountToString(bytesPerSecond);
|
||||||
std::cout << "Transferred " << Utility::formatNumber(totalBytesRead) << " of " << Utility::formatNumber(fileLength) << " " << percent << " percent " << strBytesPerSecond << std::endl;
|
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 << "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();
|
writeFile.close();
|
||||||
return totalBytesRead==fileLength;
|
return totalBytesRead==fileLength;
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ size_t SocketConnectionReceiver::expectPacket(void)
|
|||||||
sb.append("Received an invalid PCKT command");
|
sb.append("Received an invalid PCKT command");
|
||||||
String str=sb.toString();
|
String str=sb.toString();
|
||||||
std::cout << str << std::endl;
|
std::cout << str << std::endl;
|
||||||
throw new InvalidOperationException(str);
|
throw InvalidOperationException(str);
|
||||||
}
|
}
|
||||||
if(!(subCommands[0]=="PCKT"))
|
if(!(subCommands[0]=="PCKT"))
|
||||||
{
|
{
|
||||||
@@ -138,7 +138,7 @@ size_t SocketConnectionReceiver::expectPacket(void)
|
|||||||
sb.append("Expected PCKT but received ").append(subCommands[0]);
|
sb.append("Expected PCKT but received ").append(subCommands[0]);
|
||||||
String str = sb.toString();
|
String str = sb.toString();
|
||||||
std::cout << str << std::endl;
|
std::cout << str << std::endl;
|
||||||
throw new InvalidOperationException(str);
|
throw InvalidOperationException(str);
|
||||||
}
|
}
|
||||||
size_t bufferLength = subCommands[1].toULong();
|
size_t bufferLength = subCommands[1].toULong();
|
||||||
return bufferLength;
|
return bufferLength;
|
||||||
|
|||||||
Reference in New Issue
Block a user