I came to an eccentric phenomenon when running my program.
My process accepts TCP connections and then reads data from the socket. It had been worked allright for months on the other servers. For the sake of test, I ran it on a new server. At the begin, everything was OK. Six or Seven hours later, it didnt work!
So I gdbed to look into it. I found there is something strange happened when exec the following code:
1 2 3
|
iRet = NBlockTcpRead(pstClient->iSock,
(char*)(&pstClient->stPkg) + pstClient->iRecvLen,
sizeof(CSPKGHEAD) - pstClient->iRecvLen);
|
and NBlockTcpRead implemented as
|
int CZoneCon::NBlockTcpRead(int iSockFd,char *pRecvBuff,int iRecvLen)
|
I checked pstClient->iSock before executed NBlockTcpRead, and it showed pstClient->iSock = 4, and sizeof(CSPKGHEAD) - pstClient->iRecvLen = 16.
But when I steped into NBlockTcpRead, it showed that iSockFd is some negative number, and iRecvLen = 0. When executed this function, I checked the pstClient again, pstClient->iSock = 4 all the same!
And my workmate told me that when he ran a process on this server, he tried to get the pointer of an Object and save in a var, but when using this val, the value in the var was different from the value, pointer of that object, that he assigned before. We checked the codes together, and were sure of that the var had never been reassigned between his assigning and using. Also, the process runs correctly on the other severs.
Why? Has somebody ever met such problems?