Bug 8462 - System.Net.Sockets.Socket.IOControl( int, byte[], byte[] )
Summary: System.Net.Sockets.Socket.IOControl( int, byte[], byte[] )
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Android
Classification: Xamarin
Component: BCL Class Libraries ()
Version: 4.2.x
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2012-11-16 10:18 UTC by Goncalo Oliveira
Modified: 2013-05-15 10:24 UTC (History)
3 users (show)

Tags:
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:
Status:
RESOLVED NOT_REPRODUCIBLE

Description Goncalo Oliveira 2012-11-16 10:18:22 UTC
IOControl method seems not to be working correctly.

Setting keepalive for a socket fails.
Sample code to reproduce

Socket socket
uint keepaliveTime
uint keepaliveInterval

[..]

            uint dummy = 0;
            byte[] inOptionValues = new byte[ Marshal.SizeOf( dummy ) * 3 ];
            BitConverter.GetBytes( (uint)( keepaliveTime ) ).CopyTo( inOptionValues, 0 );
            BitConverter.GetBytes( (uint)keepaliveTime ).CopyTo( inOptionValues, Marshal.SizeOf( dummy ) );
            BitConverter.GetBytes( (uint)keepaliveInterval ).CopyTo( inOptionValues, Marshal.SizeOf( dummy ) * 2 );

            socket.IOControl( unchecked( (int)IOControlCode.KeepAliveValues ), inOptionValues, null );


Also, the enum version of the method is not implemented.
System.Net.Sockets.Socket.IOControl( IOControlCode, byte[], byte[] )
Comment 1 Peter Collins 2012-12-05 12:47:12 UTC
Thanks for pasting some sample code, however I am still unclear on the error being reported. What about the IOControl method is causing an error for you?

If possible could you please attach a small project, or .cs file that will compile and produce the error you are reporting? This will help us efficiently confirm and fix the bug.
Comment 2 Goncalo Oliveira 2012-12-12 05:48:34 UTC
I don't quite understand what's unclear.

Create a new project, with one activity and one button. On button click execute the code bellow (inside a thread is better).

            TcpClient client = new TcpClient();

            client.Connect( "host_address_here", port_number_here );

            uint keepaliveTime = 60000 * 5;     // 5 minutes
            uint keepaliveInterval = 60000 * 5; // 5 minutes

            /* the native structure
            struct tcp_keepalive {
            ULONG onoff;
            ULONG keepalivetime;
            ULONG keepaliveinterval;
            };
            */

            // marshal the equivalent of the native structure into a byte array
            uint dummy = 0;
            byte[] inOptionValues = new byte[ Marshal.SizeOf( dummy ) * 3 ];
            BitConverter.GetBytes( (uint)( keepaliveTime ) ).CopyTo( inOptionValues, 0 );
            BitConverter.GetBytes( (uint)keepaliveTime ).CopyTo( inOptionValues, Marshal.SizeOf( dummy ) );
            BitConverter.GetBytes( (uint)keepaliveInterval ).CopyTo( inOptionValues, Marshal.SizeOf( dummy ) * 2 );

            // write SIO_VALS to Socket IOControl

            // Scenario 1: enum method not implemented
            client.Client.IOControl( IOControlCode.KeepAliveValues, inOptionValues, null );

            // Scenario 2 - enum workaround: invalid arguments exception
            // ( comment Scenario 1 line )
            client.Client.IOControl( unchecked( (int)IOControlCode.KeepAliveValues ), inOptionValues, null );

            System.Threading.Thread.Sleep( 10000 );
            client.Close();


logcat doesn't say much, apart from the exception reported

12-12 10:50:13.280 E/mono    (19270): 
12-12 10:50:13.280 E/mono    (19270): Unhandled Exception:
12-12 10:50:13.280 E/mono    (19270): System.Net.Sockets.SocketException: Invalid arguments
12-12 10:50:13.280 E/mono    (19270):   at System.Net.Sockets.Socket.IOControl (Int32 ioctl_code, System.Byte[] in_value, System.Byte[] out_value) [0x00000] in <filename unknown>:0
Comment 3 Goncalo Oliveira 2013-05-15 10:24:00 UTC
Seems to be working on 4.6.04000