/usr/include/itpp/protocol/tcp_client_server.h is in libitpp-dev 4.3.1-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | /*!
* \file
* \brief Definitions of TCP Client and Server Applications
* \author Krister Norlund
*
* -------------------------------------------------------------------------
*
* Copyright (C) 1995-2010 (see AUTHORS file for a list of contributors)
*
* This file is part of IT++ - a C++ library of mathematical, signal
* processing, speech processing, and communications classes and functions.
*
* IT++ is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* IT++ is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along
* with IT++. If not, see <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef TCP_CLIENT_SERVER_H
#define TCP_CLIENT_SERVER_H
#include <itpp/itexports.h>
#if (defined(_MSC_VER) && defined(ITPP_SHARED_LIB) && !defined(itpp_EXPORTS))
#ifndef ITPP_PROTOCOL_EXCLUDED
#define ITPP_PROTOCOL_EXCLUDED
#pragma message( "PROTOCOL definitions are not available for MSVC shared builds" )
#endif
#else
#include <itpp/protocol/tcp.h>
namespace itpp
{
//! \addtogroup protocol
//@{
/*! ADD DOCUMENTATION HERE
*/
class TCP_Server_Application
{
public:
//! Default constructor
TCP_Server_Application() {
write.set_name("TcpServerApplicationWriteSignal");
write.set_debug();
}
//! Destructor
~TCP_Server_Application() { }
//! ADD DOCUMENTATION HERE
Signal<itpp::Packet*> write;
//! ADD DOCUMENTATION HERE
void write_to_net(unsigned byte_size, double delta_time) {
itpp::Packet *packet = new Packet(8*byte_size);
write(packet, delta_time);
std::cout << "TcpServerApplication::write_to_net,"
<< " byte_size=" << packet->bit_size() / 8
<< " ptr=" << packet
<< " time=" << Event_Queue::now() << std::endl;
}
};
/*! ADD DOCUMENTATION HERE
*/
class TCP_Client_Application
{
public:
//! Default constructor
TCP_Client_Application(TCP_Sender *tcp_snd_p, TCP_Receiver *tcp_recv_p) {
tcp_receiver_p = tcp_recv_p;
tcp_sender_p = tcp_snd_p;
nbr_bytes_received = 0;
select.forward(this, &TCP_Client_Application::received_packet_indication);
select.set_name("TcpClientApplicationSelectSlot");
seq_num_index = 0;
}
//! Destructor
~TCP_Client_Application() { }
//! ADD DOCUMENTATION HERE
Slot<TCP_Client_Application, int> select;
//! ADD DOCUMENTATION HERE
void read_from_net(unsigned byte_size) {
nbr_bytes_to_receive = byte_size;
seq_num_val.set_size(10 + byte_size / 1460);
seq_num_val.zeros();
seq_num_time.set_size(10 + byte_size / 1460);
seq_num_time.zeros();
seq_num_val(0) = 0;
seq_num_time(0) = 0;
seq_num_index = 1;
};
private:
TCP_Receiver *tcp_receiver_p;
TCP_Sender *tcp_sender_p;
unsigned nbr_bytes_received;
unsigned nbr_bytes_to_receive;
vec seq_num_val;
vec seq_num_time;
int seq_num_index;
void TCP_Client_Application::received_packet_indication(int label) {
itpp::Packet &packet = tcp_receiver_p->get_user_message();
nbr_bytes_received = nbr_bytes_received + packet.bit_size() / 8;
delete &packet;
if (seq_num_index >= seq_num_time.size()) {
seq_num_time.set_size(2*seq_num_time.size(), true);
seq_num_val.set_size(2*seq_num_val.size(), true);
}
seq_num_val(seq_num_index) = nbr_bytes_received;
seq_num_time(seq_num_index) = Event_Queue::now();
seq_num_index++;
std::cout << "### sequence number: " << nbr_bytes_received
<< " ### time:" << Event_Queue::now() << std::endl;
if (nbr_bytes_received >= nbr_bytes_to_receive) {
std::cout << "###### Stop sender and receiver" << std::endl;
tcp_receiver_p->release();
tcp_sender_p->release();
tcp_sender_p->save_trace("seq_num.it");
seq_num_val.set_size(seq_num_index, true);
seq_num_time.set_size(seq_num_index, true);
save_to_file("seq_num.it");
}
}
void TCP_Client_Application::save_to_file(string file) {
it_file ff2(file);
ff2 << Name("seq_num_val") << seq_num_val;
ff2 << Name("seq_num_time") << seq_num_time;
ff2 << Name("seq_num_index") << seq_num_index;
ff2.flush();
ff2.close();
}
};
//@}
} // namespace itpp
#endif
#endif //TCP_CLIENT_SERVER_H
|