Ejemplo n.º 1
0
        static IntPtr CFNetworkCopyProxiesForAutoConfigurationScript(IntPtr proxyAutoConfigurationScript, IntPtr targetURL, out IntPtr error)
        {
            // This method must only be called on only one thread during an application's life time.
            // Note that it's not enough to use a lock to make calls sequential across different threads,
            // it has to be one thread. Also note that that thread can't be the main thread, because the
            // main thread might be blocking waiting for this network request to finish.
            // Another possibility would be to use JavaScriptCore to execute this piece of
            // javascript ourselves, but unfortunately it's not available before iOS7.
            // See bug #7923 comment #21+.

            using (var data = new GetProxyData()) {
                data.script    = proxyAutoConfigurationScript;
                data.targetUri = targetURL;

                lock (lock_obj) {
                    if (get_proxy_queue == null)
                    {
                        get_proxy_queue = new Queue <GetProxyData> ();
                        proxy_event     = new AutoResetEvent(false);
                        new Thread(CFNetworkCopyProxiesForAutoConfigurationScriptThread)
                        {
                            IsBackground = true,
                        }.Start();
                    }
                    get_proxy_queue.Enqueue(data);
                    proxy_event.Set();
                }

                data.evt.WaitOne();

                error = data.error;

                return(data.result);
            }
        }
Ejemplo n.º 2
0
		static IntPtr CFNetworkCopyProxiesForAutoConfigurationScript (IntPtr proxyAutoConfigurationScript, IntPtr targetURL, out IntPtr error)
		{
			// This method must only be called on only one thread during an application's life time.
			// Note that it's not enough to use a lock to make calls sequential across different threads,
			// it has to be one thread. Also note that that thread can't be the main thread, because the
			// main thread might be blocking waiting for this network request to finish.
			// Another possibility would be to use JavaScriptCore to execute this piece of
			// javascript ourselves, but unfortunately it's not available before iOS7.
			// See bug #7923 comment #21+.

			using (var data = new GetProxyData ()) {
				data.script = proxyAutoConfigurationScript;
				data.targetUri = targetURL;

				lock (lock_obj) {
					if (get_proxy_queue == null) {
						get_proxy_queue = new Queue<GetProxyData> ();
						proxy_event = new AutoResetEvent (false);
						new Thread (CFNetworkCopyProxiesForAutoConfigurationScriptThread) {
							IsBackground = true,
						}.Start ();
					}
					get_proxy_queue.Enqueue (data);
					proxy_event.Set ();
				}

				data.evt.WaitOne ();

				error = data.error;

				return data.result;
			}
		}