-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExchangeConnectionHandlerUDPClient.cpp
129 lines (96 loc) · 5.46 KB
/
ExchangeConnectionHandlerUDPClient.cpp
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
#include "ExchangeConnectionHandlerUDPClient.h"
CExchangeConnectionHandlerUDPClient::CExchangeConnectionHandlerUDPClient(STExchangeConnectionInfo _ExConInfo)
{
this->m_ExchnageConnectionInfo = _ExConInfo;
this->m_BufferSize = _ExConInfo.BufferSize;
this->m_Connected = 0;
}
int CExchangeConnectionHandlerUDPClient::open ()
{
ACE_INET_Addr _endPoint(m_ExchnageConnectionInfo.Port, m_ExchnageConnectionInfo.IP.c_str());
// m_Inet_Addr(m_ExchnageConnectionInfo.Port, m_ExchnageConnectionInfo.IP.c_str());
m_Inet_Addr = _endPoint;
if(this->m_sockDgram.open(m_Inet_Addr)==-1 )
{
ACE_ERROR_RETURN ((LM_ERROR,"%p\n", "ACE_SOCK_Dgram::open"), -1);
return -1;
}
return 0;
}
bool CExchangeConnectionHandlerUDPClient::Start()
{
if( ACE_Thread::spawn((ACE_THR_FUNC)CExchangeConnectionHandlerUDPClient::Start_,this,
THR_JOINABLE | THR_NEW_LWP,
&m_processorThreadID,
&m_processorThreadHandle ) == -1 )
{
// TODO: Log
return false;
}
return true;
}
void CExchangeConnectionHandlerUDPClient::Start_( void* _param )
{
((CExchangeConnectionHandlerUDPClient*)_param)->Start_Callback();
}
void CExchangeConnectionHandlerUDPClient::Start_Callback()
{
while(m_bthreadContinue) // Connection loop
{
int nResult = open();
if(nResult !=-1 )
while(m_bthreadContinue)
{
int nBytesRead = m_sockDgram.recv(szMsg,1024,m_Inet_Addr);
if ( nBytesRead == -1 )
{
this->m_Connected = 0;
ACE_DEBUG( ( LM_DEBUG, "(%t) On %D\n" ) );
ACE_DEBUG( ( LM_DEBUG, "(%t) Not Receiveing data...\n\n" ) );
Sleep(1000);
continue;
}
if (nBytesRead > 0)
szMsg[nBytesRead]= '\0';
else
szMsg[1]= '\0';
if ( nBytesRead > 0 )
{
std::string _item = szMsg;
char _date[50];
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
strftime(_date,25,"%d %b %Y %H:%M:%S", timeinfo);
Last_Connection_Time = _date;
this->m_Connected = 1;
this->m_Queue.push(_item);
}
else
{
this->m_Connected = 2;
ACE_DEBUG( ( LM_DEBUG, "(%t) On %D\n" ) );
ACE_DEBUG( ( LM_DEBUG, "(%t) Incomming Connection From MDFServer is disconnected...\n\n" ) );
return;
}
}
}
}
bool CExchangeConnectionHandlerUDPClient::Destroy( void )
{
m_bthreadContinue = false;
return true;
}
CExchangeConnectionHandlerUDPClient::~CExchangeConnectionHandlerUDPClient(void)
{
}
bool CExchangeConnectionHandlerUDPClient::Create( void )
{
m_bthreadContinue = true;
return Start();
}
std::string CExchangeConnectionHandlerUDPClient::GetMessage( std::string& )
{
return std::string();
}