Gentlefolk,
I am porting a product that was originally written for Windows NT using Visual C++ 6, to run on Windows 7 using Visual C++ 2010. (We have gone through the intermediate step of Windows XP and Visual C++ 6.0 a few years ago.) The problem
I describe below did not manifest on either Windows NT nor Windows XP, but does on Windows 7.
The problem I am getting at the moment is that "short lived clients" are not sending all their data to the server. A scenario would be, assuming a continuously running (TCP/IP) server:
- Client connects to server
- Client sends small amount of data. (I cannot quantify "small" precisely at the moment -- I can say that I would expect it to be more than 10 bytes, but less than 250 bytes.
- Client disconnects from the server.
The above all happens in sequential code. The server in this case does not send any data to the client.
Now to fill in the detail. We are using the normal CArchive / CSocket / CSocketFile combination to communicate between the client and the server. I can confirm that having serialised into the CArchive instance it is flushed. For good measure I have also
added a Flush to the CSocketFile after flushing the CArchive. I have discovered that adding a sleep between sending the data and disconnecting does solve the problem -- but I am very reluctant to use this as the final solution for obvious reasons. The MFC
objects are cleaned up after the final disconnect.
I have tried to use the SO_LINGER socket option, with l_onoff = 1 and l_linger = 5. This had some success in that on Windows 7 (32bit) -- the data was sent, however the connection did not close (even after the 5 seconds specified by l_linger). Using netstat, the connection remained ESTABLISHED, even minutes after the disconnection. On Windows 7 (64bit) the original problem remains, i.e. the data is not sent. (Note the application was built as a 32 bit executable).
I would like to give you code samples, but trying to produce a minimal sample that exhibits the problem is not easy. For IPR reasons I cannot publish the actual code I am working with.
I find it hard to believe that this is a fundamental problem with Windows 7 or the MFC classes in VC++ 2010 -- if it were I am sure others would be screaming about it. More likely there is some subtle mistake in our approach. If anyone could suggest areas for me to investigate, or offer a "likely cause & solution" for my problem, I would be very grateful.
Thanks,
Andrew Ch.