private bool setKeepAlive(Socket sock, ulong time, ulong interval)
{
try
{
// resulting structure
byte[] SIO_KEEPALIVE_VALS = new byte[3*bytesperlong];
// array to hold input values
ulong[] input = new ulong[3];
// put input arguments in input array
if (time == 0 || interval == 0) // enable disable keep-alive
input[0] = (0UL); // off
else
input[0] = (1UL); // on
input[1] = (time); // time millis
input[2] = (interval); // interval millis
// pack input into byte struct
for (int i = 0; i < input.Length; i++)
{
SIO_KEEPALIVE_VALS[i*bytesperlong + 3] =
(byte) (input[i] >> ((bytesperlong - 1)*bitsperbyte) & 0xff);
SIO_KEEPALIVE_VALS[i*bytesperlong + 2] =
(byte) (input[i] >> ((bytesperlong - 2)*bitsperbyte) & 0xff);
SIO_KEEPALIVE_VALS[i*bytesperlong + 1] =
(byte) (input[i] >> ((bytesperlong - 3)*bitsperbyte) & 0xff);
SIO_KEEPALIVE_VALS[i*bytesperlong + 0] =
(byte) (input[i] >> ((bytesperlong - 4)*bitsperbyte) & 0xff);
}
// create bytestruct for result (bytes pending on server socket)
byte[] result = BitConverter.GetBytes(0);
// write SIO_VALS to Socket IOControl
sock.IOControl(IOControlCode.KeepAliveValues, SIO_KEEPALIVE_VALS, result);
ByteDump(result);
}
catch (Exception)
{
return false;
}
return true;
}