Bug 22166 - Setting Socket.ReceiveTimeout to -1 fails
Summary: Setting Socket.ReceiveTimeout to -1 fails
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: master
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-08-18 10:05 UTC by Ivo Smits
Modified: 2014-08-26 12:32 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Ivo Smits 2014-08-18 10:05:32 UTC
Attempting to set Socket.ReceiveTimeout to -1 on a connected TCP socket fails (throws an exception "System call failed") on iPad/iPhone devices. The call works fine in the emulator. MSDN documents values 0 and -1 for an infinite time-out ("The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period."). Setting a value of 0 works as expected.

Xamarin.iOS should probably use a 0 value in the SetSocketOption system call if -1 is specified.
Comment 1 Sebastien Pouliot 2014-08-25 22:06:04 UTC
Agreed, but the existing code already do this, i.e.

	set {
		if (this.disposed && this.closed) {
			throw new ObjectDisposedException (base.GetType ().ToString ());
		if (value < -1) {
			throw new ArgumentOutOfRangeException ("value", "The value specified for a set operation is less than -1");
		if (value == -1) {
			value = 0;
		this.SetSocketOption (SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, value);

IOW -1 is never given to the OS.

Your `System call failed` might be related to something else. Could you provide us with:

a) the exact version numbers of the software you're using, both Xamarin [1] and others (e.g. iOS version of the devices)

b) a self-contained test case to duplicate the issue


The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 2 Ivo Smits 2014-08-26 12:32:20 UTC
I'm sorry. I just realized I am actually using a TcpClient instance. The -1 value is not documented for the TcpClient.ReceiveTimeout property.

Although the differences between Socket.ReceiveTimeout/TcpClient.ReceiveTimeout and iOS emulator/device are somewhat confusing, it is probably not a bug in mono.

Sorry about that. Thanks for your time.