1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
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;
}
|