29int main(
int argc,
char* argv[])
32 unsigned int port = 0;
33 unsigned int sleep_time;
35 po::options_description desc(
"Options");
37 (
"help,h",
"Print this help and exit.")
39 po::value<std::string>(&filename)->required(),
40 "Set the name of the data file to send back to DQ or CLBSwissKnife.")
42 po::value<unsigned int>(&port)->required(),
43 "Set the UDP port to send the data through")
44 (
"sleep,s",po::value<unsigned int>(&sleep_time)->default_value(1000),
"sleep time between sending data packets (in microseconds)");
50 po::command_line_parser(argc, argv).options(desc).run(),
55 std::cout << desc << std::endl;
61 catch (
const po::error& e)
63 std::cerr <<
"CLBReplay: Error: " << e.what() <<
'\n'
67 catch (
const std::runtime_error& e)
69 std::cerr <<
"CLBReplay: Error: " << e.what() <<
'\n'
74 std::ifstream input_file(filename.c_str());
75 boost::asio::ip::udp::udp::endpoint endpoint(
76 boost::asio::ip::address::from_string(
"127.0.0.1"),
79 boost::asio::io_service service;
80 boost::asio::ip::udp::socket sock(service, boost::asio::ip::udp::udp::v4());
84 while (input_file && input_file.peek() != EOF)
86 unsigned int datagram_size = 0;
87 input_file.read((
char*) &datagram_size,
sizeof(datagram_size));
89 input_file.read(buffer, datagram_size);
91 sock.send_to(boost::asio::buffer(buffer, datagram_size), endpoint);
96 std::cout <<
"File finished\n";