internal async Task <Stream> SendAsync(WebSocketRequest request, BucketGroup group, int bucketId, ulong objId) { request.CancelToken = _cancelToken; var bucket = GetBucket(group, bucketId, objId); return(await bucket.SendAsync(request).ConfigureAwait(false)); }
public async Task SendAsync(WebSocketRequest request) { int id = Interlocked.Increment(ref nextId); #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Start"); #endif LastAttemptAt = DateTimeOffset.UtcNow; while (true) { await _queue.EnterGlobalAsync(id, request).ConfigureAwait(false); await EnterAsync(id, request).ConfigureAwait(false); #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Sending..."); #endif try { await request.SendAsync().ConfigureAwait(false); return; } catch (TimeoutException) { #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Timeout"); #endif if ((request.Options.RetryMode & RetryMode.RetryTimeouts) == 0) { throw; } await Task.Delay(500).ConfigureAwait(false); continue; //Retry } /*catch (Exception) * { #if DEBUG_LIMITS * Debug.WriteLine($"[{id}] Error"); #endif * if ((request.Options.RetryMode & RetryMode.RetryErrors) == 0) * throw; * * await Task.Delay(500); * continue; //Retry * }*/ finally { UpdateRateLimit(id, request, default(RateLimitInfo), false); #if DEBUG_LIMITS Debug.WriteLine($"[{id}] Stop"); #endif } } }
public async Task SendAsync(WebSocketRequest request) { CancellationTokenSource createdTokenSource = null; if (request.Options.CancelToken.CanBeCanceled) { createdTokenSource = CancellationTokenSource.CreateLinkedTokenSource(_requestCancelToken, request.Options.CancelToken); request.Options.CancelToken = createdTokenSource.Token; } else { request.Options.CancelToken = _requestCancelToken; } var bucket = GetOrCreateBucket(request.Options, request); await bucket.SendAsync(request).ConfigureAwait(false); createdTokenSource?.Dispose(); }
internal async Task EnterGlobalAsync(int id, WebSocketRequest request) { //If this is a global request (unbucketed), it'll be dealt in EnterAsync var requestBucket = GatewayBucket.Get(request.Options.BucketId); if (requestBucket.Type == GatewayBucketType.Unbucketed) { return; } //It's not a global request, so need to remove one from global (per-session) var globalBucketType = GatewayBucket.Get(GatewayBucketType.Unbucketed); var options = RequestOptions.CreateOrClone(request.Options); options.BucketId = globalBucketType.Id; var globalRequest = new WebSocketRequest(null, null, false, false, options); var globalBucket = GetOrCreateBucket(options, globalRequest); await globalBucket.TriggerAsync(id, globalRequest); }
public async Task SendAsync(WebSocketRequest request) { //TODO: Re-impl websocket buckets request.CancelToken = _requestCancelToken; await request.SendAsync().ConfigureAwait(false); }