예제 #1
0
        internal void RemoveEasy(CurlEasy easy)
        {
            lock (this)
            {
                var res = Lib.curl_multi_remove_handle(multiPtr, (IntPtr)easy);
                CurlLog.Assert(res == CURLM.OK, $"RemoveEasy {res}");
            }

            lock (workingEasies)
            {
                workingEasies.Remove((IntPtr)easy);
            }
        }
예제 #2
0
        internal void AddEasy(CurlEasy easy)
        {
            lock (this)
            {
                var wc  = workingEasies.Count;
                var res = Lib.curl_multi_add_handle(multiPtr, (IntPtr)easy);
                CurlLog.Assert(res == CURLM.OK, $"AddEasy {easy.uri} {res} {wc}");
                easy.SetOpt(CURLOPT.SHARE, (IntPtr)share);
            }

            lock (workingEasies)
            {
                workingEasies[(IntPtr)easy] = easy;
            }
        }
예제 #3
0
        internal int Perform()
        {
            if (!started)
            {
                return(0);
            }

            long running = 0;

            if (multiPtr != IntPtr.Zero)
            {
                lock (this)
                {
                    var res = Lib.curl_multi_perform(multiPtr, ref running);
                    CurlLog.Assert(res == CURLM.OK, $"Perform {res}");
                }

                while (true)
                {
                    long index  = 0;
                    var  msgPtr = Lib.curl_multi_info_read(multiPtr, ref index);
                    if (msgPtr != IntPtr.Zero)
                    {
                        var msg = (CurlMsg)msgPtr;
                        if (msg.message == CURLMSG.DONE)
                        {
                            CurlEasy easy = null;

                            lock (workingEasies)
                            {
                                workingEasies.TryGetValue(msg.easyPtr, out easy);
                            }

                            if (easy != null)
                            {
                                RemoveEasy(easy);
                                easy.OnMultiPerform(msg.result, this);
                            }
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
            return((int)running);
        }
예제 #4
0
        internal void RemoveEasy(CurlEasy easy)
        {
            int workingCount = 0;

            lock (this)
            {
                Lib.curl_multi_remove_handle(multiPtr, (IntPtr)easy);
                workingEasies.Remove((IntPtr)easy);
                workingCount = workingEasies.Count;
            }

            if (workingCount == 0 && CurlMultiUpdater.Instance != null)
            {
                CurlMultiUpdater.Instance.RemoveMulti(this);
            }
        }
예제 #5
0
        internal void AddEasy(CurlEasy easy)
        {
            Lib.curl_multi_add_handle(multiPtr, (IntPtr)easy);
            easy.SetOpt(CURLOPT.SHARE, (IntPtr)share);

            int workingCount = 0;

            lock (this)
            {
                workingEasies[(IntPtr)easy] = easy;
                workingCount = workingEasies.Count;
            }
            if (workingCount == 1)
            {
                CurlMultiUpdater.Instance.AddMulti(this);
            }
        }