Beispiel #1
0
        public HyperPipe(int poolSize,
                         IRequestProvider <T> requestProvider,
                         IResponseConsumer <T> responseConsumer)
        {
            _requestProvider  = requestProvider;
            _responseConsumer = responseConsumer;

            _easyPool    = new EasyPool <T>(poolSize);
            _multiHandle = CurlNative.Multi.Init();
            if (_multiHandle.IsInvalid)
            {
                throw new Exception("Could not init curl_multi handle.");
            }

            _socketMap = new SocketPollMap();
            _loop      = new Loop();
            _timeout   = _loop.CreateTimer();

            // Explicitly define callback functions to keep them from being GCed.
            _socketCallback = HandleSocket;
            _timerCallback  = StartTimeout;

            Logger.LogDebug($"Set {CURLMoption.SOCKETFUNCTION}.");
            CurlNative.Multi.SetOpt(_multiHandle, CURLMoption.SOCKETFUNCTION, _socketCallback);
            Logger.LogDebug($"Set {CURLMoption.TIMERFUNCTION}.");
            CurlNative.Multi.SetOpt(_multiHandle, CURLMoption.TIMERFUNCTION, _timerCallback);
        }
Beispiel #2
0
 EventLoop(TimeSpan breakoutInterval)
 {
     this.preciseBreakoutInterval     = (long)breakoutInterval.TotalMilliseconds;
     this.terminationCompletionSource = new TaskCompletionSource <bool>();
     this.taskQueue   = new ConcurrentQueue <Activator>();
     this.loop        = new Loop();
     this.asyncHandle = this.loop.CreateAsync(this.OnCallback);
     this.timerHandle = this.loop.CreateTimer();
     this.thread      = new Thread(Run);
     this.thread.Start(this);
 }
Beispiel #3
0
        void OnTimer(Timer handle)
        {
            this.resetEvent.Set();
            this.thread.Join(1000);

            foreach (Async async in this.handles)
            {
                async.CloseHandle(OnClose);
                if (async.UserToken != null)
                {
                    this.asyncSeen++;
                }
            }

            handle.CloseHandle(OnClose);
        }