/* # 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 #include #include #include #include #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 Receive to file FILE" << endl << " -addr Use ADDR as address specification" << endl << " -dport Send to port PORT" << endl << " -sport Send from port PORT" << endl << " -mtu Set MTU to BYTES" << endl << " -rate Send BYTES per second" << endl << " -winsize 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; }