BUG: recv() Causes Data Corruption of Large BufferLast reviewed: January 15, 1998Article ID: Q168187 |
The information in this article applies to:
SYMPTOMSData buffers passed to the Windows Sockets recv() function have the potential to lose the data they contain. This problem only affects buffers passed to recv(). Data buffers manipulated solely by the application or by API's other than recv() are not affected by this problem.
CAUSEThe recv() function accepts a buffer to be filled with data received over a socket connection. For memory management purposes, the system may discard portions of such a buffer to allow other memory activity of the system to proceed successfully. When the system does this, it first checks the memory page's "dirty" bit to determine if the page should be written to the paging file before being discarded. When the memory is later needed, it is retrieved from the paging file intact. The memory pages touched by recv() are supposed to be marked "dirty" when modified so that the pages will be properly written to the system paging file before the memory is discarded. In Windows 95, the pages are not marked "dirty." This causes the pages to be discarded without first being written to the paging file. When the data is later needed by the application, it is treated like newly-allocated zero-initialized memory. Such data received over the socket connection earlier is now lost.
RESOLUTIONThere is no absolutely effective workaround to this problem. One thing that may work is to use small buffers with the recv() function. This reduces the risk that some portion of the buffer will need to be swapped out and subsequently lost. Note that this reduces the risk but doesn't completely alleviate it. Alternatively, a program may dirty each page manually just before or after calling recv(). A program can dirty each page by writing data to one of the bytes in each page. The system page size on Windows 95 is 4096 (4K) bytes so a program only needs to touch a single byte in each 4K section of the buffer. This causes the pages to be properly written to the paging file before the memory is discarded, if necessary. The only drawback to this method is that there is no way to determine when a page will be paged out. If a page is paged out at an inopportune time, then the data it contains may be lost.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
|
Additional query words: winsock bse base
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |