netduino / Netduino.IP_CC3100

Netduino.IP hybrid network stack (to be assimilated into Netduino.IP core)
7 stars 0 forks source link

Socket.SendTo/ReceiveFrom crash when send/receive timeouts are set #1

Open misenhower opened 9 years ago

misenhower commented 9 years ago

I noticed a crash when using SendTo and ReceiveFrom with sockets that have SendTimeout or ReceiveTimeout values set. As an example, the following code throws an ArgumentOutOfRange exception:

// Wait for DHCP
while (IPAddress.GetDefaultLocalAddress() == IPAddress.Any)
    Thread.Sleep(50);

// Set up a sample IP endpoint
IPAddress ip = Dns.GetHostEntry("time-a.nist.gov").AddressList[0];
EndPoint remoteEndPoint = new IPEndPoint(ip, 123);

// Set up a send/receive buffer with sample data
byte[] buffer = new byte[48];
buffer[0] = 0x1B;

using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp))
{
    socket.SendTimeout = 1000;
    socket.ReceiveTimeout = 1000;

    socket.SendTo(buffer, remoteEndPoint);
    socket.ReceiveFrom(buffer, ref remoteEndPoint);
}

If you comment out the SendTimeout line, the call to SendTo completes successfully. Similarly, commenting out the ReceiveTimeout line makes the ReceiveFrom call complete successfully.

This issue does not appear to be present when using the Send/Receive methods.

Please let me know if you need any more information. Thanks!