summaryrefslogtreecommitdiffstats
path: root/src/net/mcast/trial_programs/mcastreceive.cpp
diff options
context:
space:
mode:
authorSebastien Braun2010-10-06 00:04:49 +0200
committerSebastien Braun2010-10-06 00:04:49 +0200
commitf07fc3b426815e28fde23313242fbbb998a08d45 (patch)
treeba9eda1a83135a1727d2d35661d6facabee53b95 /src/net/mcast/trial_programs/mcastreceive.cpp
parentFix recognition of letters in keyboard handler (diff)
parentMerge remote branch 'openslx/master' into mcastft (diff)
downloadpvs-f07fc3b426815e28fde23313242fbbb998a08d45.tar.gz
pvs-f07fc3b426815e28fde23313242fbbb998a08d45.tar.xz
pvs-f07fc3b426815e28fde23313242fbbb998a08d45.zip
Merge remote branch 'openslx/mcastft' into input
Conflicts: CMakeLists.txt i18n/pvs_ar_JO.ts i18n/pvs_de_DE.ts i18n/pvs_es_MX.ts i18n/pvs_fr_FR.ts i18n/pvs_pl_PL.ts i18n/pvsmgr_ar_JO.ts i18n/pvsmgr_de_DE.ts i18n/pvsmgr_es_MX.ts i18n/pvsmgr_fr_FR.ts i18n/pvsmgr_pl_PL.ts icons/README pvsmgr.qrc src/gui/mainWindow.cpp src/pvs.cpp src/pvs.h src/pvsDaemon.cpp src/util/clientGUIUtils.h
Diffstat (limited to 'src/net/mcast/trial_programs/mcastreceive.cpp')
-rw-r--r--src/net/mcast/trial_programs/mcastreceive.cpp150
1 files changed, 150 insertions, 0 deletions
diff --git a/src/net/mcast/trial_programs/mcastreceive.cpp b/src/net/mcast/trial_programs/mcastreceive.cpp
new file mode 100644
index 0000000..48a0f10
--- /dev/null
+++ b/src/net/mcast/trial_programs/mcastreceive.cpp
@@ -0,0 +1,150 @@
+/*
+# Copyright (c) 2009 - OpenSLX Project, Computer Center University of Freiburg
+#
+# This program is free software distributed under the GPL version 2.
+# See http://openslx.org/COPYING
+#
+# If you have any feedback please consult http://openslx.org/feedback and
+# send your suggestions, praise, or complaints to feedback@openslx.org
+#
+# General information about OpenSLX can be found at http://openslx.org/
+# -----------------------------------------------------------------------------
+# src/net/mcast/trial_programs/mcastsend.cpp
+# - Receive a file via the PVS Mcast protocol
+# -----------------------------------------------------------------------------
+*/
+
+#include <iostream>
+
+#include <QCoreApplication>
+#include <QFile>
+#include <QStringList>
+#include <QTimer>
+
+#include "mcastreceive.h"
+#include "McastConfigArgParser.h"
+#include "../McastConfiguration.h"
+#include "../McastReceiver.h"
+
+using namespace std;
+
+int main(int argc, char** argv)
+{
+ QCoreApplication app(argc, argv);
+ McastReceive me;
+
+ QTimer::singleShot(0, &me, SLOT(run()));
+
+ return app.exec();
+}
+
+void McastReceive::run()
+{
+ QStringList args = QCoreApplication::arguments();
+ QStringList::iterator i = args.begin();
+ QStringList::iterator const end = args.end();
+
+ QString filename("");
+
+ McastConfiguration config;
+
+ ++i;
+ while (i != end)
+ {
+ QString arg = *i;
+
+ cerr << "Arg: " << arg.toLatin1().constData() << endl;
+
+ if (arg == "-file")
+ {
+ ++i;
+ if (i == end)
+ {
+ cerr << "Option " << arg.toLatin1().constData() << " is missing its argument" << endl;
+ QCoreApplication::exit(1);
+ return;
+ }
+ filename = *i;
+ }
+ else if (arg == "-help")
+ {
+ cerr << "Options:" << endl << endl
+ << " -file <FILE> Receive to file FILE" << endl
+ << " -addr <ADDR> Use ADDR as address specification" << endl
+ << " -dport <PORT> Send to port PORT" << endl
+ << " -sport <PORT> Send from port PORT" << endl
+ << " -mtu <BYTES> Set MTU to BYTES" << endl
+ << " -rate <BYTES> Send BYTES per second" << endl
+ << " -winsize <SECONDS> Set Window Size to SECONDS" << endl
+ << " -udp Use UDP encapsulation" << endl
+ << " -udp-port PORT Use UDP port PORT" << endl;
+ QCoreApplication::quit();
+ return;
+ }
+ else
+ {
+ if (!parseMcastConfigArg(i, end, &config))
+ {
+ cerr << "Unknown argument: " << arg.toLatin1().constData() << endl;
+ QCoreApplication::exit(1);
+ return;
+ }
+ }
+
+ ++i;
+ }
+
+ if (filename == "")
+ {
+ cerr << "No Filename given" << endl;
+ QCoreApplication::exit(1);
+ return;
+ }
+
+ _target = new QFile(filename, this);
+ _target->open(QIODevice::WriteOnly);
+
+ McastReceiver* recv = new McastReceiver(_target, &config, this);
+
+ connect(recv, SIGNAL(finished(int)), this, SLOT(finished(int)));
+
+ QTimer::singleShot(0, recv, SLOT(start()));
+}
+
+void McastReceive::finished(int state)
+{
+ cerr << "finished: ";
+
+ switch(state)
+ {
+ case McastReceiver::RES_OK:
+ cerr << "OK." << endl;
+ break;
+ case McastReceiver::RES_ABORTED:
+ cerr << "Aborted." << endl;
+ goto failed;
+ case McastReceiver::RES_CHECKSUM_MISMATCH:
+ cerr << "Checksum mismatch." << endl;
+ goto failed;
+ case McastReceiver::RES_CONNECTION_RESET:
+ cerr << "Connection reset." << endl;
+ goto failed;
+ case McastReceiver::RES_MD5_MISMATCH:
+ cerr << "MD5 mismatch." << endl;
+ goto failed;
+ case McastReceiver::RES_OFFSET_MISMATCH:
+ cerr << "Offset mismatch. Undetected packet loss?" << endl;
+ goto failed;
+ default:
+ cerr << "Unknown error code!" << endl;
+ goto failed;
+ }
+
+ QCoreApplication::quit();
+ return;
+failed:
+ cerr << "Deleting file." << endl;
+ _target->remove();
+ QCoreApplication::exit(1);
+ return;
+}