47pthread_mutex_t
mutex_tcp = PTHREAD_MUTEX_INITIALIZER;
57 std::cout <<
getEpoch() <<
"::" << NOW
58 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::SOCKET_"
63 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::SOCKET_CREATION_"
69 if (setsockopt(
servSockDescr, SOL_SOCKET, SO_REUSEADDR, &sockoptval,
sizeof(
int)) == -1) {
71 std::cout <<
getEpoch() <<
"::" << NOW
72 <<
"::UWAPPLICATION::ERROR::REUSABLE_FAIL"
77 std::cout <<
getEpoch() <<
"::" << NOW
78 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::SOCKET_CREATED"
85 servAddr.sin_addr.s_addr = htonl(INADDR_ANY);
91 std::cout <<
getEpoch() <<
"::" << NOW
92 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::BINDING_FAILED_"
93 << strerror(errno) << endl;
96 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::BINDING_FAILED_"
97 << strerror(errno) << endl;
104 std::cout <<
getEpoch() <<
"::" << NOW
105 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::LISTEN_FAILED"
109 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::LISTEN_FAILED"
114 std::cout <<
getEpoch() <<
"::" << NOW
115 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::SERVER_READY"
122 std::cout <<
getEpoch() <<
"::" << NOW
123 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::CANNOT_CREATE_"
128 <<
"::UWAPPLICATION::OPEN_CONNECTION_TCP::CANNOT_CREATE_"
145 socklen_t clnLen =
sizeof(sockaddr_in);
152 (
struct sockaddr *) &(obj->
clnAddr),
153 (socklen_t *) &clnLen)) < 0) {
155 std::cout << obj->
getEpoch() <<
"::" << NOW
156 <<
"::UWAPPLICATION::READ_PROCESS_TCP::CONNECTION_"
161 std::cout << obj->
getEpoch() <<
"::" << NOW
162 <<
"::UWAPPLICATION::READ_PROCESS_TCP::NEW_CLIENT_IP_"
163 << inet_ntoa(obj->
clnAddr.sin_addr) << std::endl;
166 <<
"::UWAPPLICATION::READ_PROCESS_TCP::NEW_CLIENT_IP_"
167 << inet_ntoa(obj->
clnAddr.sin_addr) << std::endl;
179 Packet *p = Packet::alloc();
184 if ((recvMsgSize = read(clnSock, buffer_msg,
MAX_READ_LEN)) < 0) {
186 std::cout <<
getEpoch() <<
"::" << NOW
187 <<
"::UWAPPLICATION::READ_PROCESS_TCP::HANDLE_TCP_"
189 "CONNECTION_NOT_ACCEPTED"
193 if (recvMsgSize == 0) {
194 shutdown(clnSock, 2);
197 int status = pthread_mutex_lock(&
mutex_tcp);
200 std::cout <<
getEpoch() <<
"::" << NOW
201 <<
"::UWAPPLICATION::PTHREAD_MUTEX_LOCK_FAILED "
205 std::cout <<
getEpoch() <<
"::" << NOW
206 <<
"::UWAPPLICATION::READ_PROCESS_TCP::PAYLOAD_"
208 for (
int i = 0; i < recvMsgSize; i++) {
209 cout << buffer_msg[i];
214 <<
"::UWAPPLICATION::READ_PROCESS_UDP::NEW_PACKET_"
217 for (
int i = 0; i < recvMsgSize; i++) {
220 hdr_cmn *ch = HDR_CMN(p);
221 ch->size() = recvMsgSize;
225 status = pthread_mutex_unlock(&
mutex_tcp);
228 std::cout <<
getEpoch() <<
"::" << NOW
229 <<
"::UWAPPLICATION::PTHREAD_MUTEX_UNLOCK_FAILED "
243 hdr_cmn *ch = HDR_CMN(ptmp);
251 ch->direction_ = hdr_cmn::DOWN;
252 ch->timestamp() = Scheduler::instance().clock();
270 std::cout <<
getEpoch() <<
"::" << NOW
271 <<
"::UWAPPLICATION::INIT_PACKET_TCP::UID_" << ch->uid_
274 std::cout <<
getEpoch() <<
"::" << NOW
275 <<
"::UWAPPLICATION::INIT_PACKET_TCP::DEST_"
276 << (int) uwiph->
daddr() << endl;
278 std::cout <<
getEpoch() <<
"::" << NOW
279 <<
"::UWAPPLICATION::INIT_PACKET_TCP::SIZE_"
282 std::cout <<
getEpoch() <<
"::" << NOW
283 <<
"::UWAPPLICATION::INIT_PACKET_TCP::SN_"
284 << (int) uwApph->
sn_ << endl;
286 std::cout <<
getEpoch() <<
"::" << NOW
287 <<
"::UWAPPLICATION::INIT_PACKET_TCP::INIT_PACKET_TCP::"
294 <<
"::UWAPPLICATION::INIT_PACKET_TCP::UID_" << ch->uid_
298 <<
"::UWAPPLICATION::INIT_PACKET_TCP::DEST_"
299 << (int) uwiph->
daddr() << endl;
302 <<
"::UWAPPLICATION::INIT_PACKET_TCP::SIZE_"
306 <<
"::UWAPPLICATION::INIT_PACKET_TCP::SN_"
307 << (int) uwApph->
sn_ << endl;
310 <<
"::UWAPPLICATION::INIT_PACKET_TCP::INIT_PACKET_TCP::"
uwSendTimerAppl chkTimerPeriod
Timer that schedule the period between two successive generation of DATA packets.
int servSockDescr
socket descriptor for server
int rftt
Forward trip time.
int debug_
Used for debug purposes 1 debug activated 0 debug not activated.
virtual void handleTCPclient(int clnSock)
Handle the communication between server and client.
virtual void incrPktsPushQueue()
Increase the number of DATA packets stored in the Server queue.
int uidcnt
Identifier counter that identify uniquely the DATA packet generated.
virtual int openConnectionTCP()
When socket communication is used, this method establish a connection between client and server.
int clnSockDescr
*socket descriptor for client
unsigned long int getEpoch()
Calculate the epoch of the event.
struct sockaddr_in servAddr
Server address.
std::ofstream out_log
Variable that handle the file in which the protocol write the statistics.
static uint MAX_READ_LEN
Maximum size (bytes) of a single read of the socket.
int port_num
Number of the port in which the server provide the service.
struct sockaddr_in clnAddr
Client address.
uint8_t dst_addr
IP destination address.
virtual double getPeriod()
return period generation time
std::queue< Packet * > queuePckReadTCP
Queue that store the DATA packets recevied from the client by the server using a TCP protocol.
virtual void init_Packet_TCP()
Set all the field of DATA packet and take from the specific queue the payload of DATA packet that wil...
int txsn
Transmission sequence number of DATA packet.
Content header of TRIGGER packet.
int rftt_
Forward Trip Time of the packet.
char payload_msg[MAX_LENGTH_PAYLOAD]
Message payload.
uint16_t sn_
Serial number of the packet.
bool rftt_valid_
Flag used to set the validity of the fft field.
uint16_t & payload_size()
uint8_t priority_
Priority flag: 1 means high priority, 0 normal priority.
hdr_uwip describes UWIP packets.
uint8_t & daddr()
Reference to the daddr_ variable.
static hdr_uwip * access(const Packet *p)
hdr_uwudp describes UWUDP packets.
static struct hdr_uwudp * access(const Packet *p)
uint8_t & dport()
Reference to the dport_ variable.
void * read_process_TCP(void *arg)
pthread_mutex_t mutex_tcp
packet_t PT_DATA_APPLICATION
Trigger packet type for UFetch protocol.
void * read_process_TCP(void *arg)