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); }
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); }
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); }