Has anyone seen similar behavior on Win95? Know if MS has made an
official statement in regards to this?
thanks,
--rich
/* the following code works correctly (in my opinion) over NT 4.0
* wsock32.dll but does not work over win95 wsock32.dll. What happens
* on 95 is that after the first recvfrom() fails with WSAEINTR, the
* next two recvfrom() calls also fail immediately with the same error
* (note: myblockinghook() is never called again.) NT 4.0 will
* correctly call recvfrom() 3 times and will call myblockinghook()
* in the background waiting for the user to cancel each call.
*/
#include <windows.h>
#include <iostream.h>
extern "C" {
#include <stdio.h>
#include <conio.h>
int WINAPI myblockinghook(void);Quote:}
int main()
{
SOCKET s;
WSADATA data;
int ret;
struct sockaddr_in addr;
WSAStartup(0x0101, &data);
int (WINAPI *fp)(void) = myblockinghook;
if(!WSASetBlockingHook(fp))
cout << "Blocking Hook installed.\n";
char buffer[256];
for(int i=0;i<3;i++) {
cout << "iteration: " << i+1 << endl;
s = socket(PF_INET, SOCK_DGRAM, 0);
cout << "socket() returns: " << s << "\t\t\tWSAGetLastError():
"
<< WSAGetLastError() << endl;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = 0;
addr.sin_port = 0;
ret = bind(s, (LPSOCKADDR)&addr, sizeof(addr));
cout << "bind() returns: " << ret << "\t\t\tWSAGetLastError():
"
<< WSAGetLastError() << endl;
cout << "Hit a key to cancel recvfrom():...\n";
// recv() fails the same way....
// ret = recv(s, buffer, sizeof(buffer), 0 );
ret = recvfrom(s, buffer, sizeof(buffer), 0, NULL, NULL);
cout << "recvfrom() returns: " << ret <<
"\t\t\tWSAGetLastError(): "
<< WSAGetLastError() << endl;
ret = closesocket(s);
cout << "closesocket() returns: " << ret <<
"\t\tWSAGetLastError(): "
<< WSAGetLastError() << endl;
}
WSAUnhookBlockingHook();
WSACleanup();
return 0;
int WINAPI myblockinghook()Quote:}
{
cout << "\\\r|\r/\r";
if(_kbhit()) {
_getch();
cout << "WSACancelBlockingCall() returns: " <<
WSACancelBlockingCall() << "\tWSAGetLastError(): " << WSAGetLastError() <<
endl;
}
return 0;
Quote:}