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
|
void __fastcall TPSM_OperatorClientForm::csktClientSocketRead(
TObject *Sender, TCustomWinSocket *Socket)
{
try
{
bool done = false;
int bytes = 0;
static int bytesLeft = 0;
int msgBytes = 0;
int offset = 0;
struct PSM_Message *msg = 0;
// Allocate memory to receive message
static char *ptr;
static char buf[MAX_SIZE];
ptr = buf;
// Read the message from the socket
// bytes = Socket->ReceiveBuf((void*)(ptr + bytesLeft), (MAX_SIZE - bytesLeft));
bytes = Socket->ReceiveBuf((void*)(ptr + offset), (MAX_SIZE - bytesLeft));
// Set the bytes left value
bytesLeft += bytes;
// Are there messages to be dispatched
int iTotalLen = 0;
while(1)
{
void *cpyBuff = 0;
// Get the 1st message
msg = (struct PSM_Message *)&(ptr[offset]);
msgBytes = msg->m_size;
if(msgBytes <= 0 || msgBytes > 4096)
{
msgBytes = bytesLeft;
// return;
}
WriteLog("cpyBuff size is %d", cpyBuff);
WriteLog("msg size is %d", msg);
WriteLog("BytesLeft size is %d", bytesLeft);
WriteLog("msgBytes size is %d", msgBytes);
if(bytesLeft < msgBytes)//badri
break;
// return;
// Allocate copy buffer for message
cpyBuff = calloc(msg->m_size, sizeof(char));
// cpyBuff = calloc(msgBytes, sizeof(char));
// cpyBuff = malloc(msgBytes);
if( cpyBuff == NULL)
return;
// Copy the 1st message to the copy buffer
::memmove((void *)cpyBuff, (const void *)&(ptr[offset]), sizeof(char) * msgBytes);
iTotalLen += sizeof(char) * msgBytes;
// Move the offset
offset += msg->m_size;
if(msg->m_messageID == MSG_SM_OC_DATABASE_PATH_INFO)
{
WriteLog("OperatorCLientForm : Connected to server received - MSG_SM_OC_DATABASE_PATH_INFO");
LogonRequest(msg);
free(cpyBuff);
}
else
{
if (!::PostThreadMessage(pRouterThread->ThreadID, msg->m_messageID, (WPARAM)cpyBuff, 0))
{
//Savita 11/dec/2001
AnsiString str = " PostMsgFailed --The Error Code returned " + AnsiString(GetLastError());
WriteLog(L_ERROR,str.c_str());
free(cpyBuff);
//If it has not deleted also create this thread inorder to maintain the continuity
pRouterThread = NULL;
pRouterThread = new PSM_RouterThread(false);
//Viswanath 12/dec/2001
if(pRouterThread != NULL)
{
WriteLog("OperatorCLientForm : Creating New Router Thread");
}
else
{
//Display a message stating that the resources is low. Shut down OC gracefully
//MessageBox(Handle,"System running low on resources.....Shutting down Operator Client","MMPOSEM Error",MB_OK |MB_SYSTEMMODAL );
MessageBox(Handle,GetString(IDS_ERR_SYSTEM_LOW_RESOURCES).c_str(),
GetString(IDS_ERR_IPOS_ERROR).c_str(),
MB_OK |MB_SYSTEMMODAL );
exit(-1);
}
}
}
// adjust the bytes left value
bytesLeft -= msg->m_size;
if (bytesLeft < 0) //if bytesLeft is less than zero
{
WriteLog("size of m_size is @ line 6833 %d", sizeof(msg->m_size));
bytesLeft = 0;
return;
}
// Check to see if we have dispatched ALL the messages in the buffer
if(bytesLeft < 8) //badri if bytesLeft is Less than 8
{
::memmove((void *)ptr, (const void *)&(ptr[iTotalLen]), sizeof(char) * bytesLeft);
return;
}
// Reset locals
cpyBuff = 0;
msg = 0;
}
// Free the Rx buffer
free(ptr);
#ifdef COMMOUT
//Process the message
try
{
if ( msg->m_messageID == MSG_SM_OC_DATABASE_PATH_INFO )
{
WriteLog("OperatorCLientForm : Connected to server received - MSG_SM_OC_DATABASE_PATH_INFO");
LogonRequest(msg);
}
else
{
::PostThreadMessage(pRouterThread->ThreadID, msg->m_messageID, (WPARAM)msg,0);
}
}
catch(...)
{
//ShowMessage("Server not located");
ShowMessage( GetString(ID_SVR_NOT_LOC) );
PSM_TransFilterForm->TransGridHeaderDisplay();
}
#endif
}
catch(...)
{
WriteLog(L_ERROR,"TPSM_OperatorClientForm :: csktClientSocketRead Failed ");
}
}
|