[System][ios] Disable non-working Ping code (and non-existing DllImport)
authorSebastien Pouliot <sebastien@xamarin.com>
Thu, 26 Nov 2015 19:55:00 +0000 (14:55 -0500)
committerSebastien Pouliot <sebastien@xamarin.com>
Thu, 26 Nov 2015 19:55:00 +0000 (14:55 -0500)
* capget is not part of libc (libSystem.dylib) on iOS (or OSX); and
* There's no working Process class to invoke `ping` by itself leading to

[FAIL] DllImportTest.LackOfCapget : System.InvalidOperationException : Process has not been started.
    at System.Diagnostics.Process.get_HasExited () [0x00039] in /Users/poupou/git/xamarin/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System/System.Diagnostics/Process.cs:184

It's technically possible to implement ping on iOS [1] so the code is
not totally removed from the build (API remains identical to existing).

[1] https://bugzilla.xamarin.com/show_bug.cgi?id=964

mcs/class/System/System.Net.NetworkInformation/Ping.cs

index abb6d5d6bce4f5fcae3d6a2a5b1e705925971278..694f89ba053a572d8d16f961bd58df79e8363968 100644 (file)
@@ -6,6 +6,7 @@
 //     Atsushi Enomoto (atsushi@ximian.com)
 //
 // Copyright (c) 2006-2007 Novell, Inc. (http://www.novell.com)
+// Copyright 2015 Xamarin Inc.
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
@@ -44,6 +45,7 @@ namespace System.Net.NetworkInformation {
        [MonoTODO ("IPv6 support is missing")]
        public class Ping : Component, IDisposable
        {
+#if !MONOTOUCH
                [StructLayout(LayoutKind.Sequential)]
                struct cap_user_header_t
                {
@@ -69,6 +71,7 @@ namespace System.Net.NetworkInformation {
 #endif
                };
                static readonly string PingBinPath;
+#endif
                const int default_timeout = 4000; // 4 sec.
                ushort identifier;
 
@@ -85,7 +88,8 @@ namespace System.Net.NetworkInformation {
                CancellationTokenSource cts;
                
                public event PingCompletedEventHandler PingCompleted;
-               
+
+#if !MONOTOUCH
                static Ping ()
                {
                        if (Environment.OSVersion.Platform == PlatformID.Unix) {
@@ -107,6 +111,7 @@ namespace System.Net.NetworkInformation {
                        if (PingBinPath == null)
                                PingBinPath = "/bin/ping"; // default, fallback value
                }
+#endif
                
                public Ping ()
                {
@@ -116,7 +121,8 @@ namespace System.Net.NetworkInformation {
                        rng.GetBytes (randomIdentifier);
                        identifier = (ushort)(randomIdentifier [0] + (randomIdentifier [1] << 8));
                }
-  
+
+#if !MONOTOUCH
                [DllImport ("libc", EntryPoint="capget")]
                static extern int capget (ref cap_user_header_t header, ref cap_user_data_t data);
 
@@ -143,6 +149,7 @@ namespace System.Net.NetworkInformation {
                                canSendPrivileged = false;
                        }
                }
+#endif
                
                void IDisposable.Dispose ()
                {
@@ -216,11 +223,16 @@ namespace System.Net.NetworkInformation {
                                throw new ArgumentException ("buffer");
                        // options can be null.
 
+#if MONOTOUCH
+                       throw new InvalidOperationException ();
+#else
                        if (canSendPrivileged)
                                return SendPrivileged (address, timeout, buffer, options);
                        return SendUnprivileged (address, timeout, buffer, options);
+#endif
                }
 
+#if !MONOTOUCH
                private PingReply SendPrivileged (IPAddress address, int timeout, byte [] buffer, PingOptions options)
                {
                        IPEndPoint target = new IPEndPoint (address, 0);
@@ -331,6 +343,7 @@ namespace System.Net.NetworkInformation {
                        throw new NotSupportedException ("Ping is not supported on this platform.");
 #endif // MONO_FEATURE_PROCESS_START
                }
+#endif // !MONOTOUCH
 
                // Async
 
@@ -406,6 +419,7 @@ namespace System.Net.NetworkInformation {
                        worker.CancelAsync ();
                }
 
+#if !MONOTOUCH
                // ICMP message
 
                class IcmpMessage
@@ -539,6 +553,7 @@ namespace System.Net.NetworkInformation {
 
                        return args.ToString ();
                }
+#endif // !MONOTOUCH
 
                public Task<PingReply> SendPingAsync (IPAddress address, int timeout, byte [] buffer)
                {