Yes, that code looks ugly. You are using strlen(buff), not the real buffer size. strlen() will just scan the buffer (and the memory after it) until it finds a NUL character, so you will get any arbitrary value. recv will use that value, and if it is higher than the actual buffer size, it will overwrite memory after the buffer (in your case, appearently it hits at least m_socket). So make sure you pass the actual buffer size, don't use strlen for that.Quote:
Originally posted by andreshs1
Code:ioctlsocket(m_socket,FIONREAD,&size); //here the value of socket it is fine
while(size > 0)
{
rtn = recv(m_socket,buff,strlen(buff),0); //the value of socket disappears,
//and doesn't receive anything
...
}
