many changes, need testing
rewrite PIDiagnostics, but not fully testing change PIQueue to PIDeque many fixes in PIBaseTransfer, it will be threadsafe and stable git-svn-id: svn://db.shs.com.ru/pip@187 12ceb7fc-bf1f-11e4-8940-5bc7170c53b5
This commit is contained in:
@@ -8,17 +8,25 @@ using namespace PICoutManipulators;
|
||||
class UDPFileTransfer: public PITimer {
|
||||
PIOBJECT_SUBCLASS(UDPFileTransfer, PITimer)
|
||||
public:
|
||||
UDPFileTransfer(const PIString &src_ip_port, const PIString &dst_ip_port) {
|
||||
UDPFileTransfer(const PIString &src_ip_port, const PIString &dst_ip_port, bool test = false) {
|
||||
quet_ = false;
|
||||
test_ = test;
|
||||
eth.setReadAddress(src_ip_port);
|
||||
eth.setSendAddress(dst_ip_port);
|
||||
ft.setPacketSize(8192);
|
||||
ft.setName("PIFT");
|
||||
CONNECTU(&ft, sendRequest, this, ftsend);
|
||||
CONNECTU(&ft, sendFilesStarted, this, ftevent);
|
||||
CONNECTU(&ft, receiveFilesStarted, this, ftevent);
|
||||
CONNECTU(&ft, sendFilesFinished, this, ftevent);
|
||||
CONNECTU(&ft, receiveFilesFinished, this, ftevent);
|
||||
if (test_) {
|
||||
testt.setPacketSize(1280);
|
||||
testt.setName("TEST");
|
||||
//testt.setTimeout(0.1);
|
||||
CONNECTU(&testt, sendRequest, this, ftsend);
|
||||
} else {
|
||||
ft.setPacketSize(1280);
|
||||
ft.setName("PIFT");
|
||||
CONNECTU(&ft, sendRequest, this, ftsend);
|
||||
CONNECTU(&ft, sendFilesStarted, this, ftevent);
|
||||
CONNECTU(&ft, receiveFilesStarted, this, ftevent);
|
||||
CONNECTU(&ft, sendFilesFinished, this, ftevent);
|
||||
CONNECTU(&ft, receiveFilesFinished, this, ftevent);
|
||||
}
|
||||
CONNECTU(ð, threadedReadEvent, this, received);
|
||||
start(50);
|
||||
eth.setParameter(PIEthernet::SeparateSockets);
|
||||
@@ -31,7 +39,14 @@ public:
|
||||
ft.send(file);
|
||||
}
|
||||
|
||||
void startTest() {
|
||||
PIByteArray ba(1024*1024*64);
|
||||
testt.send(ba);
|
||||
}
|
||||
|
||||
PIFileTransfer ft;
|
||||
PIDataTransfer testt;
|
||||
bool test_;
|
||||
|
||||
private:
|
||||
PIEthernet eth;
|
||||
@@ -44,30 +59,50 @@ private:
|
||||
ft.stopSend();
|
||||
ft.stopReceive();
|
||||
}
|
||||
// piCout << (int)ft.diagnostic().quality();
|
||||
// piCout << (int)ft.diagnostic().quality();
|
||||
}
|
||||
if (testt.isSending() || testt.isReceiving()) ftevent();
|
||||
}
|
||||
|
||||
EVENT_HANDLER(void, ftevent) {
|
||||
if (test_) {
|
||||
|
||||
#ifdef WINDOWS
|
||||
piCout
|
||||
#else
|
||||
PICout(AddSpaces) << ClearLine
|
||||
#endif
|
||||
<< testt.stateString()
|
||||
<< testt.diagnostic().receiveSpeed()
|
||||
<< testt.diagnostic().sendSpeed()
|
||||
<< "("
|
||||
<< PIString::readableSize(testt.bytesCur()) << "/" << PIString::readableSize(testt.bytesAll())
|
||||
<< ")"
|
||||
#ifndef WINDOWS
|
||||
<< Flush
|
||||
#endif
|
||||
;
|
||||
return;
|
||||
}
|
||||
if (quet_) return;
|
||||
|
||||
#ifdef WINDOWS
|
||||
piCout
|
||||
#else
|
||||
piCout
|
||||
#else
|
||||
PICout(AddSpaces) << ClearLine
|
||||
#endif
|
||||
#endif
|
||||
<< ft.stateString() << ft.curFile()
|
||||
<< PIString::readableSize(ft.diagnostic().receiveBytesPerSec()) + "/s"
|
||||
<< PIString::readableSize(ft.diagnostic().sendBytesPerSec()) + "/s"
|
||||
<< ft.diagnostic().receiveSpeed()
|
||||
<< ft.diagnostic().sendSpeed()
|
||||
<< "(" << PIString::readableSize(ft.bytesFileCur()) << "/" << PIString::readableSize(ft.bytesFileAll()) << ", "
|
||||
<< PIString::readableSize(ft.bytesCur()) << "/" << PIString::readableSize(ft.bytesAll()) << ")"
|
||||
<< "ETA" << (ft.diagnostic().receiveBytesPerSec() > 0 ?
|
||||
PIString::fromNumber(PISystemTime::fromSeconds((ft.bytesAll() - ft.bytesCur()) /
|
||||
ft.diagnostic().receiveBytesPerSec()).toSeconds())
|
||||
: PIString("unknown"))
|
||||
#ifndef WINDOWS
|
||||
#ifndef WINDOWS
|
||||
<< Flush
|
||||
#endif
|
||||
#endif
|
||||
;
|
||||
}
|
||||
|
||||
@@ -77,6 +112,10 @@ private:
|
||||
|
||||
EVENT_HANDLER2(void, received, uchar * , readed, int, size) {
|
||||
PIByteArray ba(readed, size);
|
||||
if(test_) {
|
||||
testt.received(ba);
|
||||
return;
|
||||
}
|
||||
ft.received(ba);
|
||||
}
|
||||
};
|
||||
@@ -95,13 +134,14 @@ void usage() {
|
||||
piCout << "-p " << Green << "- UDP port for transfer, by default 50005";
|
||||
piCout << "-d <work_dir> " << Green << "- directory, where place received files";
|
||||
piCout << "<path> " << Green << "- add path to send, if no path, then \"pift\" working in receive mode";
|
||||
piCout << "-t " << Green << "- test mode";
|
||||
}
|
||||
|
||||
|
||||
int main (int argc, char * argv[]) {
|
||||
PICLI cli(argc, argv);
|
||||
PIINTROSPECTION_START
|
||||
cli.setOptionalArgumentsCount(-1);
|
||||
cli.setOptionalArgumentsCount(-1);
|
||||
cli.addArgument("send", true);
|
||||
cli.addArgument("receive", true);
|
||||
cli.addArgument("dir", true);
|
||||
@@ -109,6 +149,28 @@ int main (int argc, char * argv[]) {
|
||||
cli.addArgument("help");
|
||||
cli.addArgument("quet");
|
||||
cli.addArgument("fullpath");
|
||||
cli.addArgument("test", true);
|
||||
if (cli.hasArgument("test")) {
|
||||
PIString src;
|
||||
PIString dst;
|
||||
bool send_ = false;
|
||||
if (cli.argumentValue("test") == "1") {
|
||||
src = "127.0.0.1:50005";
|
||||
dst = "127.0.0.1:50006";
|
||||
send_ = true;
|
||||
} else {
|
||||
src = "127.0.0.1:50006";
|
||||
dst = "127.0.0.1:50005";
|
||||
}
|
||||
if (cli.hasArgument("send") && cli.hasArgument("receive") && cli.hasArgument("fullpath")) {
|
||||
src = cli.argumentValue("receive");
|
||||
dst = cli.argumentValue("send");
|
||||
}
|
||||
UDPFileTransfer tuf(src, dst, true);
|
||||
if (send_) tuf.startTest();
|
||||
WAIT_FOREVER;
|
||||
return 0;
|
||||
}
|
||||
if ((!cli.hasArgument("send") || !cli.hasArgument("receive")) || cli.hasArgument("help")) {
|
||||
usage();
|
||||
return 0;
|
||||
@@ -137,8 +199,9 @@ int main (int argc, char * argv[]) {
|
||||
} else {
|
||||
piCout << "wait for receiving";
|
||||
}
|
||||
kbd.start();
|
||||
WAIT_FOR_EXIT
|
||||
PICout(0) << "\n";
|
||||
PICout(0) << "\n";
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user