1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| BOOL _KeepAlive(SP_SOCKET fd) { struct KeepAlive { u_long onoff; u_long keepalivetime; u_long keepaliveinterval; };
#define SIO_KEEPALIVE_VALS _WSAIOW(IOC_VENDOR,4)
KeepAlive inKeepAlive = { 0 }; unsigned long ulInLen = sizeof(KeepAlive);
KeepAlive outKeepAlive = { 0 }; unsigned long ulOutLen = sizeof(KeepAlive); unsigned long ulBytesReturn = 0;
inKeepAlive.onoff = 1; inKeepAlive.keepaliveinterval = 5000; inKeepAlive.keepalivetime = 5000;
if (WSAIoctl((SOCKET)fd, SIO_KEEPALIVE_VALS, (LPVOID)&inKeepAlive, ulInLen, (LPVOID)&outKeepAlive, ulOutLen, &ulBytesReturn, NULL, NULL) == SOCKET_ERROR) { LOGT("Set Keep Alive FAILED."); return FALSE; } else { LOGT("Set Keep Alive OK."); return TRUE; }
}
|